b537677277
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
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
"""
|
|
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 |