2014-11-03 83 views
1

我想移动turtlebot。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%] 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

的.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

在C++中,语句进入函数内部。看起来你的陈述p.header.stamp = ros::Time();出现在函数之外。

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