test.py
Go to the documentation of this file.
1 import sys
2 import rospy
3 import numpy as np
4 import geometry_msgs.msg as geom_msg
5 import time
6 import subprocess
7 from dynamic_reconfigure.client import Client
8 from absl import app, flags, logging
9 from scipy.spatial.transform import Rotation as R
10 import os
11 
12 FLAGS = flags.FLAGS
13 flags.DEFINE_string("robot_ip", None, "IP address of the robot.", required=True)
14 flags.DEFINE_string("load_gripper", 'false', "Whether or not to load the gripper.")
15 
16 
17 def main(_):
18  try:
19  input("\033[33mPress enter to start roscore and the impedance controller.\033[0m")
20  try:
21  roscore = subprocess.Popen('roscore')
22  time.sleep(1)
23  except:
24  pass
25 
26  impedence_controller = subprocess.Popen(['roslaunch', 'serl_franka_controllers', 'impedance.launch',
27  f'robot_ip:={FLAGS.robot_ip}', f'load_gripper:={FLAGS.load_gripper}'],
28  stdout=subprocess.PIPE)
29 
30  eepub = rospy.Publisher('/cartesian_impedance_controller/equilibrium_pose', geom_msg.PoseStamped, queue_size=10)
31  rospy.init_node('franka_control_api')
32  client = Client("/cartesian_impedance_controllerdynamic_reconfigure_compliance_param_node")
33 
34  # Reset the arm
35  msg = geom_msg.PoseStamped()
36  msg.header.frame_id = "0"
37  msg.header.stamp = rospy.Time.now()
38  msg.pose.position = geom_msg.Point(0.5, 0, 0.2)
39  quat = R.from_euler('xyz', [np.pi, 0, np.pi/2]).as_quat()
40  msg.pose.orientation = geom_msg.Quaternion(quat[0], quat[1], quat[2], quat[3])
41  input("\033[33m\nObserve the surroundings. Press enter to move the robot to the initial position.\033[0m")
42  eepub.publish(msg)
43  time.sleep(1)
44 
45  time.sleep(1)
46  # Setting the reference limiting values through ros dynamic reconfigure
47  for direction in ['x', 'y', 'z', 'neg_x', 'neg_y', 'neg_z']:
48  client.update_configuration({"translational_clip_" + direction: 0.005})
49  client.update_configuration({"rotational_clip_" + direction: 0.04})
50  time.sleep(1)
51  print("\nNew reference limiting values has been set")
52 
53  time.sleep(1)
54  input("\033[33mPress enter to move the robot up with the reference limiting engaged. Notice that the arm motion should be slower this time because the maximum force is effectively limited. \033[0m")
55  for i in range(10):
56  msg = geom_msg.PoseStamped()
57  msg.header.frame_id = "0"
58  msg.header.stamp = rospy.Time.now()
59  msg.pose.position = geom_msg.Point(0.5, 0, 0.2+i*0.02)
60  quat = R.from_euler('xyz', [np.pi, 0, np.pi/2]).as_quat()
61  msg.pose.orientation = geom_msg.Quaternion(quat[0], quat[1], quat[2], quat[3])
62  eepub.publish(msg)
63  time.sleep(0.2)
64  time.sleep(1)
65 
66  time.sleep(1)
67  input("\033[33m\nPress enter to reset the robot arm back to the initial pose. \033[0m")
68  for i in range(10):
69  msg = geom_msg.PoseStamped()
70  msg.header.frame_id = "0"
71  msg.header.stamp = rospy.Time.now()
72  msg.pose.position = geom_msg.Point(0.5, 0, 0.4-i*0.02)
73  quat = R.from_euler('xyz', [np.pi, 0, np.pi/2]).as_quat()
74  msg.pose.orientation = geom_msg.Quaternion(quat[0], quat[1], quat[2], quat[3])
75  eepub.publish(msg)
76  time.sleep(0.1)
77 
78  input("\033[33m\n \nPress enter to exit the test and stop the controller.\033[0m")
79  impedence_controller.terminate()
80  roscore.terminate()
81  sys.exit()
82  except:
83  rospy.logerr("Error occured. Terminating the controller.")
84  impedence_controller.terminate()
85  roscore.terminate()
86  sys.exit()
87 
88 
89 if __name__ == "__main__":
90  app.run(main)
test.main
def main(_)
Definition: test.py:17


serl_franka_controllers
Author(s): Jianlan Luo, Charles Xu
autogenerated on Fri Feb 9 2024 03:09:57