qq_33670784
qq_33670784
2017-11-30 02:16

请教一个ROS编写发布者程序的问题

  • 机器人
  • ros机器人操作系统

按照机器人操作系统浅析中发布者程序编写的步骤 到最后一步catkin时候一直报错报错如下:
[ 50%] Built target hello
[ 75%] Building CXX object agitr/CMakeFiles/pubvel.dir/pubvel.cpp.o
/home/lucky/ros/src/agitr/pubvel.cpp:12:3: error: stray ‘\342’ in program
msg.angular.z=2*double(rand())/double(RAND_MAX)−1;
^
/home/lucky/ros/src/agitr/pubvel.cpp:12:3: error: stray ‘\210’ in program
/home/lucky/ros/src/agitr/pubvel.cpp:12:3: error: stray ‘\222’ in program
/home/lucky/ros/src/agitr/pubvel.cpp: In function ‘int main(int, char**)’:
/home/lucky/ros/src/agitr/pubvel.cpp:12:53: error: expected ‘;’ before numeric constant
msg.angular.z=2*double(rand())/double(RAND_MAX)−1;
^
agitr/CMakeFiles/pubvel.dir/build.make:62: recipe for target 'agitr/CMakeFiles/pubvel.dir/pubvel.cpp.o' failed
make[2]: *** [agitr/CMakeFiles/pubvel.dir/pubvel.cpp.o] Error 1
CMakeFiles/Makefile2:963: recipe for target 'agitr/CMakeFiles/pubvel.dir/all' failed
make[1]: *** [agitr/CMakeFiles/pubvel.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j1 -l1" failed

pubvel 文件为
#include
#include
#include
int main (int argc,char **argv) {
ros::init(argc,argv,"publish_velocity") ;
ros::NodeHandle nh ;
ros::Publisher pub=nh.advertise("turtle1/cmd_vel",1000); srand(time(0));
ros::Rate rate(2);
while(ros::ok()){
geometry_msgs::Twist msg;
msg.linear.x = double (rand ( ) ) / double(RAND_MAX);
msg.angular.z=2*double(rand())/double(RAND_MAX)−1;
pub.publish(msg);
ROS_INFO_STREAM("Sending random velocity command:"<<"linear="<<msg.linear.x<<"angular="<<msg.angular.z);
rate.sleep();
}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐