40 import roslib; roslib.load_manifest(PKG)
44 from std_msgs.msg
import Bool
45 from pr2_msgs.msg
import LaserTrajCmd
46 from pr2_msgs.msg
import PowerState
47 from pr2_msgs.srv
import SetLaserTrajCmd
48 from actionlib_msgs.msg
import GoalStatus
49 from move_base_msgs.msg
import MoveBaseAction, MoveBaseGoal, MoveBaseResult, MoveBaseFeedback
50 from pr2_controllers_msgs.msg
import SingleJointPositionAction, SingleJointPositionGoal
51 from pr2_common_action_msgs.msg
import TuckArmsAction, TuckArmsGoal
52 import dynamic_reconfigure.client
53 from pr2_controllers_msgs.msg
import PointHeadAction, PointHeadGoal
56 server.publish_feedback(feedback)
60 cmd.profile =
'blended_linear' 61 cmd.position = position
62 cmd.time_from_start = [rospy.Time.from_sec(x)
for x
in time_from_start]
64 cmd.max_acceleration = 30
66 tilt_profile_client.call(cmd)
67 except rospy.ServiceException, e:
68 rospy.logerr(
"Couldn't set the profile on the laser. Exception %s" % e)
74 head_client.wait_for_server()
75 point_head_goal = PointHeadGoal()
76 point_head_goal.target.header.frame_id =
'base_link' 77 point_head_goal.target.point.x = 3.0
78 point_head_goal.target.point.y = 0.0
79 point_head_goal.target.point.z = 1.0
80 point_head_goal.pointing_frame =
'head_tilt_link' 81 point_head_goal.pointing_axis.x = 1
82 point_head_goal.pointing_axis.y = 0
83 point_head_goal.pointing_axis.z = 0
85 head_client.send_goal(point_head_goal)
86 head_client.wait_for_result(rospy.Duration(5.0))
92 rospy.wait_for_service(
'tilt_hokuyo_node/set_parameters', 1.0)
93 except rospy.exceptions.ROSException, e:
94 rospy.logerr(
"Couldn't set parameters %s" % e)
98 client = dynamic_reconfigure.client.Client(
'tilt_hokuyo_node')
100 old_config = client.get_configuration(2.0)
101 new_config = {
'skip': 0,
'intensity': 0,
'min_ang': -1.57,
'max_ang': 1.57,
'calibrate_time': 1,
'cluster': 1,
'time_offset': 0.0}
102 rospy.loginfo(
'Setting laser to the navigation configuration: %s' % new_config)
103 client.update_configuration(new_config)
108 rospy.wait_for_service(
'tilt_hokuyo_node/set_parameters', 1.0)
109 except rospy.exceptions.ROSException, e:
110 rospy.logerr(
"Couldn't set the profile on the laser. Exception %s" % e)
114 rospy.loginfo(
'Setting laser back to this configuration: %s' % old_config)
115 client = dynamic_reconfigure.client.Client(
'tilt_hokuyo_node')
116 client.update_configuration(old_config)
123 rospy.loginfo(
"Received a goal")
126 if network_connected:
127 server.set_aborted(
None,
"Dangerous to navigate with network cable connected.")
131 if ac_power_connected:
132 server.set_aborted(
None,
"Dangerous to navigate with AC power cable connected.")
140 tuck_arms_client.wait_for_server()
141 tuck_goal = TuckArmsGoal()
142 tuck_goal.tuck_left=
True 143 tuck_goal.tuck_right=
True 144 tuck_arms_client.send_goal(tuck_goal)
148 torso_client.wait_for_server()
149 torso_down_goal = SingleJointPositionGoal()
150 torso_down_goal.position = 0
151 torso_client.send_goal(torso_down_goal)
155 server.set_aborted(MoveBaseResult(),
"Couldn't set the profile on the laser")
162 while not tuck_arms_client.wait_for_result(rospy.Duration(0.1)):
163 if server.is_preempt_requested():
164 if not server.is_new_goal_available():
165 tuck_arms_client.cancel_goal()
167 tuck_state = tuck_arms_client.get_state()
168 if tuck_state != GoalStatus.SUCCEEDED:
169 if tuck_state == GoalStatus.PREEMPTED:
170 server.set_preempted(MoveBaseResult(),
"Tuck-arms preempted")
171 elif tuck_state == GoalStatus.ABORTED:
172 server.set_aborted(MoveBaseResult(),
"Tuck-arms aborted")
176 move_base_client.send_goal(goal,
None,
None, feedback_cb)
178 while not move_base_client.wait_for_result(rospy.Duration(0.1)):
180 if network_connected:
181 move_base_client.cancel_goal()
182 server.set_aborted(
None,
"Dangerous to navigate with network cable connected.")
186 if ac_power_connected:
187 move_base_client.cancel_goal()
188 server.set_aborted(
None,
"Dangerous to navigate with ac power cable connected.")
191 if server.is_preempt_requested():
192 if not server.is_new_goal_available():
193 rospy.loginfo(
"Preempt requested without new goal, cancelling move_base goal.")
194 move_base_client.cancel_goal()
196 server.set_preempted(MoveBaseResult(),
"Got preempted by a new goal")
200 terminal_state = move_base_client.get_state()
201 result = move_base_client.get_result()
202 if terminal_state == GoalStatus.PREEMPTED:
203 server.set_preempted(result)
204 elif terminal_state == GoalStatus.SUCCEEDED:
205 server.set_succeeded(result)
206 elif terminal_state == GoalStatus.ABORTED:
207 server.set_aborted(result)
209 server.set_aborted(result,
"Unknown result from move_base")
212 global network_connected
213 network_connected = connectedness_msg.data
216 global ac_power_connected
217 ac_power_connected = (power_state_msg.AC_present > 0)
219 if __name__ ==
'__main__':
220 name =
'pr2_move_base' 221 rospy.init_node(name)
224 global network_connected
225 network_connected =
False 226 rospy.Subscriber(
"network/connected", Bool, handle_network_connected)
229 global ac_power_connected
230 ac_power_connected =
False 231 rospy.Subscriber(
"power_state", PowerState, handle_power_state)
235 move_base_client.wait_for_server()
236 move_base_goal = MoveBaseGoal()
239 rospy.wait_for_service(
'laser_tilt_controller/set_traj_cmd')
240 tilt_profile_client = rospy.ServiceProxy(
'laser_tilt_controller/set_traj_cmd', SetLaserTrajCmd)
243 rospy.loginfo(
'%s: Action server running', name)
253 rospy.on_shutdown(on_shutdown)
def feedback_cb(feedback)
def handle_power_state(power_state_msg)
def set_tilt_profile(position, time_from_start)
def handle_network_connected(connectedness_msg)