-
Notifications
You must be signed in to change notification settings - Fork 0
/
hitbot_interface.py
204 lines (161 loc) · 7.96 KB
/
hitbot_interface.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import os
from ctypes import *
# do not edit this python file
class HitbotInterface:
card_number = 0
x = 0.0
y = 0.0
z = 0.0
r = 0.0
angle1 = 0.0
angle2 = 0.0
communicate_success = False
initial_finish = False
move_flag = False
efg_distance = 0.0
efg_type = 0.0
encoder_x = 0.0
encoder_y = 0.0
encoder_z = 0.0
encoder_r = 0.0
encoder_angle1 = 0.0
encoder_angle2 = 0.0
def __init__(self, card_number):
self.card_number = card_number
self.x = 0.0
self.y = 0.0
self.z = 0.0
self.r = 0.0
self.angle1 = 0.0
self.angle2 = 0.0
self.efg_dis = 0.0
self.efg_type = 0.0
def net_port_initial(self):
"""Initialize the port and connect the robot."""
os.chdir(os.path.expanduser('~')) # go to home directory
file_dir = os.path.dirname(__file__) # get current folder directory
os.chdir(file_dir) # change current directory to file_dir
self.dll = CDLL('./src/libsmall_scara_interface.so')
return self.dll.net_port_initial()
def initial(self, generation, z_trail):
"""Initialize the robot."""
return self.dll.initial(c_int(self.card_number), c_int(generation), c_float(z_trail))
def get_scara_param(self):
c_angle1 = c_float(0)
c_angle2 = c_float(0)
c_z = c_float(0)
c_r = c_float(0)
c_x = c_float(0)
c_y = c_float(0)
c_communicate_success = c_bool(False)
c_initial_finish = c_bool(False)
c_move_flag = c_bool(False)
self.dll.get_scara_param(c_int(self.card_number), byref(c_x), byref(c_y), byref(c_z), byref(c_angle1),
byref(c_angle2), byref(c_r), byref(c_communicate_success),
byref(c_initial_finish),
byref(c_move_flag))
self.x = c_x.value
self.y = c_y.value
self.z = c_z.value
self.angle1 = c_angle1.value
self.angle2 = c_angle2.value
self.r = c_r.value
self.communicate_success = c_communicate_success.value
self.initial_finish = c_initial_finish.value
self.move_flag = c_move_flag.value
def unlock_position(self):
return self.dll.unlock_position(c_int(self.card_number))
def is_connect(self):
return self.dll.is_connected(c_int(self.card_number))
def get_joint_state(self, joint_num):
return self.dll.get_joint_state(c_int(self.card_number), c_int(joint_num))
def set_drag_teach(self, enable):
return self.dll.set_drag_teach(c_int(self.card_number), c_bool(enable))
def get_drag_teach(self):
return self.dll.get_drag_teach(c_int(self.card_number))
def set_cooperation_fun_state(self, enable):
return self.dll.set_cooperation_fun_state(c_int(self.card_number), c_bool(enable))
def get_cooperation_fun_state(self):
return self.dll.get_cooperation_fun_state(c_int(self.card_number))
def is_collision(self):
return self.dll.is_collision(c_int(self.card_number))
def stop_move(self):
return self.dll.stop_move(c_int(self.card_number))
def joint_home(self,joint_num):
return self.dll.joint_home(c_int(self.card_number),c_int(joint_num))
def movel_xyz(self, goal_x, goal_y, goal_z, goal_r, speed):
return self.dll.movel_xyz(c_int(self.card_number), c_float(goal_x), c_float(goal_y), c_float(goal_z), c_float(goal_r),
c_float(speed))
def movej_xyz(self, goal_x, goal_y, goal_z, goal_r, speed, roughly):
return self.dll.movej_xyz(c_int(self.card_number), c_float(goal_x), c_float(goal_y), c_float(goal_z), c_float(goal_r),
c_float(speed), c_float(roughly))
def movej_angle(self, goal_angle1, goal_angle2, goal_z, goal_r, speed, roughly):
return self.dll.movej_angle(c_int(self.card_number), c_float(goal_angle1), c_float(goal_angle2), c_float(goal_z),
c_float(goal_r),
c_float(speed), c_float(roughly))
def change_attitude(self, speed):
return self.dll.change_attitude(c_int(self.card_number), c_float(speed))
def wait_stop(self):
return self.dll.wait_stop(c_int(self.card_number))
def pause_move(self):
return self.dll.pause_move(c_int(self.card_number))
def resume_move(self):
return self.dll.resume_move(c_int(self.card_number))
def set_digital_out(self, io_number, io_value):
return self.dll.set_digital_out(c_int(self.card_number), c_int(io_number), c_int(io_value))
def get_digital_out(self, io_number):
return self.dll.get_digital_out(c_int(self.card_number), c_int(io_number))
def get_digital_in(self, io_number):
return self.dll.get_digital_in(c_int(self.card_number), c_int(io_number))
def set_efg_state(self, efg_type, efg_distance):
return self.dll.set_efg_state(c_int(self.card_number), c_int(efg_type), c_float(efg_distance))
def get_efg_state(self):
c_efg_type = c_int(0)
c_efg_distance = c_float(0)
ret = self.dll.get_efg_state(c_int(self.card_number), byref(c_efg_type), byref(c_efg_distance))
self.efg_type = c_efg_type
self.efg_distance = c_efg_distance
return ret
def movej_xyz_lr(self, goal_x, goal_y, goal_z, goal_r, speed, roughly, lr):
return self.dll.movej_xyz_lr(c_int(self.card_number), c_float(goal_x), c_float(goal_y), c_float(goal_z), c_float(goal_r),
c_float(speed), c_float(roughly), c_int(lr))
def new_movej_xyz_lr(self, goal_x, goal_y, goal_z, goal_r, speed, roughly, lr):
return self.dll.new_movej_xyz_lr(c_int(self.card_number), c_float(goal_x), c_float(goal_y), c_float(goal_z), c_float(goal_r), c_float(speed), c_float(roughly), c_int(lr))
def new_set_acc(self, j1_max_acc, j2_max_acc, j3_max_acc, j4_max_acc):
return self.dll.new_set_acc(c_int(self.card_number), c_float(j1_max_acc), c_float(j2_max_acc), c_float(j3_max_acc), c_float(j4_max_acc))
def j5_motor_zero(self):
return self.dll.j5_motor_zero(c_int(self.card_number))
def set_j5_motor_pos(self, deg, speed):
return self.dll.set_j5_motor_pos(c_int(self.card_number), c_float(deg), c_float(speed))
def get_j5_parameter(self):
self.dll.get_j5_parameter.restype = c_float
return self.dll.get_j5_parameter(c_int(self.card_number))
def movej_j5(self, deg, speed):
return self.dll.movej_j5(c_int(self.card_number), c_float(deg), c_float(speed))
def get_efg_state_dji(self):
c_efg_type = c_int(0)
c_efg_distance = c_float(0)
ret = self.dll.get_efg_state_dji(c_int(self.card_number), byref(c_efg_type), byref(c_efg_distance))
self.efg_type = c_efg_type
self.efg_distance = c_efg_distance
return ret
def set_efg_state_dji(self, efg_type, efg_distance):
return self.dll.set_efg_state_dji(c_int(self.card_number), c_int(efg_type), c_float(efg_distance))
def new_stop_move(self):
return self.dll.new_stop_move(c_int(self.card_number))
def get_encoder_coor(self):
c_x = c_float(0)
c_y = c_float(0)
c_z = c_float(0)
c_angle1 = c_float(0)
c_angle2 = c_float(0)
c_r = c_float(0)
self.dll.get_encoder_coor(c_int(self.card_number), byref(c_x), byref(c_y), byref(c_z), byref(c_angle1), byref(c_angle2), byref(c_r))
self.encoder_x = c_x.value
self.encoder_y = c_y.value
self.encoder_z = c_z.value
self.encoder_angle1 = c_angle1.value
self.encoder_angle2 = c_angle2.value
self.encoder_r = c_r.value
def new_movej_angle(self, goal_angle1, goal_angle2, goal_z, goal_r, speed, roughly):
return self.dll.new_movej_angle(c_int(self.card_number), c_float(goal_angle1), c_float(goal_angle2), c_float(goal_z), c_float(goal_r), c_float(speed), c_float(roughly))