@@ -6,35 +6,50 @@ from builtin_interfaces.msg import Duration
66
77from std_msgs .msg import String , Float64
88from trajectory_msgs .msg import JointTrajectory , JointTrajectoryPoint
9+ from std_srvs .srv import Empty
910
1011class MoveArm (Node ):
1112
1213 def __init__ (self ):
1314 super ().__init__ ('arm_node' )
1415 self .arm_publisher_ = self .create_publisher (JointTrajectory , '/arm_joint_trajectory_controller/joint_trajectory' , 10 )
15- timer_period = 0.5 # seconds
16- self .timer = self .create_timer (timer_period , self .timer_callback )
16+ self .pick_srv = self .create_service (Empty , 'move_arm' , self .move_arm_callback )
1717
1818
19- def timer_callback (self ):
19+ # timer_period = 20.0 # seconds
20+ # self.timer = self.create_timer(timer_period, self.timer_callback)
21+
22+ def move_arm_callback (self , request , response ):
2023 traj = JointTrajectory ()
2124 traj .joint_names = ["arm_01_joint" , "arm_02_joint" , "arm_03_joint" , "arm_04_joint" , "arm_tools_joint" ]
2225
23- point = JointTrajectoryPoint ()
24- point .positions = [0.0 ,0.0 ,0.0 ,1.0 ,0.0 ]
25- point .time_from_start = Duration (sec = 1 )
26+ point1 = JointTrajectoryPoint ()
27+ point1 .positions = [0.0 ,0.0 ,1.0 ,0.0 ,0.0 ]
28+ point1 .time_from_start = Duration (sec = 4 )
29+
30+ traj .points .append (point1 )
31+
32+ point2 = JointTrajectoryPoint ()
33+ point2 .positions = [0.0 ,0.0 ,0.0 ,0.0 ,0.0 ]
34+ point2 .time_from_start = Duration (sec = 8 )
35+
36+
37+ traj .points .append (point2 )
38+
39+ self .get_logger ().info (f'Publishing: "{ traj .points } "' )
2640
27- traj .points .append (point )
2841 self .arm_publisher_ .publish (traj )
2942
43+ return response
44+
45+
3046
3147def main (args = None ):
3248 rclpy .init (args = args )
3349
3450 arm_node = MoveArm ()
3551
3652 rclpy .spin (arm_node )
37-
3853 # Destroy the node explicitly
3954 # (optional - otherwise it will be done automatically
4055 # when the garbage collector destroys the node object)
0 commit comments