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

Docking sensor event not exist #11

Closed
scottcandy34 opened this issue Jan 16, 2023 · 3 comments · Fixed by #31 or #32
Closed

Docking sensor event not exist #11

scottcandy34 opened this issue Jan 16, 2023 · 3 comments · Fixed by #31 or #32
Assignees
Labels
enhancement New feature or request

Comments

@scottcandy34
Copy link
Contributor

scottcandy34 commented Jan 16, 2023

I have create3 robot Firmware version (G.3.1) and have found that the docking sensor event has not been added yet for the robot found here https://github.com/iRobotEducation/root-robot-ble-protocol#command-0---docking-sensor-event

I have done an override class to implement it

class DockingSensor:
    def __init__(self):
        self.contact = 0
        self.sensor_0 = 0
        self.sensor_1 = 0

class Create3(Create3):
    def __init__(self, backend):
        super().__init__(backend)

        self._events[(19, 0)] = self._when_docking_sensor_handler

        self.docking_sensor = DockingSensor()

        self._when_docking_sensor: list[Event] = []

    def when_docking_sensor(self, callback: Callable[[bool], Awaitable[None]]):
        self._when_docking_sensor.append(Event(True, callback))

    async def _when_docking_sensor_handler(self, packet):
        for event in self._when_docking_sensor:
            if len(packet.payload) > 4:
                self.docking_sensor.contact = packet.payload[4] != 0
                self.docking_sensor.sensor_0 = packet.payload[5] != 0
                self.docking_sensor.sensor_1 = packet.payload[6] != 0
                await event.run(self)

I only did a simple implementation of this. Can this be added to the create3.py, maybe with [int, int, int] or something similar to have a more specific control over what it is sensing.

@shamlian shamlian added the enhancement New feature or request label Jan 16, 2023
@shamlian
Copy link
Collaborator

shamlian commented Dec 8, 2023

The basics of this are in pre_0.5.0 and I will plan to improve the docking sensor event and getter in a future update. See #30 . I will close this when I merge 0.5.0 to main.

@shamlian shamlian mentioned this issue Dec 8, 2023
@shamlian shamlian linked a pull request Dec 8, 2023 that will close this issue
shamlian added a commit that referenced this issue Dec 11, 2023
Pre 0.5.0
* Add color sensor support (close #4)
* Add docking sensor support (close #11)
* Fix logical error causing events to not save state without handlers
* Use proper Python enums for most getter types and commands
* Update and add examples
* General syntax improvements
* Add experimental and questionably-documented Turtle _backend_
* Bump minimum Python version to 3.10
@shamlian
Copy link
Collaborator

Because I saw your other question -- there was some merge weirdness here because someone pressed the wrong button, and then I did a bad job rewriting the history. But rest assured, this is merged in.

@scottcandy34
Copy link
Contributor Author

Ah, I figured once I dug into it I noticed that it was merged so I deleted my comment. I like what you did with it much better and improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants