Add copy methods, fix state imports, pass lock
Add copy() to PosArray, DegArray and RadArray to allow easy shallow copies. Change RobotState imports in idle.py and walking.py to use explicit 'from RobotState.RobotState import RobotState' to avoid import issues. In main.py create a threading.Lock and pass it into the controller thread args to prepare for synchronized access in controller_loop.
This commit is contained in:
@@ -19,6 +19,8 @@ class PosArray:
|
|||||||
def __getitem__(self, key): return self.data[key]
|
def __getitem__(self, key): return self.data[key]
|
||||||
def __iter__(self): return iter(self.data)
|
def __iter__(self): return iter(self.data)
|
||||||
def __repr__(self): return f"PosArray(\n{self.data}\n)"
|
def __repr__(self): return f"PosArray(\n{self.data}\n)"
|
||||||
|
def copy(self):
|
||||||
|
return PosArray(self.data.copy())
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -37,6 +39,8 @@ class DegArray:
|
|||||||
def __getitem__(self, key): return self.data[key]
|
def __getitem__(self, key): return self.data[key]
|
||||||
def __iter__(self): return iter(self.data)
|
def __iter__(self): return iter(self.data)
|
||||||
def __repr__(self): return f"PosArray(\n{self.data}\n)"
|
def __repr__(self): return f"PosArray(\n{self.data}\n)"
|
||||||
|
def copy(self):
|
||||||
|
return DegArray(self.data.copy())
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RadArray:
|
class RadArray:
|
||||||
@@ -53,6 +57,8 @@ class RadArray:
|
|||||||
def __getitem__(self, key): return self.data[key]
|
def __getitem__(self, key): return self.data[key]
|
||||||
def __iter__(self): return iter(self.data)
|
def __iter__(self): return iter(self.data)
|
||||||
def __repr__(self): return f"PosArray(\n{self.data}\n)"
|
def __repr__(self): return f"PosArray(\n{self.data}\n)"
|
||||||
|
def copy(self):
|
||||||
|
return RadArray(self.data.copy())
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RobotCommand:
|
class RobotCommand:
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import RobotState
|
from RobotState.RobotState import RobotState
|
||||||
|
|
||||||
class IdleState(RobotState):
|
class IdleState(RobotState):
|
||||||
def update(self, ctx, intent, dt):
|
def update(self, ctx, intent, dt):
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import numpy as np
|
|||||||
import config as cfg
|
import config as cfg
|
||||||
import kinematics as kin
|
import kinematics as kin
|
||||||
import DataTypes as dt
|
import DataTypes as dt
|
||||||
import RobotState
|
from RobotState.RobotState import RobotState
|
||||||
|
|
||||||
class WalkingState(RobotState):
|
class WalkingState(RobotState):
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import DataTypes as dt
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
intent = ControlIntent()
|
intent = ControlIntent()
|
||||||
|
lock = threading.Lock()
|
||||||
ctx = RobotContext()
|
ctx = RobotContext()
|
||||||
|
|
||||||
ctx.center_points = dt.PosArray([
|
ctx.center_points = dt.PosArray([
|
||||||
@@ -29,7 +30,7 @@ def main():
|
|||||||
|
|
||||||
controller_thread = threading.Thread(
|
controller_thread = threading.Thread(
|
||||||
target=controller_loop,
|
target=controller_loop,
|
||||||
args=(intent,),
|
args=(intent, lock),
|
||||||
daemon=True
|
daemon=True
|
||||||
)
|
)
|
||||||
controller_thread.start()
|
controller_thread.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user