Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ROS编程:向前移动turtlebot_C++_Ros - Fatal编程技术网

C++ ROS编程:向前移动turtlebot

C++ ROS编程:向前移动turtlebot,c++,ros,C++,Ros,我想搬动这只海龟 首先,我在我的柳絮中创建了一个包 $ 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_L

我想搬动这只海龟

首先,我在我的柳絮中创建了一个包

$ 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})
编译后:

[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生成[1]:* [ileri/cmakfiles/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);`
  • 你对这些错误怎么看
  • 包含是否有问题?如果您这样认为,我应该添加哪些代码

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

    您的程序还应该包含一个
    intmain(){}
    函数。尝试将语句移动到
    {}

    `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);`