example_sendupdate.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2019 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 import roslib
18 import rospy
19 from sr_robot_msgs.msg import sendupdate, joint
20 from std_msgs.msg import Float64
21 import math
22 
23 #
24 # Small demo of moving a number of joints together.
25 # Flexes the 2 fingers and then waves the wrist.
26 #
27 
28 
29 # We set up all the publishers needed for all joints in a dict and create a simple
30 # sendupdate function to send joint targets from a dictioary of joint name and angle
31 # (in degrees)
32 # Note naist hand is only 2 fingers and a thumb
33 joint_names = ["thj1", "thj2", "thj3", "thj4", "thj5", "ffj0",
34  "ffj3", "ffj4", "rfj0", "rfj3", "rfj4", "wrj1", "wrj2"]
35 joint_pubs = {}
36 for jname in joint_names:
37  topic = "/sh_" + jname + "_muscle_position_controller/command"
38  print topic
39  joint_pubs[jname] = rospy.Publisher(topic, Float64, latch=True)
40 
41 
42 def sendupdate(joints):
43  print "Sending:"
44  for jname in joints:
45  if jname not in joint_pubs:
46  print "\tJoint %s not found" % jname
47  return
48  msg = Float64()
49  msg.data = math.radians(float(joints[jname]))
50  print "\t" + jname + ": " + str(joints[jname])
51  joint_pubs[jname].publish(msg)
52 
53 rospy.init_node('example_sendupdate')
54 
55 start_pose = {'ffj0': 27.0, 'ffj3': 0, 'ffj4': 0,
56  'rfj0': 40.0, 'rfj3': 0, 'rfj4': 0,
57  'thj1': 20, 'thj2': 31, 'thj3': 0, 'thj4': 25, 'thj5': -29,
58  'wrj1': 0, 'wrj2': 0
59  }
60 
61 print "Start"
62 sendupdate(start_pose)
63 rospy.sleep(2)
64 
65 # FF curl
66 sendupdate({'ffj3': 90})
67 rospy.sleep(3)
68 sendupdate({'ffj0': 120})
69 rospy.sleep(2)
70 sendupdate(start_pose)
71 rospy.sleep(4)
72 
73 # RF curl
74 sendupdate({'rfj0': 120, 'rfj3': 90})
75 rospy.sleep(4)
76 sendupdate(start_pose)
77 rospy.sleep(4)
78 
79 # Back to the start
80 sendupdate(start_pose)
81 rospy.sleep(2)
82 
83 # Wrist wave
84 sendupdate({'wrj2': 10})
85 rospy.sleep(6)
86 sendupdate({'wrj2': -20})
87 rospy.sleep(6)
88 sendupdate({'wrj2': 0})
89 rospy.sleep(4)
90 
91 # Back to the start
92 sendupdate(start_pose)
93 
94 rospy.sleep(2)


sr_edc_muscle_tools
Author(s): Mark Pitchless
autogenerated on Tue Oct 13 2020 04:01:56