简体   繁体   English

ROS编程:前进turtlebot

[英]ROS programming: move forward turtlebot

I want to move the turtlebot. 我想移动乌龟机器人。

Firstly i created package inside my catkin_ws 首先,我在catkin_ws内部创建了包

$ catkin_create_pkg /..package_name../ std_msgs rospy roscpp actionlib tf geometry_msgs move_base_msgs

Then i edit CMakeList 然后我编辑CMakeList

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

Thirdly, i run this command: 第三,我运行以下命令:

catkin_make

after compile: 编译后:

[100%] Building CXX object ileri/CMakeFiles/gg.dir/src/gg.cpp.o /home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:18:2: error: 'p' does not name a type /home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:28:2: error: expected unqualified-id before 'try' /home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:31:3: error: expected unqualified-id before 'catch' make[2]: * [ileri/CMakeFiles/gg.dir/src/gg.cpp.o] Error 1 make[1]: * [ileri/CMakeFiles/gg.dir/all] Error 2 [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'/home/turtlebot/catkin_ws/src/ileri/src/gg.cpp之前,预期的unqualified-id :31:3:错误:“捕获” make [2]之前预期的不合格ID:* [ileri / CMakeFiles / gg.dir / src / gg.cpp.o]错误1 make [1]:* [ileri / CMakeFiles /gg.dir/all]错误2

.cpp : .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);`
  • What do you think about these errors? 您如何看待这些错误?
  • Are there problems about include? 是否存在包含问题? If you think so, which includes should i add this code? 如果您这样认为,我应该添加哪些代码?

In C++, statements go inside functions. 在C ++中,语句进入函数内部。 It appears that your statement p.header.stamp = ros::Time(); 看来您的陈述p.header.stamp = ros::Time(); appears outside a function. 出现在函数外部。

Your program should also contain a int main() { } function. 您的程序还应包含一个int main() { }函数。 Try moving the statements inside the { } . 尝试将语句移动到{ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM