El firmware del controlador del robot té una sèrie d'accions predefinides.
Aquests patrons tenen una durada concreta, diferent en cada cas, i sempre acaben amb la posició per defecte.
xgo.executar_accio (ID ACCIO)
Podem encadenar accions (amb o sense pausa entre una i altra):
xgo.executar_accio (11)
xgo.executar_accio (18)
Podem definir el temps d'execució de l'acció (sortir abans del temps predefinit) i evitar la posició inicial final:
xgo.executar_accio(11, esperar=False)
sleep(6000) # amb aquest sleep definim la durada de l'acció
xgo.executar_accio(18)
Les accions 128, 129, 130 utilitzen el braç
acció 255: postura per defecte
canvis a xgo
Reflectits a https://github.com/TecnoLogicsIB/XGO/blob/main/xgo.py
# --- Accions ---
# Durades de les accions en mil·lisegons (ms)
_DUR_MS = {
1: 3000, # get down
2: 3000, # stand up
3: 5000, # creep forward
4: 5000, # circle around
6: 4000, # squat up
7: 4000, # turn roll
8: 4000, # turn pitch
9: 4000, # turn yaw
10: 7000, # three-axis rotation
11: 7000, # pee
12: 5000, # sit down
13: 7000, # wave
14: 10000, # stretch
15: 6000, # wave
16: 6000, # swing left and right
17: 4000, # begging for food
18: 6000, # looking for food
19: 10000, # shake hands
20: 9000, # chicken head
21: 8000, # push ups
22: 7000, # look around
23: 6000, # dance
24: 7000, # naughty
128: 10000, # catch up
129: 10000, # caught
130: 10000, # catch
255: 1000, # restore default posture
}
def executar_accio(action_id, esperar=True, durada_ms=None):
# Prioritat: durada passada manualment
if durada_ms is not None:
dur = durada_ms
else:
dur = _DUR_MS.get(action_id, 0)
# Enviar ID d'acció al robot
escriure_byte(0x3E, action_id & 0xFF)
# Si cal esperar, ho fem en ms
if esperar and dur > 0:
sleep(dur)
stop_accio()
return dur
def stop_accio():
# 1) prova de cancel·lar acció
escriure_byte(0x3E, 0x00)
sleep(20)
# 2) override mínim per interrompre l'acció (segons la idea "interrupted by other commands")
# posar velocitats a "0" (0x80 és centre/aturat en aquests registres)
escriure_byte(0x30, 0x80) # forward/back speed = 0
escriure_byte(0x31, 0x80) # left/right speed = 0
escriure_byte(0x32, 0x80) # yaw speed = 0
# 3) parar "no progress / step height" (0x00 = stop)
escriure_byte(0x3C, 0x00)