merge conflict and readme update

old code was uploaded in the initial upload
changed everything with working programm and updated the readme
This commit is contained in:
2026-07-29 22:35:41 +02:00
parent 1e660fcdb6
commit 2b2125bfde
9 changed files with 723 additions and 343 deletions
+46 -48
View File
@@ -1,62 +1,60 @@
from threading import Thread
from multiprocessing import Process, Manager, Queue
import time
# Selfmade Libraries
import Controller as ctr
import RobotState as rs
# Global Variables
import GlobalVariables as gv
# main.py
import time
import threading
from DataTypes import ControlIntent
from RobotState.RobotState import RobotContext
from Controller import controller_loop
from RobotState.idle import IdleState
from RobotState.walking import WalkingState
def robot_control():
# Connection
if gv.robotCommunication != None:
gv.robotCommunication.start()
import DataTypes as dt
# Start Position
rs.initPos()
time.sleep(1)
def main():
intent = ControlIntent()
lock = threading.Lock()
ctx = RobotContext()
############################## Main Loop ##############################
tick = 0.05
next_time = time.time()
ctx.center_points = dt.PosArray([
[50, 50, -80],
[50,-50, -80],
[0, 70, -80],
[0,-70, -80],
[-50,50, -80],
[-50,-50,-80]
])
ctx.current_pos = ctx.center_points.copy()
while gv.control_pause == False:
next_time += tick
controller_thread = threading.Thread(
target=controller_loop,
args=(intent, lock),
daemon=True
)
controller_thread.start()
if gv.emote == "wave":
rs.initPos()
time.sleep(0.3)
rs.wave_emote()
gv.emote = None
gv.robot_state = "idle"
continue
states = {
"idle": IdleState(),
"walking": WalkingState()
}
# Robot
if gv.robot_state == "idle":
rs.initPos()
time.sleep(0.2)
elif gv.robot_state == "walking":
rs.walking()
current = states["idle"]
current.on_enter(ctx)
# Simulation
if gv.shared_sim != None:
gv.shared_sim.step()
last = time.perf_counter()
sleep_time = next_time - time.time()
if sleep_time > 0:
time.sleep(sleep_time)
while not intent.quit:
now = time.perf_counter()
dt_s = now - last
last = now
next_state = current.update(ctx, intent, dt_s)
if next_state:
current.on_exit(ctx)
current = states[next_state]
current.on_enter(ctx)
time.sleep(0.01)
if __name__ == "__main__":
main()
controller_queue = Queue()
robot_queue = Queue()
controller_thread = Thread(target=ctr.controller)
controller_thread.start()
robot_control_thread = Thread(target=robot_control)
robot_control_thread.start()