-
Notifications
You must be signed in to change notification settings - Fork 40
/
example_pushups(highlevel).py
66 lines (59 loc) · 2.48 KB
/
example_pushups(highlevel).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
from ucl.common import byte_print, decode_version, decode_sn, getVoltage, pretty_print_obj, lib_version
from ucl.highCmd import highCmd
from ucl.highState import highState
from ucl.lowCmd import lowCmd
from ucl.unitreeConnection import unitreeConnection, HIGH_WIFI_DEFAULTS, HIGH_WIRED_DEFAULTS
from ucl.enums import MotorModeHigh, GaitType, SpeedLevel
from ucl.complex import motorCmd
import time
# You can use one of the 3 Presets WIFI_DEFAULTS, LOW_CMD_DEFAULTS or HIGH_CMD_DEFAULTS.
# IF NONE OF THEM ARE WORKING YOU CAN DEFINE A CUSTOM ONE LIKE THIS:
#
# MY_CONNECTION_SETTINGS = (listenPort, addr_wifi, sendPort_high, local_ip_wifi)
# conn = unitreeConnection(MY_CONNECTION_SETTINGS)
#
print(f'Running lib version: {lib_version()}')
conn = unitreeConnection(HIGH_WIFI_DEFAULTS)
conn.startRecv()
hcmd = highCmd()
hstate = highState()
# Send empty command to tell the dog the receive port and initialize the connectin
cmd_bytes = hcmd.buildCmd(debug=False)
conn.send(cmd_bytes)
time.sleep(0.5) # Some time to collect pakets ;)
i = 0
while True:
data = conn.getData()
for paket in data:
print(i)
print('+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=')
hstate.parseData(paket)
print(f'SN [{byte_print(hstate.SN)}]:\t{decode_sn(hstate.SN)}')
print(f'Ver [{byte_print(hstate.version)}]:\t{decode_version(hstate.version)}')
print(f'SOC:\t\t\t{hstate.bms.SOC} %')
print(f'Overall Voltage:\t{getVoltage(hstate.bms.cell_vol)} mv') #something is still wrong here ?!
print(f'Current:\t\t{hstate.bms.current} mA')
print(f'Cycles:\t\t\t{hstate.bms.cycle}')
print(f'Temps BQ:\t\t{hstate.bms.BQ_NTC[0]} °C, {hstate.bms.BQ_NTC[1]}°C')
print(f'Temps MCU:\t\t{hstate.bms.MCU_NTC[0]} °C, {hstate.bms.MCU_NTC[1]}°C')
print(f'FootForce:\t\t{hstate.footForce}')
print(f'FootForceEst:\t\t{hstate.footForceEst}')
print('+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=')
# Example rotate 90° left
if i == 0:
hcmd.mode = MotorModeHigh.FORCE_STAND
elif i == 11:
hcmd.mode = MotorModeHigh.DAMPING
else:
if (i % 2) == 0:
hcmd.mode = MotorModeHigh.STAND_DOWN
else:
hcmd.mode = MotorModeHigh.STAND_UP
# hcmd.mode = MotorModeHigh.STAND_UP
# hcmd.mode = MotorModeHigh.STAND_DOWN
cmd_bytes = hcmd.buildCmd(debug=False)
conn.send(cmd_bytes)
time.sleep(1)
i += 1
if i > 11:
break