WUT Velma robot API
set_gripper_configuration.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
5 
6 # Copyright (c) 2021, Robot Control and Pattern Recognition Group,
7 # Institute of Control and Computation Engineering
8 # Warsaw University of Technology
9 #
10 # All rights reserved.
11 #
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions are met:
14 # * Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # * Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # * Neither the name of the Warsaw University of Technology nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL <COPYright HOLDER> BE LIABLE FOR ANY
27 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 # Author: Dawid Seredynski
35 #
36 
37 import roslib; roslib.load_manifest('velma_task_cs_ros_interface')
38 import rospy
39 import sys
40 import math
41 from velma_common import VelmaInterface
42 from rcprg_ros_utils import exitError
43 
44 def deg2rad(deg):
45  return float(deg)/180.0*math.pi
46 
47 def printUsage():
48  print('Usage:')
49  print('set_gripper_configuration left|right reset')
50  print('set_gripper_configuration left|right <q_f1_deg> <q_f2_deg> <q_f3_deg> <q_spread_deg>')
51 
52 if __name__ == "__main__":
53 
54  reset = False
55  if len(sys.argv) == 6:
56  q_f1_deg = float(sys.argv[2])
57  q_f2_deg = float(sys.argv[3])
58  q_f3_deg = float(sys.argv[4])
59  q_spread_deg = float(sys.argv[5])
60  elif len(sys.argv) == 3 and sys.argv[2] == 'reset':
61  reset = True
62  else:
63  printUsage()
64  exitError(1, msg='Wrong arguments')
65 
66  side = sys.argv[1]
67  if side != 'left' and side != 'right':
68  printUsage()
69  exitError(2, msg='Wrong side: "{}"'.format(side))
70 
71  rospy.init_node('set_gripper_configuration', anonymous=False)
72  rospy.sleep(1)
73  print "waiting for init..."
74 
75  velma = VelmaInterface()
76 
77  print "Waiting for VelmaInterface initialization..."
78  if not velma.waitForInit(timeout_s=10.0):
79  print "Could not initialize VelmaInterface\n"
80  exitError(3)
81 
82  print "Initialization ok!\n"
83 
84  diag = velma.getCoreCsDiag()
85  if (not diag.inStateCartImp()) and (not diag.inStateJntImp()):
86  exitError(4, msg='Velma should be in cart_imp or jnt_imp state')
87 
88  if reset:
89  velma.resetHand(side)
90  if velma.waitForHand(side) != 0:
91  exitError(5)
92  exitError(0)
93 
94  q = [deg2rad(q_f1_deg), deg2rad(q_f2_deg), deg2rad(q_f3_deg), deg2rad(q_spread_deg)]
95  velma.moveHand(side, q, [1, 1, 1, 1], [4000,4000,4000,4000], 1000, hold=False)
96  if velma.waitForHand(side) != 0:
97  exitError(6)
98  exitError(0)