ROS程序设计:向前推进

ROS programming: move forward turtlebot

本文关键字:程序设计 ROS      更新时间:2023-10-16

我想移动这个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"之前需要不合格的id/home/turtlebot/catkin_ws/src/ileri/src/gg.cpp:31:3:错误:预期'catch'make[2]之前的不合格id:*[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);`
  • 你对这些错误怎么看
  • include是否存在问题?如果你认为是这样的话,我应该添加这个代码的哪些内容

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

您的程序还应该包含一个int main() { }函数。尝试在{ }中移动语句。