neck_joint_trajectory_example.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # coding: utf-8
3 
4 # Copyright 2018 RT Corporation
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 
18 import rospy
19 import actionlib
20 from control_msgs.msg import (
21  FollowJointTrajectoryAction,
22  FollowJointTrajectoryGoal
23 )
24 from trajectory_msgs.msg import JointTrajectoryPoint
25 import sys
26 import math
27 
28 class NeckPitch(object):
29  def __init__(self):
30  self.__client = actionlib.SimpleActionClient("/sciurus17/controller3/neck_controller/follow_joint_trajectory",
31  FollowJointTrajectoryAction)
32  self.__client.wait_for_server(rospy.Duration(5.0))
33  if not self.__client.wait_for_server(rospy.Duration(5.0)):
34  rospy.logerr("Action Server Not Found")
35  rospy.signal_shutdown("Action Server not found")
36  sys.exit(1)
37  self.yaw_angle = 0.0
38  self.pitch_angle = 0.0
39 
40  def set_angle(self, yaw_angle, pitch_angle):
41  goal = FollowJointTrajectoryGoal()
42  goal.trajectory.joint_names = ["neck_yaw_joint", "neck_pitch_joint"]
43  yawpoint = JointTrajectoryPoint()
44  self.yaw_angle = yaw_angle
45  self.pitch_angle = pitch_angle
46  yawpoint.positions.append(self.yaw_angle)
47  yawpoint.positions.append(self.pitch_angle)
48  yawpoint.time_from_start = rospy.Duration(nsecs=1)
49  goal.trajectory.points.append(yawpoint)
50  self.__client.send_goal(goal)
51  self.__client.wait_for_result(rospy.Duration(0.1))
52  return self.__client.get_result()
53 
54 if __name__ == '__main__':
55  rospy.init_node("neck_test")
56 
57  np = NeckPitch()
58  try:
59  pitch = float(sys.argv[1])
60  except:
61  pass
62  np.set_angle(math.radians(0.0), math.radians(-60.0))
63  rospy.sleep(1.0)
64  np.set_angle(math.radians(0.0), math.radians(50.0))
65  rospy.sleep(1.0)
66  np.set_angle(math.radians(0.0), math.radians(0.0))
67  rospy.sleep(1.0)
68  np.set_angle(math.radians(-90.0), math.radians(0.0))
69  rospy.sleep(1.0)
70  np.set_angle(math.radians(80.0), math.radians(0.0))
71  rospy.sleep(1.0)
72  np.set_angle(math.radians(0.0), math.radians(0.0))
neck_joint_trajectory_example.NeckPitch.__client
__client
Definition: neck_joint_trajectory_example.py:30
neck_joint_trajectory_example.NeckPitch
Definition: neck_joint_trajectory_example.py:28
actionlib::SimpleActionClient
neck_joint_trajectory_example.NeckPitch.__init__
def __init__(self)
Definition: neck_joint_trajectory_example.py:29
neck_joint_trajectory_example.NeckPitch.set_angle
def set_angle(self, yaw_angle, pitch_angle)
Definition: neck_joint_trajectory_example.py:40
neck_joint_trajectory_example.NeckPitch.pitch_angle
pitch_angle
Definition: neck_joint_trajectory_example.py:38
neck_joint_trajectory_example.NeckPitch.yaw_angle
yaw_angle
Definition: neck_joint_trajectory_example.py:37


sciurus17_examples
Author(s): Daisuke Sato , Hiroyuki Nomura
autogenerated on Fri Aug 2 2024 08:37:20