Skip to content

Commit

Permalink
optimizing values using real system U3
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Jul 12, 2024
1 parent cea442e commit 28ef41a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
55 changes: 25 additions & 30 deletions field_friend/interface/components/io_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING

import rosys
from nicegui import background_tasks, ui
from nicegui import ui

from .status_bulb import StatusBulb as status_bulb

Expand All @@ -18,13 +18,12 @@ class io_sockets:

def __init__(self, system: System) -> None:
self.system = system
if isinstance(system.field_friend, rosys.hardware.RobotHardware):
self.robot_brain = system.field_friend.robot_brain
with ui.card().style('min-width: 200px; background-color: #3E63A6') as bumper_card:
ui.markdown('**Bumper**').classes('w-full text-center')
ui.separator()
if self.system.field_friend.bumper is not None:
with ui.row():
# TODO test the bumpers because U3 have no Bumpers
status_bulb(True).bind_visibility_from(self.system.field_friend.bumper, 'active_bumpers',
lambda active_bumpers: True if 'front_top' in active_bumpers else False)
status_bulb(False).bind_visibility_from(self.system.field_friend.bumper, 'active_bumpers',
Expand Down Expand Up @@ -119,13 +118,19 @@ def __init__(self, system: System) -> None:
ui.separator()
if self.system.field_friend.wheels is not None:
if self.system.is_real:
# TODO: can messages testen
with ui.row():
if self.system.field_friend.wheels:
status_bulb(True)
else:
status_bulb(False)
ui.label('Moving')
print(self.system.field_friend.wheels.linear_target_speed)
status_bulb(True).bind_visibility_from(
self.system.field_friend.wheels, 'linear_target_speed', lambda x: x > 0 or x < 0)
status_bulb(False).bind_visibility_from(
self.system.field_friend.wheels, 'linear_target_speed', lambda x: x == 0)
ui.label('Forward/Backwards')
with ui.row():
status_bulb(True).bind_visibility_from(
self.system.field_friend.wheels, 'angular_target_speed', lambda x: x > 0 or x < 0)
status_bulb(False).bind_visibility_from(
self.system.field_friend.wheels, 'angular_target_speed', lambda x: x == 0)
ui.label('Turning')
else:
with ui.row():
if self.system.field_friend.wheels:
Expand All @@ -149,30 +154,20 @@ def __init__(self, system: System) -> None:
ui.icon("link_off").props("size=lg").style(
"display: block; margin-left: auto; margin-right: auto; margin-top: 20px; margin-bottom: 20px;")
with ui.card().style('min-width: 200px; background-color: #3E63A6') as batterie_control_card:
ui.markdown('**Battery-Control**').classes('w-full text-center')
ui.markdown('**Battery**').classes('w-full text-center')
ui.separator()
if self.system.is_real and self.system.field_friend.battery_control is not None:
if self.system.is_real:
with ui.row():
status_bulb(True).bind_visibility_from(
self.system.field_friend.bms.state, 'percentage', lambda x: x < 20)
status_bulb(False).bind_visibility_from(
self.system.field_friend.bms.state, 'percentage', lambda x: x >= 20)
ui.label('Battery Low (< 20%)')
with ui.row():
status_bulb(True).bind_visibility_from(self.system.field_friend.battery_control, 'status')
status_bulb(True).bind_visibility_from(self.system.field_friend.bms.state, 'is_charging')
status_bulb(False).bind_visibility_from(
self.system.field_friend.battery_control, 'status', lambda x: not x)
ui.label('Status')
self.system.field_friend.bms.state, 'is_charging', lambda x: not x)
ui.label('Is Charging')
else:
ui.icon("link_off").props("size=lg").style(
"display: block; margin-left: auto; margin-right: auto; margin-top: 20px; margin-bottom: 20px;")
if self.system.is_real:
with ui.card().style('min-width: 200px; background-color: #3E63A6') as batterie_control_card:
ui.markdown('**Expander**').classes('w-full text-center')
ui.separator()
with ui.row():
# TODO add check if the enable pin of expander is active
if True:
status_bulb(True)
else:
status_bulb(False)
ui.label('Enabled')

def set_modules(self) -> None:
self.module_row.clear()
with self.module_row:
ui.label('Get Modules')
29 changes: 12 additions & 17 deletions field_friend/interface/pages/io_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class io_page():

def __init__(self, page_wrapper, system: 'System') -> None:
self.system = system
if isinstance(system.field_friend, rosys.hardware.RobotHardware):
print(self.system.field_friend.robot_brain)
# self.hardwaremanager = HardwareManager(self.system.field_friend.robot_brain)

@ui.page('/io')
def page() -> None:
Expand All @@ -30,24 +27,22 @@ def content(self) -> None:
ui.markdown('**E-Stops**').classes('w-full text-center')
ui.separator()
with ui.row():
if self.system.field_friend.estop.is_soft_estop_active:
status_bulb(True)
else:
status_bulb(False)
status_bulb(True).bind_visibility_from(self.system.field_friend.estop, 'is_soft_estop_active')
status_bulb(False).bind_visibility_from(
self.system.field_friend.estop, 'is_soft_estop_active', lambda x: not x)
ui.label('Soft E-Stop')
if self.system.is_real:
with ui.row():
# TODO: Need to test this, because not sure if '1' and '2' are correct)
status_bulb(True).bind_visibility_from(self.system.field_friend.estop,
'pressed_estops', lambda pressed_estops: '1' in pressed_estops)
status_bulb(False).bind_visibility_from(
self.system.field_friend.estop, 'pressed_estops', lambda pressed_estops: '1' not in pressed_estops or not pressed_estops)
ui.label('Hard E-Stop 1')
if self.system.field_friend.estop.pressed_estops:
status_bulb(True)
else:
status_bulb(False)
with ui.row():
status_bulb(True).bind_visibility_from(self.system.field_friend.estop,
'pressed_estops', lambda pressed_estops: '2' in pressed_estops)
status_bulb(False).bind_visibility_from(
self.system.field_friend.estop, 'pressed_estops', lambda pressed_estops: '2' not in pressed_estops or not pressed_estops)
ui.label('Hard E-Stop 2')
if self.system.field_friend.estop.pressed_estops:
status_bulb(True)
else:
status_bulb(False)
print(self.system.field_friend.estop.pressed_estops)
print(self.system.field_friend.estop.is_soft_estop_active)
io_sockets(self.system)
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def page_wrapper() -> None:
interface.pages.test_page(page_wrapper, system) # /test
interface.pages.kpi_page(page_wrapper, system) # /kpis
interface.pages.monitor_page(page_wrapper, system) # /monitor
interface.pages.io_page(page_wrapper, system) # /monitor
interface.pages.io_page(page_wrapper, system) # /io_overview

@app.get('/status') # /status
def status():
Expand Down

0 comments on commit 28ef41a

Please sign in to comment.