test_positions.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Author: John Hsu
3 
4 PKG = 'test_pr2_grasping'
5 NAME = 'test_joint_position_controllers'
6 
7 import math
8 import roslib
9 roslib.load_manifest(PKG)
10 roslib.load_manifest('rostest')
11 
12 import sys, unittest
13 import os, os.path, threading, time
14 import rospy, rostest
15 import actionlib
16 from std_msgs.msg import String, Float64
17 from geometry_msgs.msg import Pose,Quaternion,Point, PoseStamped, PoseWithCovariance, PoseWithCovarianceStamped
18 from pr2_controllers_msgs.msg import Pr2GripperCommand, JointControllerState
19 from trajectory_msgs.msg import JointTrajectory
20 from actionlib_msgs.msg import GoalStatusArray
21 import tf.transformations as tft
22 from numpy import float64
23 
24 def positionState(state):
25  print "set_point : ",state.set_point
26  print "process_value : ",state.process_value
27  print "command : ",state.command
28  print "error : ",state.error
29 
30 def gripperState(state):
31  print "set_point : ",state.set_point
32  print "process_value : ",state.process_value
33  print "command : ",state.command
34  print "error : ",state.error
35 
36 if __name__ == '__main__':
37 
38  sub_top = {}
39  sub_top[0] = "/l_elbow_flex_position_controller/state"
40  sub_top[1] = "/l_forearm_roll_position_controller/state"
41  sub_top[2] = "/l_gripper_position_controller/state"
42  sub_top[3] = "/l_shoulder_lift_position_controller/state"
43  sub_top[4] = "/l_shoulder_pan_position_controller/state"
44  sub_top[5] = "/l_upper_arm_roll_position_controller/state"
45  sub_top[6] = "/l_wrist_flex_position_controller/state"
46  sub_top[7] = "/l_wrist_roll_position_controller/state"
47  sub_top[8] = "/r_elbow_flex_position_controller/state"
48  sub_top[9] = "/r_forearm_roll_position_controller/state"
49  sub_top[10] = "/r_gripper_position_controller/state"
50  sub_top[11] = "/r_shoulder_lift_position_controller/state"
51  sub_top[12] = "/r_shoulder_pan_position_controller/state"
52  sub_top[13] = "/r_upper_arm_roll_position_controller/state"
53  sub_top[14] = "/r_wrist_flex_position_controller/state"
54  sub_top[15] = "/r_wrist_roll_position_controller/state"
55  sub_top[16] = "/torso_lift_position_controller/state"
56  sub_top[17] = "/l_gripper_controller/state"
57  sub_top[18] = "/r_gripper_controller/state"
58  sub_top[19] = "/torso_controller/state"
59 
60  pub_top = {}
61  pub_top[0] = "/l_elbow_flex_position_controller/command"
62  pub_top[1] = "/l_forearm_roll_position_controller/command"
63  pub_top[2] = "/l_gripper_position_controller/command"
64  pub_top[3] = "/l_shoulder_lift_position_controller/command"
65  pub_top[4] = "/l_shoulder_pan_position_controller/command"
66  pub_top[5] = "/l_upper_arm_roll_position_controller/command"
67  pub_top[6] = "/l_wrist_flex_position_controller/command"
68  pub_top[7] = "/l_wrist_roll_position_controller/command"
69  pub_top[8] = "/r_elbow_flex_position_controller/command"
70  pub_top[9] = "/r_forearm_roll_position_controller/command"
71  pub_top[10] = "/r_gripper_position_controller/command"
72  pub_top[11] = "/r_shoulder_lift_position_controller/command"
73  pub_top[12] = "/r_shoulder_pan_position_controller/command"
74  pub_top[13] = "/r_upper_arm_roll_position_controller/command"
75  pub_top[14] = "/r_wrist_flex_position_controller/command"
76  pub_top[15] = "/r_wrist_roll_position_controller/command"
77  pub_top[16] = "/torso_lift_position_controller/command"
78  pub_top[17] = "/l_gripper_controller/command"
79  pub_top[18] = "/r_gripper_controller/command"
80  pub_top[19] = "/torso_controller/command"
81 
82  pub_cmd = {}
83  pub_cmd[0] = rospy.Publisher(pub_top[0] , Float64)
84  pub_cmd[1] = rospy.Publisher(pub_top[1] , Float64)
85  pub_cmd[2] = rospy.Publisher(pub_top[2] , Float64)
86  pub_cmd[3] = rospy.Publisher(pub_top[3] , Float64)
87  pub_cmd[4] = rospy.Publisher(pub_top[4] , Float64)
88  pub_cmd[5] = rospy.Publisher(pub_top[5] , Float64)
89  pub_cmd[6] = rospy.Publisher(pub_top[6] , Float64)
90  pub_cmd[7] = rospy.Publisher(pub_top[7] , Float64)
91  pub_cmd[8] = rospy.Publisher(pub_top[8] , Float64)
92  pub_cmd[9] = rospy.Publisher(pub_top[9] , Float64)
93  pub_cmd[10] = rospy.Publisher(pub_top[10] , Float64)
94  pub_cmd[11] = rospy.Publisher(pub_top[11] , Float64)
95  pub_cmd[12] = rospy.Publisher(pub_top[12] , Float64)
96  pub_cmd[13] = rospy.Publisher(pub_top[13] , Float64)
97  pub_cmd[14] = rospy.Publisher(pub_top[14] , Float64)
98  pub_cmd[15] = rospy.Publisher(pub_top[15] , Float64)
99  pub_cmd[16] = rospy.Publisher(pub_top[16] , Float64)
100  pub_cmd[17] = rospy.Publisher(pub_top[17] , Pr2GripperCommand)
101  pub_cmd[18] = rospy.Publisher(pub_top[18] , Pr2GripperCommand)
102  pub_cmd[19] = rospy.Publisher(pub_top[19] , JointTrajectory)
103 
104  rospy.init_node(NAME, anonymous=False)
105 
106  rospy.Subscriber(sub_top[0] , JointControllerState, positionState)
107 
108  cmd = Float64()
109  cmd.data = -0.3
110 
111  timeout = 10.0
112  while True:
113  cmd.data = cmd.data * -1
114  start_time = time.time()
115  end_time = start_time + timeout
116 
117  while time.time() < end_time:
118  pub_cmd[0] .publish( cmd )
119  pub_cmd[1] .publish( cmd )
120  pub_cmd[2] .publish( cmd )
121  pub_cmd[3] .publish( cmd )
122  pub_cmd[4] .publish( cmd )
123  pub_cmd[5] .publish( cmd )
124  pub_cmd[6] .publish( cmd )
125  pub_cmd[7] .publish( cmd )
126  pub_cmd[8] .publish( cmd )
127  pub_cmd[9] .publish( cmd )
128  pub_cmd[10].publish( cmd )
129  pub_cmd[11].publish( cmd )
130  pub_cmd[12].publish( cmd )
131  pub_cmd[13].publish( cmd )
132  pub_cmd[14].publish( cmd )
133  pub_cmd[15].publish( cmd )
134  pub_cmd[16].publish( cmd )
135  #pub_cmd[17].publish(0)
136  #pub_cmd[18].publish(0)
137  #pub_cmd[19].publish(0)
138  time.sleep(0.1)
def positionState(state)
def gripperState(state)


pr2_gazebo
Author(s): John Hsu
autogenerated on Fri May 3 2019 02:24:27