/
calibration.py
54 lines (37 loc) · 948 Bytes
/
calibration.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
import sys
import pydyn.dynamixel as dyn
from bot import Spidey, SymbiotSpidey
def init_ctrl():
"""motors initialisation"""
if len(sys.argv) == 2:
min_id, max_id = int(sys.argv[0]), int(sys.argv[1])
else:
min_id, max_id = 0, 26
ctrl = dyn.create_controller(verbose = True, motor_range = [min_id, max_id])
sys.stdout.flush()
return ctrl
def calibration(simulation=False):
"""calibration"""
if simulation:
dyn.enable_vrep()
ctrl = init_ctrl()
if simulation:
peter = SymbiotSpidey(ctrl)
else:
peter = Spidey(ctrl)
if simulation:
ctrl.start_sim()
peter.compliant = True
ctrl.wait(10)
leg = peter.legs[0]
leg.led = True
ctrl.wait(10)
raw_input("Calibration. Press enter when done...")
peter.compliant = False
ctrl.wait(10)
references = (motor.position for motor in leg.motors)
print("references :", references)
if simulation:
ctrl.stop_sim()
if __name__ == "__main__":
calibration(simulation=True)