ROS编程实例出现“terminate called after throwing an instance of 'ros::TimeNotInitializedException”方法

梦里梦外; 2023-06-22 03:19 61阅读 0赞

利用ROS编写一个输出“hello world”简单实例出现“terminate called after throwing an instance of ‘ros::TimeNotInitializedException’
what(): Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called. If this is a standalone app or test that just uses ros::Time and does not communicate over ROS, you may also call ros::Time::init()”的解决方法!!!

代码如下:

  1. #include "ros/ros.h"
  2. #include "std_msgs/String.h"
  3. #include <sstream>
  4. using namespace ros;
  5. using namespace std;
  6. int main(int argc,char ** argv)
  7. {
  8. ros::init(argc,argv,"message_output");
  9. ros::Rate loop_rate(1);
  10. int count = 0;
  11. while(ros::ok())
  12. {
  13. ROS_INFO("Hello world");
  14. count++;
  15. loop_rate.sleep();
  16. }
  17. return 0;
  18. }

出现了以上的错误,原因是使用ros::Rate loop_rate(1)对象未初始化,需在ros::Rate loop_rate(1)前面添加ros::Time::init();语句进行初始化

发表评论

表情:
评论列表 (有 0 条评论,61人围观)

还没有评论,来说两句吧...

相关阅读