Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalzauberzeug committed Dec 9, 2024
1 parent c9a786f commit a4c352d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
33 changes: 16 additions & 17 deletions field_friend/app_controls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import rosys
from rosys.automation import Automator
from rosys.automation import app_controls as RosysAppControls # noqa ignore this due to being a class
from rosys.automation.app_controls_ import AppControls as RosysAppControls
from rosys.hardware import RobotBrain

from .hardware.field_friend import FieldFriend
Expand All @@ -11,36 +11,35 @@ class AppControls(RosysAppControls):
def __init__(self,
robot_brain: RobotBrain,
automator: Automator,
robot: FieldFriend,
field_friend: FieldFriend,
) -> None:
super().__init__(robot_brain, automator)
self.robot = robot
self.last_battery_percentage: float | None = self.robot.bms.state.percentage
self.last_charging: bool | None = self.robot.bms.state.is_charging
self.field_friend = field_friend
self.last_battery_percentage: float | None = self.field_friend.bms.state.percentage
self.last_charging: bool | None = self.field_friend.bms.state.is_charging
self.last_info: str = ''
self.APP_CONNECTED.register(self.reset)
if self.robot.bumper:
self.robot.bumper.BUMPER_TRIGGERED.register(self.sync)
self.robot.estop.ESTOP_TRIGGERED.register(self.sync)
if self.field_friend.bumper:
self.field_friend.bumper.BUMPER_TRIGGERED.register(self.sync)
self.field_friend.estop.ESTOP_TRIGGERED.register(self.sync)
rosys.on_repeat(self.check_battery, 5.0)

async def check_battery(self) -> None:
if self.robot.bms.state.percentage != self.last_battery_percentage or self.robot.bms.state.is_charging != self.last_charging:
self.last_battery_percentage = self.robot.bms.state.percentage
self.last_charging = self.robot.bms.state.is_charging
if self.field_friend.bms.state.percentage != self.last_battery_percentage or self.field_friend.bms.state.is_charging != self.last_charging:
self.last_battery_percentage = self.field_friend.bms.state.percentage
self.last_charging = self.field_friend.bms.state.is_charging
await self.sync()

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

if self.robot.estop.active:
if self.field_friend.estop.active:
infos.append('E Stop active')
if self.robot.bumper and self.robot.bumper.active_bumpers:
infos.append(f'Bumper ({" ".join(self.robot.bumper.active_bumpers)}) active')
if self.robot.bms.state.is_charging:
if self.field_friend.bumper and self.field_friend.bumper.active_bumpers:
infos.append(f'Bumper ({" ".join(self.field_friend.bumper.active_bumpers)}) active')
if self.field_friend.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 '?'
battery = f'{self.field_friend.bms.state.percentage:.0f}%' if self.field_friend.bms.state.percentage is not None else '?'
infos.append(f'Battery: {battery}')

info = ' | '.join(infos)
Expand Down
18 changes: 3 additions & 15 deletions field_friend/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,15 @@
PlantProvider,
Puncher,
)
from .automations.implements import (
ExternalMower,
Implement,
Recorder,
Tornado,
WeedingScrew,
)
from .automations.implements import ExternalMower, Implement, Recorder, Tornado, WeedingScrew
from .automations.navigation import (
CrossglideDemoNavigation,
FieldNavigation,
FollowCropsNavigation,
Navigation,
StraightLineNavigation,
)
from .hardware import (
FieldFriend,
FieldFriendHardware,
FieldFriendSimulation,
TeltonikaRouter,
)
from .hardware import FieldFriend, FieldFriendHardware, FieldFriendSimulation, TeltonikaRouter
from .info import Info
from .kpi_generator import generate_kpis
from .localization.geo_point import GeoPoint
Expand Down Expand Up @@ -186,8 +175,7 @@ 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)
app_controls(
robot_brain=self.field_friend.robot_brain, automator=self.automator, robot=self.field_friend)
app_controls(self.field_friend.robot_brain, self.automator, self.field_friend)
rosys.on_repeat(self.log_status, 60*5)

def restart(self) -> None:
Expand Down

0 comments on commit a4c352d

Please sign in to comment.