#include <serial/serial.h>
#include <string.h>
#include <ros/ros.h>
#include <ros/console.h>
using std::string;
string stop("printtrigger 0 set drop\r\n");
string mask("printmask time_trigger yawt_trigger or roll_trigger or pitch_trigger or temp_trigger or accelp_trigger or magp_trigger or gyrop_trigger or set drop\r\n");
string rate("printmodulus 1 set drop\r\n");
string start("printtrigger printmask set drop\r\n");
int main(int argc, char **argv)
{
string port("/dev/tty.usbserial-FTFUUY6A");
unsigned int baudrate = 115200;
ros::init(argc, argv, "IMU");
serial::Serial IMU(port, baudrate, serial::Timeout::simpleTimeout(1000));
IMU.write(stop);
IMU.write(mask);
IMU.write(rate);
IMU.write(start);
int c = 0;
while(ros::ok() && c < 100){
ROS_INFO("here");
c++;
ros::spinOnce(); //remove this and it works again
}
return 0;
}
As highlighted in the snipped, spinOnce() is causing a page fault. Here's the trace:
Sat May 10 19:20:13 2014
panic(cpu 1 caller 0xffffff802e2dbe7e): Kernel trap at 0x0000000000000000, type 14=page fault, registers:
CR0: 0x000000008001003b, CR2: 0x0000000000000000, CR3: 0x00000000307c5000, CR4: 0x00000000001606e0
RAX: 0xffffff8042c70280, RBX: 0xffffff804303b0b0, RCX: 0x0000000000000000, RDX: 0xffffff804303c110
RSP: 0xffffff81113f3bb8, RBP: 0xffffff81113f3c30, RSI: 0xffffff8042dc9900, RDI: 0xffffff8042e63a80
R8: 0x0000000000000000, R9: 0x0000000000000000, R10: 0xffffff8042e91e00, R11: 0xffffff802e6ae9a0
R12: 0x000000000000003e, R13: 0x000000000000003e, R14: 0xffffff804303b000, R15: 0x000000000000003e
RFL: 0x0000000000010246, RIP: 0x0000000000000000, CS: 0x0000000000000008, SS: 0x0000000000000010
Fault CR2: 0x0000000000000000, Error code: 0x0000000000000010, Fault CPU: 0x1
Backtrace (CPU 1), Frame : Return Address
0xffffff81113f3840 : 0xffffff802e222fa9
0xffffff81113f38c0 : 0xffffff802e2dbe7e
0xffffff81113f3a90 : 0xffffff802e2f3376
0xffffff81113f3ab0 : 0x0
0xffffff81113f3c30 : 0xffffff7faecdc7fd
0xffffff81113f3d30 : 0xffffff7faee45166
0xffffff81113f3de0 : 0xffffff7faee45f51
0xffffff81113f3e20 : 0xffffff7faee5383e
0xffffff81113f3ed0 : 0xffffff7faee5b475
0xffffff81113f3ef0 : 0xffffff802e6ae0d0
0xffffff81113f3f30 : 0xffffff802e6acb72
0xffffff81113f3f80 : 0xffffff802e6acc47
0xffffff81113f3fb0 : 0xffffff802e2d7047
Kernel Extensions in backtrace:
com.apple.iokit.IOUSBFamily(675.4)[5C861553-BC5A-3979-A6B4-58C57879DD40]@0xffffff7faecd9000->0xffffff7faed39fff
dependency: com.apple.iokit.IOPCIFamily(2.9)[EDA75271-4E9D-34E7-A2C5-14F0C8817D37]@0xffffff7fae8ba000
com.apple.driver.AppleUSBXHCI(670.4)[91761100-07BD-32B9-AAE7-6BE5C6623809]@0xffffff7faee44000->0xffffff7faee60fff
dependency: com.apple.iokit.IOUSBFamily(675.4.0)[5C861553-BC5A-3979-A6B4-58C57879DD40]@0xffffff7faecd9000
dependency: com.apple.iokit.IOPCIFamily(2.9)[EDA75271-4E9D-34E7-A2C5-14F0C8817D37]@0xffffff7fae8ba000
BSD process name corresponding to current thread: kernel_task
Mac OS version:
13C1021
Kernel version:
Darwin Kernel Version 13.1.0: Wed Apr 2 23:52:02 PDT 2014; root:xnu-2422.92.1~2/RELEASE_X86_64
Kernel UUID: E9CF78E2-1E9F-3B6F-81A4-FEE6C6D0E4D5
Kernel slide: 0x000000002e000000
Kernel text base: 0xffffff802e200000
System model name: MacBookPro10,2 (Mac-AFD8A9D944EA4843)
I can verify that there is nothing wrong with the serial device as anything without ros::Spin() or ros::spinOnce() works as supposed to.