WUT Velma robot API
test_external_force.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
7 
8 import roslib; roslib.load_manifest('velma_core_ve_body')
9 
10 import sys
11 import rospy
12 import math
13 import copy
14 import tf
15 
16 from std_msgs.msg import ColorRGBA
17 from gazebo_msgs.srv import *
18 from geometry_msgs.msg import *
19 from tf.transformations import *
20 
21 if __name__ == "__main__":
22 
23  rospy.init_node('cimp_test', anonymous=True)
24 
25  print "This script tests Vitrual Effector of Velma robot for"
26  print "stability of safe behavior."
27  print "It can be run in simulation environment only."
28  rospy.sleep(1)
29 
30  try:
31  rospy.wait_for_service('/gazebo/apply_body_wrench', timeout=10.0)
32  rospy.wait_for_service('/gazebo/get_model_properties', timeout=10.0)
33  rospy.wait_for_service('/gazebo/get_joint_properties', timeout=10.0)
34  except rospy.ServiceException, e:
35  print "wait_for_service failed: %s"%e
36  exit(0)
37 
38  try:
39  apply_wrench = rospy.ServiceProxy('/gazebo/apply_body_wrench', ApplyBodyWrench)
40  except rospy.ServiceException, e:
41  print "ServiceProxy failed: %s"%e
42  exit(0)
43 
44  try:
45  get_model_properties = rospy.ServiceProxy('/gazebo/get_model_properties', GetModelProperties)
46  except rospy.ServiceException, e:
47  print "ServiceProxy failed: %s"%e
48  exit(0)
49 
50  try:
51  get_joint_proporties = rospy.ServiceProxy('/gazebo/get_joint_properties', GetJointProperties)
52  except rospy.ServiceException, e:
53  print "ServiceProxy failed: %s"%e
54  exit(0)
55 
56  model_prop = get_model_properties("velma")
57  if not model_prop.success:
58  print "error while executing rosservice '/gazebo/get_model_properties':", model_prop.status_message
59  exit(0)
60 
61  print "applying external forces..."
62  for i in range(3):
63  apply_wrench("torso_link0", "world", Point(), Wrench(force=Vector3(), torque=Vector3(0,0,200)), rospy.Time(), rospy.Duration.from_sec(0.01))
64  apply_wrench("left_arm_4_link", "world", Point(), Wrench(force=Vector3(), torque=Vector3(0,0,50)), rospy.Time(), rospy.Duration.from_sec(0.01))
65  apply_wrench("right_arm_4_link", "world", Point(), Wrench(force=Vector3(), torque=Vector3(0,0,50)), rospy.Time(), rospy.Duration.from_sec(0.01))
66  rospy.sleep(0.5)
67 
68  print "waitning for stabilization..."
69  rospy.sleep(2.0)
70 
71  joint_pos = {}
72  for joint_name in model_prop.joint_names:
73  joint_prop = get_joint_proporties(joint_name)
74  if not joint_prop.success:
75  print "error while executing rosservice '/gazebo/get_joint_properties' for joint", joint_name, ":", model_prop.status_message
76  exit(0)
77  joint_pos[joint_name] = joint_prop.position[0]
78 
79  print "waitning for next measurement..."
80  rospy.sleep(1.0)
81  for joint_name in model_prop.joint_names:
82  joint_prop = get_joint_proporties(joint_name)
83  if not joint_prop.success:
84  print "error while executing rosservice '/gazebo/get_joint_properties' for joint", joint_name, ":", model_prop.status_message
85  exit(0)
86  diff = joint_prop.position[0] - joint_pos[joint_name]
87  if abs(diff) > 1.0/180.0*math.pi:
88  print "joint", joint_name, "is still moving:", diff
89 # else:
90 # print "joint", joint_name, "is stable:", diff
91