qq_33670784 2017-11-30 02:16 采纳率: 50%
浏览 2036
已采纳

请教一个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条回答 默认 最新

  • zxtchiu 2018-04-21 02:51
    关注

    msg.angular.z=2*double(rand())/double(RAND_MAX)−1;

    这句代码你是从pdf上粘贴过来的吧,问题在于最后的-1,前面的不是减号,可能被翻译成中文的了!!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容