-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Changes from all commits
a7792f3
fa38aaf
ba26792
80bb7ed
d27c137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This member variable isn't used. Should we remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.