ROS编程:向前推进turtlebot

时间:2014-11-03 20:11:49

标签: c++ ros

我想移动turtlebot。

首先我在catkin_ws

中创建了包
$ catkin_create_pkg /..package_name../ std_msgs rospy roscpp actionlib tf geometry_msgs move_base_msgs

然后我编辑CMakeList

add_executable(myProgram src/main.cpp) and target_link_libraries(<executabletargetname>, ${catkin_LIBRARIES})

第三,我运行这个命令:

catkin_make
编译后

  

[100%]构建CXX对象ileri / CMakeFiles / gg.dir / src / gg.cpp.o   /home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:18:2:错误:'p'确实   不要命名类型/home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:28:2:   错误:'try'之前的预期unqualified-id   /home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:31:3:错误:预期   'catch'之前的不合格身份[2]:*   [ileri / CMakeFiles / gg.dir / src / gg.cpp.o]错误1 make [1]:*   [ileri / CMakeFiles / gg.dir / all]错误2

.cpp:

`geometry_msgs::PointStamped p;
 geometry_msgs::PointStamped p1;
 p.header.stamp = ros::Time();
 std::string frame1 = "/camera_depth_optical_frame";
 p.header.frame_id = frame1.c_str();

 p.point.x = 0;
 p.point.y = 0;
 p.point.z = 1; // 1 meter

 std::string frame = "map";

 try
 {
   listener.transformPoint(frame,p,p1);
 }catch(tf::TransformException& ex) { ROS_ERROR("exception while transforming..."); }

 // create message for move_base_simple/goal 
 geometry_msgs::PoseStamped msg;
 msg.header.stamp = ros::Time();
 std::string frame = "/map";
 msg.header.frame_id = frame.c_str();
 msg.pose.position = p1.point;
 msg.pose.orientation = tf::createQuaternionMsgFromYaw(0.0);
 publisher.publish(msg);`
  • 您如何看待这些错误?
  • 包含有问题吗?如果您这么认为,我应该添加此代码吗?

1 个答案:

答案 0 :(得分:1)

在C ++中,语句进入函数内部。您的声明p.header.stamp = ros::Time();似乎出现在函数之外。

您的程序还应包含int main() { }功能。尝试移动{ }内的语句。