8 from geometry_msgs.msg
import Vector3
16 self.
_hostname = rospy.get_param(
'~hostname',
'robot1')
23 self.
_pose_offset = np.array([(-1,1), (1,1), (0,0), (1,-1), (-1,-1)], dtype=np.float32)
24 self.
_gradient = np.array([(-1,1), (1,1), (0,0), (1,-1), (-1,-1)], dtype=np.float32)
25 self.
_team_pose = np.array([(0,0), (0,0), (0,0), (0,0), (0,0)], dtype=np.float32)
26 self.
_my_pose = np.array((0,0), dtype=np.float32)
30 self.
vel_hp_pub = rospy.Publisher(
"cmd_vel_hp", Vector3, queue_size=1)
34 rospy.wait_for_service(
"/robot" + str(i+1) +
"/get_pose")
35 get_pose_1 = rospy.ServiceProxy(
"/robot1/get_pose", Pose2D, persistent=
True)
36 get_pose_2 = rospy.ServiceProxy(
"/robot2/get_pose", Pose2D, persistent=
True)
37 get_pose_3 = rospy.ServiceProxy(
"/robot3/get_pose", Pose2D, persistent=
True)
38 get_pose_4 = rospy.ServiceProxy(
"/robot4/get_pose", Pose2D, persistent=
True)
39 get_pose_5 = rospy.ServiceProxy(
"/robot5/get_pose", Pose2D, persistent=
True)
40 self.
get_pose = (get_pose_1, get_pose_2, get_pose_3, get_pose_4, get_pose_5)
43 self.
_feedback = pioneer_mrs.msg.FormationFeedback()
44 self.
_result = pioneer_mrs.msg.FormationResult()
51 rospy.loginfo(self.
_hostname +
" algorithm_node launched.")
63 rospy.loginfo(self.
_hostname +
" algorithm_node action started")
67 for step
in range(1, goal.order):
74 if self._as.is_preempt_requested():
75 self._as.set_preempted()
77 rospy.logerr(self.
_hostname +
" algorithm_node action preempted")
88 self._as.set_succeeded(self.
_result)
89 rospy.loginfo(self.
_hostname +
" algorithm_node action succeeded")
105 rospy.loginfo(self.
_hostname +
" algorithm_node: Updating team pose.")
107 rospy.loginfo(self.
_hostname +
" algorithm_node: Updated team pose.")
112 vel_sum = np.array((0,0), dtype=np.float32)
119 vel = (team_pose_with_offset[i] - my_pose_with_offset) * self.
_gain_q 120 vel_sum = vel_sum + vel
121 rospy.loginfo(self.
_hostname +
" algorithm_node: robot" + str(i+1) + \
123 rospy.loginfo(self.
_hostname +
" algorithm_node: vel" + str(i+1) + \
124 " (% .4f,% .4f)", vel[0], vel[1])
128 vel_sum = vel_sum - (gradient - moving_distance)
129 rospy.loginfo(self.
_hostname +
" algorithm_node: gradient (% .4f,% .4f)", gradient[0], gradient[1])
133 vel_hp.x = vel_sum[0]
134 vel_hp.y = vel_sum[1]
135 self.vel_hp_pub.publish(vel_hp)
136 rospy.loginfo(self.
_hostname +
" algorithm_node: pub vel_hp (% .4f,% .4f)", vel_hp.x, vel_hp.y)
139 if __name__ ==
'__main__':
140 rospy.init_node(
'algorithm_node')
143 except rospy.ROSInterruptException:
def communication_state_callback(self, msg)
def update_team_pose(self)
def action_callback(self, goal)