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