Skip to content

Commit

Permalink
adding basic roboter info to the app control
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Nov 25, 2024
1 parent 1651b81 commit 4859240
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
39 changes: 39 additions & 0 deletions field_friend/app_controls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from rosys.automation import Automator
from rosys.automation import app_controls as RosysAppControls
from rosys.hardware import RobotBrain

from .hardware.field_friend import FieldFriend


class AppControls(RosysAppControls):

def __init__(self,
robot_brain: RobotBrain,
automator: Automator,
robot: FieldFriend,
) -> None:
super().__init__(robot_brain, automator)
self.robot = robot
self.last_info: str = ''
self.APP_CONNECTED.register(self.reset)

async def sync(self) -> None:
await super().sync()
infos = []

if self.robot.estop.active:
infos.append("E Stop active")
if self.robot.bumper.active_bumpers:
infos.append(f'Bumper ({" ".join(self.robot.bumper.active_bumpers)}) active')
if self.robot.bms.state.is_charging:
infos.append('charging battery')
battery = f'{self.robot.bms.state.percentage:.0f}%' if self.robot.bms.state.percentage is not None else '?'
infos.append(f'Battery: {battery}')

info = ' | '.join(infos)
if info != self.last_info:
await self.set_info(info)
self.last_info = info

def reset(self) -> None:
self.last_info = 'loading'
6 changes: 4 additions & 2 deletions field_friend/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import psutil
import rosys

from .app_controls import AppControls as app_controls
import config.config_selection as config_selector

from . import localization
Expand Down Expand Up @@ -183,7 +183,9 @@ def watch_robot() -> None:
assert isinstance(self.field_friend, FieldFriendHardware)
if self.field_friend.battery_control:
self.battery_watcher = BatteryWatcher(self.field_friend, self.automator)
rosys.automation.app_controls(self.field_friend.robot_brain, self.automator)
# rosys.automation.app_controls(self.field_friend.robot_brain, self.automator)
app_controls(
robot_brain=self.field_friend.robot_brain, automator=self.automator, robot=self.field_friend)
rosys.on_repeat(self.log_status, 60*5)

def restart(self) -> None:
Expand Down

0 comments on commit 4859240

Please sign in to comment.