This repository has been archived by the owner on Dec 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_machine.py
56 lines (45 loc) · 1.51 KB
/
state_machine.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
import detect_line
import yolov5_trash
import PID_function
class RobotStateMachine:
def __init__(self):
self.state = "Navigation Mode"
def navigation_mode(self):
print("Robot is in Navigation Mode.")
if self.detect_trash():
self.state = "Trash Picking Mode"
elif self.detect_error():
self.state = "Error Handling"
else:
line_position = detect_line.detect()
motor_input = PID_function.calculate(line_position)
self.motor_move(motor_input)
def error_handling(self):
print("Handling error.")
# Implement actual error handling logic here
self.state = "Navigation Mode"
def trash_picking_mode(self):
print("Robot is in Trash Picking Mode.")
self.state = "Picking Up Mode"
def picking_up_mode(self):
print("Robot is picking up trash.")
if self.more_trash_detected():
self.state = "Trash Picking Mode"
else:
self.state = "Navigation Mode"
def detect_trash(self):
return yolov5_trash.detect()
def detect_error(self):
# Implement actual error detection logic
return False
def more_trash_detected(self):
# Implement logic to detect more trash
return False
def motor_move(self, input):
# Implement motor movement logic
pass
def run(self):
while True:
getattr(self, self.state.lower().replace(" ", "_"))()
robot = RobotStateMachine()
robot.run()