effort.py
Go to the documentation of this file.
1 #! /usr/bin/python
2 # Copyright (c) 2008, Willow Garage, Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the Willow Garage, Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 
29 # This script brings up an effort controller on your joint of choice
30 # and allows you to type in the desired efforts.
31 #
32 # Author: Stuart Glaser
33 
34 import random
35 CONTROLLER_NAME = "quick_effort_controller_%08d" % random.randint(0,10**8-1)
36 
37 import sys
38 import signal
39 import roslib
40 roslib.load_manifest('robot_mechanism_controllers')
41 import rospy
42 from std_msgs.msg import *
43 from pr2_controller_manager import pr2_controller_manager_interface
44 
45 prev_handler = None
46 
47 def shutdown(sig, stackframe):
48  pr2_controller_manager_interface.stop_controller(CONTROLLER_NAME)
49  pr2_controller_manager_interface.unload_controller(CONTROLLER_NAME)
50  if prev_handler is not None:
51  prev_handler(signal.SIGINT,None)
52 
53 def load_joint_config(joint_name):
54  rospy.set_param(CONTROLLER_NAME+'/type', 'JointEffortController')
55  rospy.set_param(CONTROLLER_NAME+'/joint', joint_name)
56 
57 def main():
58  if len(sys.argv) < 2:
59  print "Usage: effort.py <joint>"
60  sys.exit(1)
61  joint = sys.argv[1]
62  rospy.init_node('effort', anonymous=True)
63 
64  # Override rospy's signal handling. We'll invoke rospy's handler after
65  # we're done shutting down
66  prev_handler = signal.getsignal(signal.SIGINT)
67  signal.signal(signal.SIGINT, shutdown)
68 
69  load_joint_config(joint)
70  pr2_controller_manager_interface.load_controller(CONTROLLER_NAME)
71  pr2_controller_manager_interface.start_controller(CONTROLLER_NAME)
72 
73  pub = rospy.Publisher("%s/command" % CONTROLLER_NAME, Float64)
74 
75  print "Enter efforts:"
76  while not rospy.is_shutdown():
77  effort = float(sys.stdin.readline().strip())
78  pub.publish(Float64(effort))
79 
80 if __name__ == '__main__':
81  main()
def load_joint_config(joint_name)
Definition: effort.py:53
def main()
Definition: effort.py:57
def shutdown(sig, stackframe)
Definition: effort.py:47
prev_handler
Definition: effort.py:45


robot_mechanism_controllers
Author(s): John Hsu, Melonee Wise, Stuart Glaser
autogenerated on Wed Jun 5 2019 19:34:03