1
votes

I want to move the turtlebot.

Firstly i created package inside my catkin_ws

$ catkin_create_pkg /..package_name../ std_msgs rospy roscpp actionlib tf geometry_msgs move_base_msgs

Then i edit CMakeList

add_executable(myProgram src/main.cpp) and target_link_libraries(<executabletargetname>, ${catkin_LIBRARIES})

Thirdly, i run this command:

catkin_make

after compile:

[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);`
  • What do you think about these errors?
  • Are there problems about include? If you think so, which includes should i add this code?
1

1 Answers

1
votes

In C++, statements go inside functions. It appears that your statement p.header.stamp = ros::Time(); appears outside a function.

Your program should also contain a int main() { } function. Try moving the statements inside the { }.