00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import time
00019 import rospy
00020 import subprocess
00021
00022 from controller_manager_msgs.srv import SwitchController
00023
00024 from simple_script_server.simple_script_server import simple_script_server
00025 import twist_controller_config as tcc
00026 from dynamic_reconfigure.client import Client
00027
00028 from data_collection import JointStateDataKraken
00029 from data_collection import ObstacleDistanceDataKraken
00030 from data_collection import TwistDataKraken
00031 from data_collection import JointVelocityDataKraken
00032 from data_collection import FrameTrackingDataKraken
00033 from data_collection import OdometryDataKraken
00034
00035
00036 def init_dyn_recfg():
00037 cli = tcc.TwistControllerReconfigureClient()
00038 cli.init()
00039
00040 cli.set_config_param(tcc.NUM_FILT, False)
00041 cli.set_config_param(tcc.DAMP_METHOD, tcc.TwistController_CONSTANT)
00042 cli.set_config_param(tcc.DAMP_FACT, 0.2)
00043 cli.set_config_param(tcc.EPS_TRUNC, 0.001)
00044
00045 cli.set_config_param(tcc.PRIO_CA, 100)
00046 cli.set_config_param(tcc.PRIO_JLA, 50)
00047
00048 cli.set_config_param(tcc.SOLVER, tcc.TwistController_STACK_OF_TASKS)
00049 cli.set_config_param(tcc.K_H, 1.0)
00050
00051 cli.set_config_param(tcc.CONSTR_CA, tcc.TwistController_CA)
00052 cli.set_config_param(tcc.K_H_CA, -1.0)
00053 cli.set_config_param(tcc.ACTIV_THRESH_CA, 0.1)
00054 cli.set_config_param(tcc.ACTIV_BUF_CA, 25.0)
00055 cli.set_config_param(tcc.CRIT_THRESH_CA, 0.025)
00056 cli.set_config_param(tcc.DAMP_CA, 0.000001)
00057
00058 cli.set_config_param(tcc.CONSTR_JLA, tcc.TwistController_JLA)
00059 cli.set_config_param(tcc.K_H_JLA, -1.0)
00060 cli.set_config_param(tcc.ACTIV_THRESH_JLA, 10.0)
00061 cli.set_config_param(tcc.ACTIV_BUF_JLA, 300.0)
00062 cli.set_config_param(tcc.CRIT_THRESH_JLA, 5.0)
00063 cli.set_config_param(tcc.DAMP_JLA, 0.00001)
00064
00065 cli.set_config_param(tcc.KIN_EXT, tcc.TwistController_BASE_ACTIVE)
00066 cli.set_config_param(tcc.EXT_RATIO, 0.05)
00067 cli.set_config_param(tcc.KEEP_DIR, True)
00068 cli.set_config_param(tcc.ENF_VEL_LIM, True)
00069 cli.set_config_param(tcc.ENF_POS_LIM, False)
00070
00071 cli.update()
00072 cli.close()
00073
00074 cli = Client('frame_tracker')
00075 ft_param = {'cart_min_dist_threshold_lin' : 5.0, 'cart_min_dist_threshold_rot' : 5.0}
00076 cli.update_configuration(ft_param)
00077 cli.close()
00078
00079
00080 def init_pos():
00081
00082 switch_controller = rospy.ServiceProxy('/base/controller_manager/switch_controller', SwitchController)
00083 print(switch_controller(None, ['odometry_controller', ], 1))
00084 time.sleep(1.0)
00085 print(switch_controller(['odometry_controller', ], None, 1))
00086 time.sleep(1.0)
00087
00088 sss = simple_script_server()
00089 sss.move("arm_left", "side")
00090 sss.move("arm_right", [[0.6849513492283021, 0.9811503738420306, -0.05053975117653131, -1.4680375957626568, -0.0824580145043452, 0.4964406318714998, -0.5817382519875354]])
00091
00092
00093 if __name__ == "__main__":
00094 rospy.init_node("test_careobot_st_jla_ca_torus")
00095
00096 base_dir = '/home/fxm-mb/bag-files/base_active_arm_right/'
00097 if rospy.has_param('~base_dir'):
00098 base_dir = rospy.get_param('~base_dir')
00099 else:
00100 rospy.logwarn('Could not find parameter ~base_dir. Using default base_dir: ' + base_dir)
00101
00102 if rospy.has_param('chain_tip_link'):
00103 chain_tip_link = rospy.get_param('chain_tip_link')
00104 else:
00105 rospy.logwarn('Could not find parameter chain_tip_link.')
00106 exit(-1)
00107
00108 if rospy.has_param('frame_tracker/tracking_frame'):
00109 tracking_frame = rospy.get_param('frame_tracker/tracking_frame')
00110 else:
00111 rospy.logwarn('Could not find parameter frame_tracker/tracking_frame.')
00112 exit(-2)
00113
00114 if rospy.has_param('root_frame'):
00115 root_frame = rospy.get_param('root_frame')
00116 else:
00117 rospy.logwarn('Could not find parameter root_frame.')
00118 exit(-3)
00119
00120 t = time.localtime()
00121 launch_time_stamp = time.strftime("%Y%m%d_%H_%M_%S", t)
00122 command = 'rosbag play ' + base_dir + 'base_active_arm_right.bag'
00123
00124 data_krakens = [
00125 JointStateDataKraken(base_dir + 'careobot_base_joint_state_data_' + launch_time_stamp + '.csv'),
00126 ObstacleDistanceDataKraken(base_dir + 'careobot_base_obst_dist_data_' + launch_time_stamp + '.csv'),
00127 TwistDataKraken(base_dir + 'careobot_base_twist_data_' + launch_time_stamp + '.csv', True, False),
00128 TwistDataKraken(base_dir + 'careobot_base_twist_controller_commanded_twist_data_' + launch_time_stamp + '.csv', False, False),
00129 JointVelocityDataKraken(base_dir + 'careobot_base_joint_vel_data_' + launch_time_stamp + '.csv'),
00130 OdometryDataKraken(base_dir + 'careobot_base_odometry_data_' + launch_time_stamp + '.csv'),
00131 ]
00132
00133 init_pos()
00134 init_dyn_recfg()
00135
00136
00137 exit()
00138
00139
00140 status_open = True
00141 for data_kraken in data_krakens:
00142 status_open = status_open and data_kraken.open()
00143 if status_open:
00144 rospy.loginfo('Subscribers started for data collection ... \nPress CTRL+C to stop program and write data to the file.')
00145
00146 pid = subprocess.Popen(command, stdin = subprocess.PIPE, cwd = base_dir, shell = True)
00147 time.sleep(0.5)
00148
00149 rate = rospy.Rate(10)
00150 try:
00151 while not rospy.is_shutdown():
00152 rate.sleep()
00153 if(pid.poll() is not None):
00154 rospy.loginfo('Bag file finished stop script.')
00155 break
00156
00157 except (KeyboardInterrupt, SystemExit) as e:
00158 rospy.loginfo('KeyboardInterrupt / SystemExit: ' + str(e))
00159
00160 for data_kraken in data_krakens:
00161 data_kraken.writeAllData()
00162 except rospy.ROSInterruptException as e:
00163 rospy.logwarn('ROSInterruptException: ' + str(e))
00164 except:
00165 rospy.logerr('Else exception.')
00166 else:
00167 for data_kraken in data_krakens:
00168 data_kraken.writeAllData()
00169
00170 try:
00171
00172 pid.kill()
00173 pid.send_signal(subprocess.signal.SIGINT)
00174 except Exception as e:
00175 rospy.logerr('Failed to stop rosbag play due to exception: ' + str(e))
00176 else:
00177 rospy.logerr('Failed to open DataKraken files.')
00178
00179
00180
00181
00182
00183
00184