iRobotEducation / irobot-edu-python-sdk

Python SDK for iRobot Edu robots (Root or Create 3)
BSD 3-Clause "New" or "Revised" License
16 stars 6 forks source link

Cliffsensor issue #6

Closed carlitoselmago closed 1 year ago

carlitoselmago commented 1 year ago

I'm trying to add a control function when the robot detects a cliff. It does it well but also it stops the motors and doesn't allow me to handle the situation and continue running.

I'm using this:

@event(robot.when_cliff_sensor,precipicimanager)
async def onprecipici(robot):
    print("handle the cliff")

But it never fires

I've seen that there is this function on the robot.py class

async def enable_events(self, bitfield: bytes):
        """Enable notifications for events. Accepts 128-bit bitfield for devices 0 to 127."""
        await self._backend.write_packet(Packet(0, 7, self.inc, bitfield))

But I don't quite understand how to use it.

Also maybe related to this, is there a way to detect / handle other events like kindap (based on the ROS2 topics I've seen) and motor_stalled?

shamlian commented 1 year ago

Are you using a Create 3 or a Root robot? I assume Create 3 since you have mentioned ROS 2. For the Root robot, cliff sensors cannot be disabled, and they will halt the motor no matter what. For Create 3, it is possible to disable the internal cliff sensor safety mechanism by setting the safety_override parameter to full (docs here), but when the robot goes into this Bluetooth mode, I believe the parameter is set to backup_only, instead, to try to operate the same as a Root robot. Do you have ROS 2 up and running? Try setting the parameter after you've connected over BLE. It is also possible that overriding this in the webserver might work, but I will have to check.

carlitoselmago commented 1 year ago

Using a Create3, Ill check it out, thanks so much!

carlitoselmago commented 1 year ago

I tried setting the "full" mode thru the webserver and it doesn't seem to work when used in the bluetooth mode as you mentioned. Now trying the other aproach, I cannot find a way to both comunicate with the robot ros2 server and then run this sdk. Tried on usb mode succesfully setting the full mode with a ros command but then not being able to connect thru serial mode (as mentioned in the ALPHA part of the readme) nor being able to connect to ros2 thru BLE and then running ros2 commands. Is this last part something that can be done entirely with python? I just tried on linux terminal using:

sudo bluetoothctl

but I don't know how to comunicate with ros with this

shamlian commented 1 year ago

Create 3 does not have a serial port to connect to. As it says in the README, the Serial backend is for "some Root® robots."

I suspect you are desiring to do something that is not currently supported via the Python SDK. The only way I can think of for you to work around it is, once the BLE connection is established, to send a ROS 2 message to change the safety_override policy. You could do this in Python in a hacky way with a call to exec(), perhaps, to run a script which sends the proper ros2 call (or to send the call directly -- maybe exec('ros2 param set /motion_control safety_override full') will work?).

shamlian commented 1 year ago

It sounds to me like you would rather use the Python SDK to communicate wired to the Create 3 robot rather than use ROS 2; unfortunately, that's not a use case we currently have covered. It occurs to me that one could write a "ROS 2" backend for the Python SDK for use with Create robots, but that's something I don't expect will get done quickly. Feel free to add an "enhancement" issue for that, and we can try to prioritize it, if that's something you're interested to see!

carlitoselmago commented 1 year ago

Thanks so much for all the information!

Yes I've been trying to use the SDK since I never used ROS and it feels a bit overwhelming at this point. Ill add the enhancement issue, thanks again.