Complete Restructered Robot Code
Robot into its own Class instead of lose Global Variables that cause circular imports StateClass usage instead of the old RobotState.py New Input Class for Controller and randome intputs
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
inputs/RandomInputProvider.py - Random Command Generator for Simulation / Training
|
||||
"""
|
||||
import random
|
||||
import time
|
||||
from inputs.InputProvider import InputProvider, CommandFrame
|
||||
|
||||
|
||||
class RandomInputProvider(InputProvider):
|
||||
def __init__(self, change_interval: float = 2.0):
|
||||
self.change_interval = change_interval
|
||||
self.last_change = time.time()
|
||||
self.current_command = CommandFrame()
|
||||
|
||||
def get_command(self) -> CommandFrame:
|
||||
now = time.time()
|
||||
if now - self.last_change > self.change_interval:
|
||||
self.last_change = now
|
||||
|
||||
# 20% chance to idle, 80% to walk randomly
|
||||
if random.random() < 0.2:
|
||||
self.current_command = CommandFrame(
|
||||
state="idle",
|
||||
vector_dirmov=[0.0, 0.0, 0.0]
|
||||
)
|
||||
else:
|
||||
vx = random.uniform(-1.0, 1.0)
|
||||
vy = random.uniform(-1.0, 1.0)
|
||||
omega = random.uniform(-1.0, 1.0)
|
||||
self.current_command = CommandFrame(
|
||||
state="walking",
|
||||
vector_dirmov=[vx, vy, omega]
|
||||
)
|
||||
|
||||
return self.current_command
|
||||
Reference in New Issue
Block a user