请教一个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();
}
}

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

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

msg.linear.x = double (rand ( ) ) / double(RAND_MAX);
msg.angular.z=2*double(rand())/double(RAND_MAX)−1;中的double放在最外面

//This program publishes randomly−generated velocity

//messages for turtlesim.

#include

#include //For geometry_msgs::Twist

#include //For rand() and RAND_MAX

int main (int argc, char **argv) {

//Initialize the ROS system and become a node.

ros::init (argc, argv, "publish_velocity");

ros::NodeHandle nh;

//Create a publisher object.

ros::Publisher pub = nh.advertise (

"turtle1/cmd_vel", 1000);

//Seed the random number generator.

srand (time (0));

//Loop at 2Hz until the node is shut down.

// ros::Raterate (2);

while (ros::ok ()) {

  //Create and fill in the message.The other four

  //fields, which are ignored by turtlesim, default to 0.

  geometry_msgs::Twist msg;

  msg.linear.x = double (rand ())/double (RAND_MAX);

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



  //Publish the message.

  pub.publish (msg);



  //Send a message to rosout with the details.

  ROS_INFO_STREAM("Sending random velocity command:"

  << "linear=" << msg.linear.x

  << "angular=" << msg.angular.z);



  //Wait untilit's time for another iteration.

 // rate.sleep ();

}

}