Timer and MultiThread
Hi erveryone, I want to add some change in pr2_teleop/teleop_pr2_keyboard.cpp to add a front collision avoidance system in my UAV project.And then I have some questions:
1. I used ros::Timer to call keyboardLoop and subscribe a topic "/front_scan"(custom) to call a callback function RecieveCostmapCB to recieve UAV front costmap.
//create keyboard Timer
ros::NodeHandle nh_;
ros::Timer keyboardTimer_;
keyboardTimer_ = nh_.createTimer(ros::Duration(0.05), &TeleopPR2Keyboard::keyboardLoop, &tpk);
keyboardTimer_.start();
But it can't step into RecieveCostmapCB until I press any key. As you know, that maybe can't step into RecieveCostmapCB when I press any key, but the result went counter to my hopes. So, why?
2. If I used ros::MultiThreadSpinner instead of ros::spin(), it will be OK! I know this is used MultiThread, but does ROS was so interlligence to do this?(I can't tell them what is belong to A thread and what is belong B thread.
ros::MultiThreadedSpinner spinner(2);
spinner.spin();
void TeleopPR2Keyboard::init()
{
cmd.linear.x = cmd.linear.y = cmd.angular.z = 0;
StopCmd.linear.x = StopCmd.linear.y = StopCmd.angular.z = 0;
vel_pub_ = n_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
sub_costmap = n_.subscribe("/front_scan", 1000, &TeleopPR2Keyboard::RecieveCostmapCB, this);
ros::NodeHandle n_private("~");
n_private.param("walk_vel", walk_vel, 0.5);
n_private.param("run_vel", run_vel, 1.0);
n_private.param("yaw_rate", yaw_rate, 1.0);
n_private.param("yaw_run_rate", yaw_rate_run, 1.5);
}