-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_3.py
executable file
·138 lines (108 loc) · 3.4 KB
/
logger_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
import rospy
import dvrk
import numpy as np
import signal
import PyKDL
from sensor_msgs.msg import Joy
trigger = False # create a variable to store the trigger boolean
flag_next = False # create a flag variable for the trigger
# define the "home" positions for the manipulators of interest
init_cart = PyKDL.Vector(0.113,-0.089,-0.100)
init_rot = PyKDL.Rotation()
init_rot = init_rot.Quaternion(0.720,0.022,0.692,0.015)
init_pos = PyKDL.Frame(init_rot,init_cart)
MSM_cart = PyKDL.Vector(-0.128,-0.020,-0.214)
MSM_rot = PyKDL.Rotation()
MSM_rot = init_rot.Quaternion(0.779,-0.063,0.622,-0.017)
MSM_pos = PyKDL.Frame(MSM_rot,MSM_cart)
# utility functions
def trigger_callback(data):
global trigger
butt = data.buttons[0]
if butt > 0.5:
trigger = True
else:
trigger = False
return
def get_cartesian(pose):
position = pose.p
x = position.x()
y = position.y()
z = position.z()
output = np.array([x,y,z])
return output
print "initializing logger"
# get user to input filename
filename = raw_input("Please key in filename :")
filename = filename+'.csv'
# declare 2 objects
p1 = dvrk.psm('PSM1')
p2 = dvrk.psm('PSM2')
m2 = dvrk.mtm('MTMR')
c = dvrk.console()
# create the subscriber to check the footpedal
sub = rospy.Subscriber('/dvrk/footpedals/camera',Joy,trigger_callback)
# set our record rate to 30hz
rate = rospy.Rate(30)
#initialize our data array
time_start = rospy.get_time()
pose1 = p1.get_current_position()
pose2 = p2.get_current_position()
twist1 = p1.get_current_twist_body()
twist2 = p2.get_current_twist_body()
wrench1 = p1.get_current_wrench_body()
wrench2 = p2.get_current_wrench_body()
#jaw_pos1 = p1.get_current_jaw_position()
#jaw_pos2 = p2.get_current_jaw_position()
#jaw_vel1 = p1.get_current_jaw_velocity()
#jaw_vel2 = p2.get_current_jaw_velocity()
#jaw_torq1 = p1.get_current_jaw_effort()
#jaw_torq2 = p2.get_current_jaw_effort()
time = rospy.get_time()-time_start
trial_num = 1
pos1 = get_cartesian(pose1)
pos2 = get_cartesian(pose2)
data = np.hstack((trial_num,time,pos1,pos2,twist1,twist2,wrench1,wrench2))
c.teleop_start()
while trial_num<16:
'''
print ' trial '+str(trial_num)+' start...'
print 'resetting arm...'
c.teleop_stop()
p2.move(init_pos)
m2.move(MSM_pos)
print 'arm ready!'
c.teleop_start()
'''
time_start = rospy.get_time() # this re-initializes the start time for each trial
next_flag = False #reset the flag
while True:
time = rospy.get_time()-time_start
pose1 = p1.get_current_position()
pose2 = p2.get_current_position()
twist1 = p1.get_current_twist_body()
twist2 = p2.get_current_twist_body()
wrench1 = p1.get_current_wrench_body()
wrench2 = p2.get_current_wrench_body()
#jaw_pos1 = p1.get_current_jaw_position()
#jaw_pos2 = p2.get_current_jaw_position()
#jaw_vel1 = p1.get_current_jaw_velocity()
#jaw_vel2 = p2.get_current_jaw_velocity()
#jaw_torq1 = p1.get_current_jaw_effort()
#jaw_torq2 = p2.get_current_jaw_effort()
pos1 = get_cartesian(pose1)
pos2 = get_cartesian(pose2)
new_data = np.hstack((trial_num,time,pos1,pos2,twist1,twist2,wrench1,wrench2))
data = np.vstack((data,new_data))
if next_flag == False and trigger == True and time>1:
next_flag = True
if next_flag == True:
trial_num += 1
break
rate.sleep()
print ' trial '+str(trial_num-1)+' completed'
#scipy.io.savemat('test.mat',dat = data)
print '\n'
print 'saving '+filename+'...'
np.savetxt(filename,data,delimiter=',',fmt='%.4f')