Skip to content

Estop and bumper use active #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions rosys/hardware/bumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,24 @@ def __init__(self, robot_brain: RobotBrain, *,
expander: ExpanderHardware | None = None,
name: str = 'bumper',
pins: dict[str, int],
estop: EStop | None = None) -> None:
estop: EStop | None = None,
inverted: bool = False) -> None:
self.name = name
self.pins = pins
self.inverted = inverted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This member variable isn't used. Should we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be interesting for other parts of the code to know if the pins are inverted, especially for debugging purposes.

lizard_code = ''
for pin, number in pins.items():
lizard_code += f'{name}_{pin} = {expander.name + "." if expander else ""}Input({number})\n'
core_message_fields = [f'{name}_{pin}.level' for pin in pins]
if inverted:
lizard_code += f'{name}_{pin}.inverted = true\n'
core_message_fields = [f'{name}_{pin}.active' for pin in pins]
super().__init__(robot_brain=robot_brain,
lizard_code=lizard_code,
core_message_fields=core_message_fields,
estop=estop)

def handle_core_output(self, time: float, words: list[str]) -> None:
active_bumpers = [pin for pin in self.pins if int(words.pop(0)) == 1]
active_bumpers = [pin for pin in self.pins if words.pop(0) == 'true']
if self.estop and self.estop.active:
return
for pin in active_bumpers:
Expand Down
9 changes: 6 additions & 3 deletions rosys/hardware/estop.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ class EStopHardware(EStop, ModuleHardware):
The module expects a dictionary of pin names and pin numbers.
"""

def __init__(self, robot_brain: RobotBrain, *, name: str = 'estop', pins: dict[str, int]) -> None:
def __init__(self, robot_brain: RobotBrain, *, name: str = 'estop', pins: dict[str, int], inverted: bool = True) -> None:
self.name = name
self.pins = pins
self.inverted = inverted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This member variable isn't used. Should we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be interesting for other parts of the code to know if the pins are inverted, especially for debugging purposes.

lizard_code = '\n'.join(f'{name}_{pin} = Input({number})' for pin, number in pins.items())
core_message_fields = [f'{name}_{pin}.level' for pin in pins]
if inverted:
lizard_code += '\n' + '\n'.join(f'{name}_{pin}.inverted = true' for pin in pins)
core_message_fields = [f'{name}_{pin}.active' for pin in pins]
super().__init__(robot_brain=robot_brain, lizard_code=lizard_code, core_message_fields=core_message_fields)

async def set_soft_estop(self, active: bool) -> None:
await super().set_soft_estop(active)
await self.robot_brain.send(f'en3.level({"false" if active else "true"})')

def handle_core_output(self, time: float, words: list[str]) -> None:
corelist = [int(words.pop(0)) == 0 for _ in self.pins]
corelist = [words.pop(0) == 'true' for _ in self.pins]
active = any(corelist)
pressed = [index for index, value in enumerate(corelist) if value]
if pressed != self.pressed_estops:
Expand Down