Disconnection detection added
PC checks for connection Esp32 send Heartbeat
This commit is contained in:
@@ -19,6 +19,8 @@ from ArduinoCommunication import ArduinoCommunication
|
||||
|
||||
class RobotBackend(Protocol):
|
||||
"""Protocol defining hardware abstraction for both Simulation and Hardware backends."""
|
||||
@property
|
||||
def connection_status(self) -> Optional[str]: ...
|
||||
def send_angles(self, rad_array: dt.RadArray) -> None: ...
|
||||
def step_simulation(self) -> None: ...
|
||||
def hard_reset_joints(self, target_angles: np.ndarray) -> None: ...
|
||||
@@ -35,6 +37,10 @@ class HardwareBackend:
|
||||
self.comm_channel = comm_channel
|
||||
self.internal_angles = np.zeros(18, dtype=np.float32)
|
||||
|
||||
@property
|
||||
def connection_status(self) -> Optional[str]:
|
||||
return getattr(self.comm_channel, "connection_status", None)
|
||||
|
||||
def send_angles(self, rad_array: dt.RadArray) -> None:
|
||||
self.internal_angles = rad_array.data.flatten().copy()
|
||||
if self.comm_channel:
|
||||
@@ -71,6 +77,10 @@ class PyBulletBackend:
|
||||
def __init__(self, sim_instance: Simulation):
|
||||
self.sim = sim_instance
|
||||
|
||||
@property
|
||||
def connection_status(self) -> Optional[str]:
|
||||
return None
|
||||
|
||||
def send_angles(self, rad_array: dt.RadArray) -> None:
|
||||
if self.sim:
|
||||
self.sim.set_robot_joint_angles(rad_array)
|
||||
@@ -171,6 +181,10 @@ class Robot:
|
||||
if self.backend:
|
||||
self.backend.send_angles(self.current_rad)
|
||||
|
||||
@property
|
||||
def connection_status(self) -> Optional[str]:
|
||||
return self.backend.connection_status
|
||||
|
||||
def step_sim(self) -> None:
|
||||
if self.backend:
|
||||
self.backend.step_simulation()
|
||||
|
||||
Reference in New Issue
Block a user