Skip to content
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

Added Cliff sensor support #37

Merged
merged 6 commits into from
Jan 16, 2024
Merged

Conversation

scottcandy34
Copy link
Contributor

Support for create3 and root

@@ -297,7 +313,7 @@ def when_touched(self, condition: list[bool, bool, bool, bool], callback: Callab
"""Register when touch callback of type: async def fn(front_left: bool, front_right: bool, back_left: bool, back_right: bool)."""
self._when_touched.append(Event(condition, callback))

def when_cliff_sensor(self, condition: list[bool], callback: Callable[[bool], Awaitable[None]]):
def when_cliff_sensor(self, condition: list[bool, bool, bool, bool], callback: Callable[[bool], Awaitable[None]]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is consistent with the current library but makes me realize I may need to do something about type hinting for the case where different robots have different numbers of arguments (this comment is more for me than you 😜 )

Copy link
Collaborator

@shamlian shamlian left a comment

Choose a reason for hiding this comment

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

This PR looks great, I will test it a bit and approve and merge later today if there are no problems. Thanks for your contribution!

for event in self._when_cliff_sensor:
# TODO: Add trigger
await event.run(self)
for event in self._when_cliff_sensor:
Copy link
Collaborator

@shamlian shamlian Jan 12, 2024

Choose a reason for hiding this comment

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

Hey, I'm sorry, but this doesn't work like the rest of the system does, where event conditions are masks, and not exact matches. (Also, this doesn't work at all on Root.) I think we had this conversation some time ago, when you were asking about how the bumper events work. I am going to open a new issue (#40) about how/whether events should latch, or if we should create a way to define events with exact matches (#41), but for now, I want to keep it consistent.

I think it should all actually look like this:

            for event in self._when_cliff_sensor:
                # An empty condition list means to trigger the event on every occurrence.
                if not event.condition and self.cliff_sensor.disable_motors:  # Any.
                    await event.run(self)
                elif len(event.condition) > 0 and len(event.condition) < 3:
                    if (event.condition[0] == self.cliff_sensor.disable_motors):
                        await event.run(self)
                elif len(event.condition) > 3:
                    if ((event.condition[0] and self.cliff_sensor.left) or
                        (event.condition[1] and self.cliff_sensor.front_left) or
                        (event.condition[2] and self.cliff_sensor.front_right) or
                        (event.condition[3] and self.cliff_sensor.right)):
                        await event.run(self)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can PR into your branch, or else if you're willing, could you replace this block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense for the Root, I figured it might be wrong. I can change that, as for the and's to or's I have tried that but it would not work at all after that. So I left it as is (with the and's). Did you have a different experience?

Copy link
Collaborator

@shamlian shamlian Jan 12, 2024

Choose a reason for hiding this comment

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

This block is working on both the Create 3 and Root RT1 that I tested it on, with the installable SDK. How are you testing, with the web interface?

Copy link
Contributor Author

@scottcandy34 scottcandy34 Jan 12, 2024

Choose a reason for hiding this comment

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

Interesting. Yes the web, but currently I'm not near the bot so I can't test again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am happy to wait until you've next got a chance to test. Would be interested to know why it didn't work for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be Monday. I'll check then, its in my office. Same and if its still the same now since you changed the any call. Which could of been the problem.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries at all, I appreciate you taking the initiative to get the cliff event rounded out. Have a great weekend!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IT WORKED! It worked fine. apparently I had some bad logic. I mean my code did work for the create3 but your changes are definingly for the better since it now works for Root and Create3. That makes me feel better knowing the readability of the logic makes sense now.

@shamlian shamlian mentioned this pull request Jan 12, 2024
@shamlian shamlian self-assigned this Jan 12, 2024
@shamlian shamlian merged commit 74502dd into iRobotEducation:pre_0.5.2 Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants