intmain(int argc, char** argv) { ros::init(argc, argv, "make_plan_node"); ros::NodeHandle nh; // Init service query for make plan //初始化路径规划服务,服务名称为"move_base_node/make_plan" std::string service_name = "move_base_node/make_plan"; //等待服务空闲,如果已经在运行这个服务,会等到运行结束。 while (!ros::service::waitForService(service_name, ros::Duration(3.0))) { ROS_INFO("Waiting for service move_base/make_plan to become available"); } // 服务的客户端,类型就是 nav_msgs::GetPlan ros::ServiceClient serviceClient = nh.serviceClient<nav_msgs::GetPlan>(service_name, true); if (!serviceClient) { ROS_FATAL("Could not initialize get plan service from %s", serviceClient.getService().c_str()); return-1; } nav_msgs::GetPlan srv; //请求服务:规划路线 fillPathRequest(srv.request); if (!serviceClient) { ROS_FATAL("Persistent service connection to %s failed", serviceClient.getService().c_str()); return-1; } ROS_INFO("conntect to %s",serviceClient.getService().c_str()); callPlanningService(serviceClient, srv); }
voidcheckForShutdown() { if (g_shutdown_requested) // 除非ros::requestShutdown() { // Since this gets run from within a mutex inside PollManager, we need to prevent ourselves from deadlocking with another thread that's already in the middle of shutdown() boost::recursive_mutex::scoped_try_lock lock(g_shutting_down_mutex, boost::defer_lock); while (!lock.try_lock() && !g_shutting_down) { ros::WallDuration(0.001).sleep(); }
if (!g_shutting_down) // ros::start()中赋值为false,之后未变 { shutdown(); // 关闭节点 }
等待时间可以通过-d选项来指定,比如等待10秒再播放bag: rosbag play -d 10 realsense.bag
以暂停的方式启动,防止跑掉数据:
1
rosbag play --pause record.bag
要一帧一帧播放的效果,先用暂停方式启动,然后按S键,这个用的还比较少
设置以0.5倍速回放,也就是以录制频率的一半回放。可以加倍播放,但会增大CPU占用。
1
rosbag play -r 0.5 record.bag
循环播放:
1
rosbag play -l record.bag
use_sim_time的问题
播放bag时,运行算法程序,结果报警:
1 2 3
Warning: TF_OLD_DATA ignoring data from the past for frame base_footprint at time 1.59524e+09 according to authority unknown_publisher Possible reasons are listed at http://wiki.ros.org/tf/Errors%20explained at line 277 in /tmp/binarydeb/ros-kinetic-tf2-0.5.20/src/buffer_core.cpp