waist_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 WaistYaw(object):
29  # 初期化処理
30  # Initialize
31  def __init__(self):
32  self.__client = actionlib.SimpleActionClient("/sciurus17/controller3/waist_yaw_controller/follow_joint_trajectory",
33  FollowJointTrajectoryAction)
34  self.__client.wait_for_server(rospy.Duration(5.0))
35 
36  if not self.__client.wait_for_server(rospy.Duration(5.0)):
37  rospy.logerr("Action Server Not Found")
38  rospy.signal_shutdown("Action Server not found")
39  sys.exit(1)
40  self.present_angle = 0.0
41 
42  # 現在角度を設定
43  # Sets the current angle
44  def set_present_angle(self, angle):
45  self.present_angle = angle
46 
47  # 目標角度の設定と実行
48  # Sets the target angle and executes
49  def set_angle(self, yaw_angle, goal_sec):
50  goal = FollowJointTrajectoryGoal()
51  goal.trajectory.joint_names = ["waist_yaw_joint"]
52 
53  # 現在の角度から開始(遷移時間は現在時刻)
54  # Starts from the current angle (The transition time is the current time)
55  yawpoint = JointTrajectoryPoint()
56  yawpoint.positions.append(self.present_angle)
57  yawpoint.time_from_start = rospy.Duration(nsecs=1)
58  goal.trajectory.points.append(yawpoint)
59 
60  # 途中に角度と時刻をappendすると細かい速度制御が可能
61  # 参考=> http://wiki.ros.org/joint_trajectory_controller/UnderstandingTrajectoryReplacement
62  # You can do a fine speed control if you append the angle and time in between
63  # Ref=> http://wiki.ros.org/joint_trajectory_controller/UnderstandingTrajectoryReplacement
64 
65  # ゴール角度を設定(指定されたゴール時間で到達)
66  # Sets the goal angle (Arrives at the specified goal time)
67  yawpoint = JointTrajectoryPoint()
68  yawpoint.positions.append(yaw_angle)
69  yawpoint.time_from_start = rospy.Duration(goal_sec)
70  goal.trajectory.points.append(yawpoint)
71  self.present_angle = yaw_angle
72 
73  # 軌道計画を実行
74  # Executes the planned trajectory
75  self.__client.send_goal(goal)
76  self.__client.wait_for_result(rospy.Duration(goal_sec))
77  return self.__client.get_result()
78 
79 if __name__ == '__main__':
80  rospy.init_node("waist_test")
81 
82  wy = WaistYaw()
83  wy.set_present_angle(math.radians(0.0))
84 
85  # まず正面を向く
86  # Faces the front
87  wy.set_angle(math.radians(0.0), 0.1)
88  rospy.sleep(1.0)
89  # 左45度,1秒
90  # Left 45 degrees, 1 second
91  wy.set_angle(math.radians(45.0), 1.0)
92  rospy.sleep(1.0)
93  # 正面:1秒
94  # Fornt 1 second
95  wy.set_angle(math.radians(0.0), 1.0)
96  rospy.sleep(1.0)
97  # 右45度,1秒
98  # Right 45 degrees, 1 second
99  wy.set_angle(math.radians(-45.0), 1.0)
100  rospy.sleep(1.0)
101  # 正面,1秒
102  # Front 1 second
103  wy.set_angle(math.radians(0.0), 1.0)
waist_joint_trajectory_example.WaistYaw.__client
__client
Definition: waist_joint_trajectory_example.py:32
waist_joint_trajectory_example.WaistYaw.__init__
def __init__(self)
Definition: waist_joint_trajectory_example.py:31
actionlib::SimpleActionClient
waist_joint_trajectory_example.WaistYaw.set_present_angle
def set_present_angle(self, angle)
Definition: waist_joint_trajectory_example.py:44
waist_joint_trajectory_example.WaistYaw.present_angle
present_angle
Definition: waist_joint_trajectory_example.py:40
waist_joint_trajectory_example.WaistYaw
Definition: waist_joint_trajectory_example.py:28
waist_joint_trajectory_example.WaistYaw.set_angle
def set_angle(self, yaw_angle, goal_sec)
Definition: waist_joint_trajectory_example.py:49


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