Advertisement
SeveQ

goal_test_1

Sep 20th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <ros/ros.h>
  2. #include <move_base_msgs/MoveBaseAction.h>
  3. #include <actionlib/client/simple_action_client.h>
  4. #include "geometry_msgs/PointStamped.h"
  5. #include "tf/transform_listener.h"
  6.  
  7. typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
  8.  
  9. int main(int argc, char** argv)
  10. {
  11.     ros::init(argc, argv, "simple_navigation_goals");
  12.  
  13.     MoveBaseClient ac("move_base", true);
  14.  
  15.     while(!ac.waitForServer(ros::Duration(5.0))){
  16.         ROS_INFO("Waiting for the move_base action server to come up");
  17.     }
  18.  
  19.     tf::TransformListener t;
  20.     ros::Time cTime = ros::Time::now();
  21.     ros::Duration dur(3.0);
  22.  
  23.     if(t.waitForTransform("/base_link", "/odom", cTime, dur)){
  24.         move_base_msgs::MoveBaseGoal goal;
  25.  
  26.         geometry_msgs::PointStamped ps;
  27.         ps.header.frame_id = "/odom";
  28.         ps.header.stamp = cTime;
  29.         ps.point.x = 2700.0;
  30.         ps.point.y = 1700.0;
  31.         ps.point.z = 0.0;
  32.  
  33.         geometry_msgs::PointStamped pt;
  34.         t.transformPoint("base_link", ps, pt);
  35.  
  36.         goal.target_pose.header.frame_id = "/base_link";
  37.         goal.target_pose.header.stamp = ros::Time::now();
  38.  
  39.         goal.target_pose.pose.position.x = pt.point.x;
  40.         goal.target_pose.pose.position.y = pt.point.y;
  41.         goal.target_pose.pose.position.z = pt.point.z;
  42.         goal.target_pose.pose.orientation.w = 1.0;
  43.  
  44.         ROS_INFO("Sending goal");
  45.         ac.sendGoal(goal);
  46.         ac.waitForResult();
  47.  
  48.         if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
  49.             ROS_INFO("Hooray, the base moved to 2700;1700");
  50.         else
  51.             ROS_INFO("The base failed to move to 2700;1700");
  52.     }
  53.     else{
  54.         ROS_ERROR("Transform /base_link /odom not found");
  55.     }
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement