2014-11-03 119 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() { }函數。嘗試移動{ }中的語句。