本文整理汇总了C++中cereal::CerealPort::startReadBetweenStream方法的典型用法代码示例。如果您正苦于以下问题:C++ CerealPort::startReadBetweenStream方法的具体用法?C++ CerealPort::startReadBetweenStream怎么用?C++ CerealPort::startReadBetweenStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cereal::CerealPort
的用法示例。
在下文中一共展示了CerealPort::startReadBetweenStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv){ //typical usage: "./traxbot_node /dev/ttyACMx"
ros::init(argc, argv, "traxbot_node");
ros::NodeHandle n;
ros::NodeHandle pn("~");
std::string port;
if (argc<2){
port="/dev/ttyACM0";
ROS_WARN("No Serial Port defined, defaulting to \"%s\"",port.c_str());
ROS_WARN("Usage: \"rosrun [pkg] robot_node /serial_port\"");
}else{
port=(std::string)argv[1];
ROS_INFO("Serial port: %s",port.c_str());
}
// ROS publishers and subscribers
ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("/odom", 100);
tf::TransformBroadcaster odom_broadcaster;
ros::Subscriber cmd_vel_sub = n.subscribe<geometry_msgs::Twist>("/cmd_vel", 10, cmdVelReceived);
odom_pub_ptr = &odom_pub;
odom_broadcaster_ptr = &odom_broadcaster;
// baud_rate and serial port:
int baudrate;
pn.param<std::string>("port", port, port.c_str());
pn.param("baudrate", baudrate, 115200);
// Open the serial port to the robot
try{ serial_port.open((char*)port.c_str(), baudrate); }
catch(cereal::Exception& e){
ROS_FATAL("Robot -- Failed to open serial port!");
ROS_BREAK();
}
//wait (2.5 seconds) until serial port gets ready
ros::Duration(2.5).sleep();
// Ask Robot ID from the Arduino board (stored in the EEPROM)
ROS_INFO("Starting Traxbot...");
serial_port.write("@5e");
std::string reply;
try{ serial_port.readBetween(&reply,'@','e'); }
catch(cereal::TimeoutException& e){
ROS_ERROR("Initial Read Timeout!");
}
int VDriver, Temperature, OMNI_Firmware, Battery;
sscanf(reply.c_str(), "@5,%d,%d,%d,%d,%de", &Temperature, &OMNI_Firmware, &Battery, &VDriver, &ID_Robot); //encoder msg parsing
ROS_INFO("Traxbot ID = %d", ID_Robot);
if (ID_Robot < 1 || ID_Robot > 3){
ROS_WARN("Attention! Unexpected Traxbot ID!");
}
ROS_INFO("OMNI Board Temperature = %.2f C", Temperature*0.01);
ROS_INFO("OMNI Firmware = %.2f", OMNI_Firmware*0.01);
ROS_INFO("Arduino Firmware Version = %d.00", VDriver);
if (VDriver > 1500){
ROS_ERROR("Reset Robot Connection and try again.");
return(0);
}
ROS_INFO("Battery = %.2f V", Battery*0.01 );
if (Battery < 100){
ROS_ERROR("Robot is off. Check power source!");
return(0);
}
if (Battery < 850 && Battery > 100){
ROS_WARN("Warning! Low Battery!");
}
// Start receiving streaming data
if( !serial_port.startReadBetweenStream(boost::bind(&robotDataCallback, _1), '@', 'e') ){
ROS_FATAL("Robot -- Failed to start streaming data!");
ROS_BREAK();
}
serial_port.write("@18e");
ros::spin(); //trigger callbacks and prevents exiting
return(0);
}