Professional Documents
Culture Documents
Lesson 6
<node
<node pkg="map_server"
pkg="map_server" type="map_server"
type="map_server" name="map_server"
name="map_server" args="$(find
args="$(find
navigation_stage)/stage_config/maps/willow-full.pgm
navigation_stage)/stage_config/maps/willow-full.pgm 0.1"
0.1" respawn="false"
respawn="false" >>
<param
<param name="frame_id"
name="frame_id" value="/map"
value="/map" />
/>
</node>
</node>
<node
<node pkg="stage_ros"
pkg="stage_ros" type="stageros"
type="stageros" name="stageros"
name="stageros" args="$(optenv
args="$(optenv
ROS_STAGE_GRAPHICS
ROS_STAGE_GRAPHICS -g)-g) $(find
$(find navigation_stage)/stage_config/worlds/willow-pr2-
navigation_stage)/stage_config/worlds/willow-pr2-
multi.world"
multi.world" respawn="false">
respawn="false">
<param
<param name="base_watchdog_timeout"
name="base_watchdog_timeout" value="0.2"/>
value="0.2"/>
</node>
</node>
<node
<node name="rviz"
name="rviz" pkg="rviz"
pkg="rviz" type="rviz"
type="rviz" args="-d
args="-d $(find
$(find navigation_stage)/multi_robot.rviz"
navigation_stage)/multi_robot.rviz" />
/>
</launch>
</launch>
typedef
typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction>
actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction>
MoveBaseClient;
MoveBaseClient;
using
using namespace
namespace std;
std;
int
int main(int
main(int argc,
argc, char**
char** argv)
argv) {{
if
if (argc
(argc << 2)
2) {{
ROS_ERROR("You
ROS_ERROR("You must
must specify
specify leader
leader robot
robot id.");
id.");
return -1;
return -1;
}}
char
char *robot_id
*robot_id == argv[1];
argv[1];
ros::init(argc,
ros::init(argc, argv,
argv, "send_goals");
"send_goals");
ros::NodeHandle nh;
ros::NodeHandle nh;
//
// Define
Define the
the goal
goal
double
double goal_x
goal_x == 7.45;
7.45;
double
double goal_y
goal_y == 18.5;
18.5;
double
double goal_theta == 0;
goal_theta 0;
//
// create
create the
the action
action client
client
MoveBaseClient
MoveBaseClient ac(move_base_str,
ac(move_base_str, true);
true);
//
// Wait
Wait for
for the
the action
action server
server to
to become
become available
available
ROS_INFO("Waiting
ROS_INFO("Waiting for
for the
the move_base
move_base action
action server");
server");
ac.waitForServer(ros::Duration(5));
ac.waitForServer(ros::Duration(5));
ROS_INFO("Connected
ROS_INFO("Connected to
to move
move base
base server");
server");
//
// Send
Send aa goal
goal to
to move_base
move_base
move_base_msgs::MoveBaseGoal
move_base_msgs::MoveBaseGoal goal;
goal;
goal.target_pose.header.frame_id
goal.target_pose.header.frame_id == "map";
"map";
goal.target_pose.header.stamp = ros::Time::now();
goal.target_pose.header.stamp = ros::Time::now();
goal.target_pose.pose.position.x
goal.target_pose.pose.position.x == goal_x;
goal_x;
goal.target_pose.pose.position.y
goal.target_pose.pose.position.y == goal_y;
goal_y;
geometry_msgs::Quaternion
geometry_msgs::Quaternion qMsg;
qMsg;
tf::quaternionTFToMsg(quaternion,
tf::quaternionTFToMsg(quaternion, qMsg);
qMsg);
goal.target_pose.pose.orientation
goal.target_pose.pose.orientation == qMsg;
qMsg;
ROS_INFO("Sending
ROS_INFO("Sending goal
goal to
to robot
robot no.
no. %s:
%s: xx == %f,
%f, yy == %f,
%f, theta
theta == %f",
%f",
robot_id, goal_x, goal_y, goal_theta);
robot_id, goal_x, goal_y, goal_theta);
ac.sendGoal(goal);
ac.sendGoal(goal);
//
// Wait
Wait for
for the
the action
action to
to return
return
ac.waitForResult();
ac.waitForResult();
if
if (ac.getState()
(ac.getState() ==
== actionlib::SimpleClientGoalState::SUCCEEDED)
actionlib::SimpleClientGoalState::SUCCEEDED)
ROS_INFO("You
ROS_INFO("You have
have reached
reached the
the goal!");
goal!");
else
else
ROS_INFO("The
ROS_INFO("The base
base failed
failed for
for some
some reason");
reason");
return
return 0;
0;
}}
<!--
<!-- BEGIN
BEGIN ROBOT
ROBOT 11 -->
-->
<group ns="robot_1">
<group ns="robot_1">
<param
<param name="goal_x"
name="goal_x" value="10.12"
value="10.12" />
/>
<param
<param name="goal_y"
name="goal_y" value="12.97"
value="12.97" />
/>
<param
<param name="goal_theta"
name="goal_theta" value="45"
value="45" />
/>
<node
<node pkg="navigation_multi"
pkg="navigation_multi" type="send_goal"
type="send_goal" respawn="false"
respawn="false"
name="send_goal" output="screen" args="1"/>
name="send_goal" output="screen" args="1"/>
</group>
</group>
<!--
<!-- END
END ROBOT
ROBOT 11 -->
-->
</launch>
</launch>