simple_navigation_goals.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Eitan Marder-Eppstein
36 *
37 * For a discussion of this tutorial, please see:
38 * http://pr.willowgarage.com/wiki/navigation/Tutorials/SendingSimpleGoals
39 *********************************************************************/
40 #include <ros/ros.h>
41 #include <move_base_msgs/MoveBaseAction.h>
43 #include <tf/transform_datatypes.h>
44 
45 #include <boost/thread.hpp>
46 
48 
49 void spinThread(){
50  ros::spin();
51 }
52 
53 int main(int argc, char** argv){
54  ros::init(argc, argv, "simple_navigation_goals");
55 
57 
58  boost::thread spin_thread = boost::thread(boost::bind(&spinThread));
59 
60  MoveBaseClient ac("pose_base_controller");
61 
62  //give some time for connections to register
63  sleep(2.0);
64 
65  move_base_msgs::MoveBaseGoal goal;
66 
67  //we'll send a goal to the robot to move 2 meters forward
68  goal.target_pose.header.frame_id = "base_link";
69  goal.target_pose.header.stamp = ros::Time::now();
70 
71  goal.target_pose.pose.position.x = 2.0;
72  goal.target_pose.pose.position.y = 0.2;
73  goal.target_pose.pose.orientation = tf::createQuaternionMsgFromYaw(M_PI);
74 
75  ROS_INFO("Sending goal");
76  ac.sendGoal(goal);
77 
78  ac.waitForResult();
79 
81  ROS_INFO("Hooray, the base moved 2 meters forward");
82  else
83  ROS_INFO("The base failed to move forward 2 meters for some reason");
84 
85  return 0;
86 }
actionlib::SimpleActionClient< move_base_msgs::MoveBaseAction > MoveBaseClient
void spinThread()
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
int main(int argc, char **argv)
#define ROS_INFO(...)
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
static Time now()
SimpleClientGoalState getState() const


simple_navigation_goals_tutorial
Author(s): Eitan Marder-Eppstein
autogenerated on Sun Jul 12 2020 03:52:58