neck_joint_trajectory_example.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # coding: utf-8
3 
4 import rospy
5 import actionlib
6 from control_msgs.msg import (
7  FollowJointTrajectoryAction,
8  FollowJointTrajectoryGoal
9 )
10 from trajectory_msgs.msg import JointTrajectoryPoint
11 import sys
12 import math
13 
14 class NeckPitch(object):
15  def __init__(self):
16  self.__client = actionlib.SimpleActionClient("/sciurus17/controller3/neck_controller/follow_joint_trajectory",
17  FollowJointTrajectoryAction)
18  self.__client.wait_for_server(rospy.Duration(5.0))
19  if not self.__client.wait_for_server(rospy.Duration(5.0)):
20  rospy.logerr("Action Server Not Found")
21  rospy.signal_shutdown("Action Server not found")
22  sys.exit(1)
23  self.yaw_angle = 0.0
24  self.pitch_angle = 0.0
25 
26  def set_angle(self, yaw_angle, pitch_angle):
27  goal = FollowJointTrajectoryGoal()
28  goal.trajectory.joint_names = ["neck_yaw_joint", "neck_pitch_joint"]
29  yawpoint = JointTrajectoryPoint()
30  self.yaw_angle = yaw_angle
31  self.pitch_angle = pitch_angle
32  yawpoint.positions.append(self.yaw_angle)
33  yawpoint.positions.append(self.pitch_angle)
34  yawpoint.time_from_start = rospy.Duration(nsecs=1)
35  goal.trajectory.points.append(yawpoint)
36  self.__client.send_goal(goal)
37  self.__client.wait_for_result(rospy.Duration(0.1))
38  return self.__client.get_result()
39 
40 if __name__ == '__main__':
41  rospy.init_node("neck_test")
42 
43  np = NeckPitch()
44  try:
45  pitch = float(sys.argv[1])
46  except:
47  pass
48  np.set_angle(math.radians(0.0), math.radians(-60.0))
49  rospy.sleep(1.0)
50  np.set_angle(math.radians(0.0), math.radians(50.0))
51  rospy.sleep(1.0)
52  np.set_angle(math.radians(0.0), math.radians(0.0))
53  rospy.sleep(1.0)
54  np.set_angle(math.radians(-90.0), math.radians(0.0))
55  rospy.sleep(1.0)
56  np.set_angle(math.radians(80.0), math.radians(0.0))
57  rospy.sleep(1.0)
58  np.set_angle(math.radians(0.0), math.radians(0.0))


sciurus17_examples
Author(s): Daisuke Sato , Hiroyuki Nomura
autogenerated on Sun Oct 2 2022 02:21:39