ROS相关(ros::time和时间戳转换,ros回调函数多个参数,csv, ros中的仿真时间),rosbag/bag.h

  • Post author:
  • Post category:其他




转换时间戳为ros::Time

ros中的time分为s和ns,因此需要做处理,这里使用string进行处理

ros::Time timesamp2rostime(int64_t timesamp){
  std::string suanz = std::to_string(timesamp);
  std::string sec_string = suanz.substr(0,10);
  std::string nsec_string = suanz.substr(10,9);
  while(nsec_string.length() < 9){
      nsec_string += "0";
  }
  return ros::Time(std::stoi(sec_string),std::stoi(nsec_string));
}



ros的回调函数使用多个参数

首先,在subscriber定义的时候使用boost::bind

int main(int argc, char **argv){
    ros::init(argc,argv, "listener");
    std::string out_path = "~/out_pose.txt";
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe<geometry_msgs::PoseWithCovarianceStamped>
    							("pose_out_info", 1, boost::bind(&posecallback, _1, out_path));
    ros::spin();
    return 0;
}

其次,回调函数对于消息类型的调用要使用shard_ptr<>智能指针的形式

void posecallback(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg, std::string out_path){
//do something
}



ros中的仿真时间

launch中首先写入 可以设置系统使用仿真时间,否则中使用rviz的过程中则会出现too old的问题,但是使用完之后要恢复现场,不然在系统中的暂停等会出问题

此参数可以也通过节点设置:

rosparam set use_sim_time false



bugs:



get_pose.cpp:(.text+0x2f4): undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned int)’

这种错误出现后将CMakeLists.txt中的target_link_libraries(talker_pose ${catkin_LIBRARIES})错写成了add_dependencies()



[rosrun] Couldn’t find executable named talker2 below ~/catkin_ws/src/make_bag_from_txt

CMakeLists.txt错误,缺少一行 catkin_package()



rosbag/bag.h

若引用该头文件中的函数,CMaklists.txt中必须在find_package()中加入rosbag,否则编译会出问题

在这里插入图片描述



tips

ubuntu terminal执行程序时 指令后加“>filename”可以将本来应该在屏幕上的输入放入filename文件中

如:

catkin_make > t

将catkin_make指令产生的在屏幕上的输入放入到了t文件中



版权声明:本文为wyf826459原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。