25 from final_assignment.srv
import user_target, user_targetRequest, user_targetResponse
26 from move_base_msgs.msg
import MoveBaseActionGoal
27 from geometry_msgs.msg
import Point
28 from final_assignment.srv
import check_position, check_positionRequest, check_positionResponse
34 node_name =
"reach_user_pos_service"
37 name_move_base =
"/move_base/goal"
40 name_user_target =
"/user_target"
43 topic_move_base =
None
46 name_check_position =
"/check_position"
50 min_distance_from_the_target = 2
53 cycle_time = rospy.Duration( 0, 500 )
70 global name_move_base, srv_move_base
73 msg = MoveBaseActionGoal( )
74 msg.goal.target_pose.header.frame_id =
'map'
75 msg.goal.target_pose.pose.position.x = target_position.x
76 msg.goal.target_pose.pose.position.y = target_position.y
77 msg.goal.target_pose.pose.orientation.w = 1.0
79 topic_move_base.publish(msg)
86 srv_check_position =
None
100 global node_name, min_distance_from_the_target
101 global name_check_position, srv_check_position
103 response = user_targetResponse( )
106 rospy.loginfo(
" [%s] sending target to MoveBase ... ", node_name )
110 rospy.loginfo(
" [%s] reaching the position... ", node_name )
112 req = check_positionRequest( )
113 req.check_only =
False
114 req.tol = min_distance_from_the_target
115 req.target = data.target
117 rospy.sleep( cycle_time )
119 rospy.loginfo(
" [%s] position reached! ", node_name )
121 response.success =
True
140 rospy.loginfo(
" [%s] is OFFLINE", node_name )
144 if __name__ ==
"__main__":
145 rospy.init_node( node_name )
146 rospy.on_shutdown( cbk_on_shutdown )
149 rospy.loginfo(
" [%s] advertising service %s ...", node_name, name_user_target )
150 rospy.Service( name_user_target, user_target, srv_user_target )
151 rospy.loginfo(
" [%s] service %s ... OK", node_name, name_user_target )
154 rospy.loginfo(
" [%s] topic (out) %s ...", node_name, name_move_base )
155 topic_move_base = rospy.Publisher( name_move_base, MoveBaseActionGoal, queue_size=1 )
156 rospy.loginfo(
" [%s] topic (out) %s ... OK", node_name, name_move_base )
159 rospy.loginfo(
" [%s] getting service %s ...", node_name, name_check_position )
160 rospy.wait_for_service( name_check_position )
161 srv_check_position = rospy.ServiceProxy( name_check_position, check_position )
162 rospy.loginfo(
" [%s] service %s ... OK", node_name, name_check_position )
165 rospy.loginfo(
" [%s] is ONLINE", node_name )
167 except rospy.ROSException:
168 rospy.loginfo(
" [%s] Raised an Exception ... ", node_name )
srv_check_position
call-point of the service 'check_position'
def new_target_to_move_base(target_position)
send the goal to MoveBase.
def srv_user_target(data)
implementation of the service '/user_target'
def cbk_on_shutdown()
This is called on the shutdown of the node.