changes in operation: testing

This commit is contained in:
Björn Ellensohn 2023-08-22 08:48:42 +02:00
parent c07ee727d7
commit 812b58ac89

View File

@ -15,9 +15,11 @@ import signal
import sys import sys
class State(Enum): # is this best-practice? class State(Enum): # is this best-practice?
DISABLED = 0 DISABLED = 0 # solid yellow
PAUSED = 1 ENABLED = 1 # solid green
ENABLED = 2 PASSIVE = 2 # solid white (push)
STOPPED = 3 # solid red
PAUSED = 4 # no extra visual feedback, solid yellow
class StateMachineNode(Node): class StateMachineNode(Node):
def __init__(self): def __init__(self):
@ -58,12 +60,17 @@ class StateMachineNode(Node):
self.chassis_mode = State.DISABLED self.chassis_mode = State.DISABLED
def chassis_mode_callback(self, msg): def chassis_mode_callback(self, msg):
# Handle the incoming chassis status message # Handle the incoming chassis status message, will update every second
# Need to figure out the type # Need to figure out the type
if msg.chassis_mode == 0:
self.chassis_mode = State.DISABLED
if msg.chassis_mode == 1: # Assuming 1 represents enabled and 0 represents disabled if msg.chassis_mode == 1: # Assuming 1 represents enabled and 0 represents disabled
self.chassis_mode = State.ENABLED self.chassis_mode = State.ENABLED
else: if msg.chassis_mode == 2:
self.chassis_mode = State.DISABLED self.chassis_mode = State.PASSIVE
if msg.chassis_mode == 3:
self.chassis_mode = State.STOPPED
def get_chassis_mode(self): def get_chassis_mode(self):
return self.chassis_mode return self.chassis_mode
@ -114,7 +121,8 @@ class StateMachineNode(Node):
self.timeout = 20.0 self.timeout = 20.0
def timer_callback(self): def timer_callback(self):
#if self.state == State.ENABLED: if self.chassis_mode == State.DISABLED or self.chassis_mode == State.STOPPED or self.chassis_mode == State.PASSIVE:
return # Do nothing if chassis is disabled, stopped or passive --> should save processing power
if self.chassis_mode == State.ENABLED: if self.chassis_mode == State.ENABLED:
if self.timeout <= 0: if self.timeout <= 0:
self.state = State.PAUSED self.state = State.PAUSED