forked from thomasfla/solopython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_solo8.py
50 lines (40 loc) · 1.76 KB
/
main_solo8.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
# coding: utf8
import numpy as np
import argparse
import math
from time import clock, sleep
from utils.viewerClient import viewerClient
from solo8 import Solo8
def example_script(name_interface):
viewer = viewerClient()
device = Solo8(name_interface,dt=0.001)
nb_motors = device.nb_motors
q_viewer = np.array((7 + nb_motors) * [0.,])
device.Init(calibrateEncoders=False)
#CONTROL LOOP ***************************************************
while ((not device.hardware.IsTimeout()) and (clock() < 200)):
device.UpdateMeasurment()
device.SetDesiredJointTorque([0]*nb_motors)
device.SendCommand(WaitEndOfCycle=True)
if ((device.cpt % 100) == 0):
device.Print()
q_viewer[3:7] = device.baseOrientation # IMU Attitude
q_viewer[7:] = device.q_mes # Encoders
viewer.display(q_viewer)
#****************************************************************
# Whatever happened we send 0 torques to the motors.
device.SetDesiredJointTorque([0]*nb_motors)
device.SendCommand(WaitEndOfCycle=True)
if device.hardware.IsTimeout():
print("Masterboard timeout detected.")
print("Either the masterboard has been shut down or there has been a connection issue with the cable/wifi.")
device.hardware.Stop() # Shut down the interface between the computer and the master board
def main():
parser = argparse.ArgumentParser(description='Example masterboard use in python.')
parser.add_argument('-i',
'--interface',
required=True,
help='Name of the interface (use ifconfig in a terminal), for instance "enp1s0"')
example_script(parser.parse_args().interface)
if __name__ == "__main__":
main()