WUT Velma robot API
test_relax.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
7 
8 # Copyright (c) 2017, Robot Control and Pattern Recognition Group,
9 # Institute of Control and Computation Engineering
10 # Warsaw University of Technology
11 #
12 # All rights reserved.
13 #
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions are met:
16 # * Redistributions of source code must retain the above copyright
17 # notice, this list of conditions and the following disclaimer.
18 # * Redistributions in binary form must reproduce the above copyright
19 # notice, this list of conditions and the following disclaimer in the
20 # documentation and/or other materials provided with the distribution.
21 # * Neither the name of the Warsaw University of Technology nor the
22 # names of its contributors may be used to endorse or promote products
23 # derived from this software without specific prior written permission.
24 #
25 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 # DISCLAIMED. IN NO EVENT SHALL <COPYright HOLDER> BE LIABLE FOR ANY
29 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Author: Dawid Seredynski
37 #
38 
39 import roslib; roslib.load_manifest('velma_task_cs_ros_interface')
40 import rospy
41 
42 from velma_common import *
43 from rcprg_ros_utils import exitError
44 
45 if __name__ == "__main__":
46  # starting position
47  q_map_starting = {'torso_0_joint':0, 'right_arm_0_joint':-0.3, 'right_arm_1_joint':-1.8,
48  'right_arm_2_joint':1.25, 'right_arm_3_joint':0.85, 'right_arm_4_joint':0, 'right_arm_5_joint':-0.5,
49  'right_arm_6_joint':0, 'left_arm_0_joint':0.3, 'left_arm_1_joint':1.8, 'left_arm_2_joint':-1.25,
50  'left_arm_3_joint':-0.85, 'left_arm_4_joint':0, 'left_arm_5_joint':0.5, 'left_arm_6_joint':0 }
51 
52  rospy.init_node('test_relax', anonymous=False)
53 
54  rospy.sleep(0.5)
55 
56  print "Running python interface for Velma..."
57  velma = VelmaInterface()
58  print "Waiting for VelmaInterface initialization..."
59  if not velma.waitForInit(timeout_s=10.0):
60  print "Could not initialize VelmaInterface\n"
61  exitError(1)
62  print "Initialization ok!\n"
63 
64  diag = velma.getCoreCsDiag()
65  if not diag.motorsReady():
66  print "Motors must be homed and ready to use for this test."
67  exitError(2)
68 
69  print "Motors must be enabled every time after the robot enters safe state."
70  print "If the motors are already enabled, enabling them has no effect."
71  print "Enabling motors..."
72  if velma.enableMotors() != 0:
73  exitError(3)
74 
75  print "Switching to relax behavior..."
76 
77  velma.switchToRelaxBehavior()
78 
79  rospy.sleep(0.5)
80 
81  diag = velma.getCoreCsDiag()
82  if not diag.inStateRelax():
83  exitError(4)
84 
85  rospy.sleep(2.0)
86 
87  print "Moving to the starting position (jnt_imp)..."
88  velma.moveJoint(q_map_starting, 2.0, start_time=0.5, position_tol=15.0/180.0*math.pi)
89  error = velma.waitForJoint()
90  if error != 0:
91  print "The action should have ended without error, but the error code is", error
92  exitError(5)
93 
94  rospy.sleep(0.5)
95  js = velma.getLastJointState()
96  if not isConfigurationClose(q_map_starting, js[1], tolerance=0.1):
97  exitError(6)
98 
99  exitError(0)
100 
def isConfigurationClose(q_map1, q_map2, tolerance=0.1, allow_subset=False)
Check if two configurations of robot body are close within tolerance.