ROS, rosserial, and Micropython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

ROS, rosserial, and Micropython

Post by dbc » Tue Jul 04, 2017 4:05 am

There are at least a few people that hang out here that build robots. Is anyone else doing anything with ROS? http://www.ros.org/

For some time, there has been a package called rosserial that is used as a serial/UART bridge from the main Linux (server) system running ROS, to (client) microcontrollers, originally the Arduino, but there are more implementations now. It strikes me that with the PyBoard one could to a much better ucontroller-side implementation with the PyBoard. The client-side data serialization protocol should be implementable in cross-compiled Micropython, but for performance I would think it would make sense to do a C extension and compile it into the flash build. The automatically-generated Python modules for message definition imports might just work as-is, or perhaps the generator script would need a tweak, but then the message definitions could be cross compiled, and built into the flash.

Then there is the rospy module. I envision doing a urospy module that implements a stripped version of rospy. It would probably need to be built on top of uasyncio to get threading. As such, it would be a fairly large deviation from rospy (which is ancient callback-based code), but I think a core API could be kept very congruent. With all that machinery in place, it is conceivable that a ROS node that didn't use messages beyond the std_msgs library could be done entirely in a simple Micropython script. Custom messages would probably require some file copying jiggery-pokery -- but compared to the end-to-end jiggery-pokery of rosserial/Arduino, it would be cake.

Seems to me a Plug-and-Play Ready-to-ROS .dfu file should be an achievable goal.

So... any other ROS users out there have an opinion on this? All you robot builders out there rise and be counted.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: ROS, rosserial, and Micropython

Post by deshipu » Tue Jul 04, 2017 7:29 am

I tried to approach ROS several times, but every time the learning curve was steep and it didn't really implement the things I wanted anyways, so my motivation was very low.

I think your ideas are all fine and potentially implementable, but I think that we need to take a step back and think about what we actually want to build. There is an infinite number of ideas that could potentially be implemented, to pick the ones that make sense you need some kind of grounding in a real-life project.

User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: ROS, rosserial, and Micropython

Post by dbc » Tue Jul 04, 2017 3:36 pm

Everything you say is true. ROS has a huge learning curve, no dispute there. I can't claim to be a ROS expert.

To your second point about being grounded in a real-world project -- that is what I am trying to do. I've been building robots as a hobby fore more than 10 years, and lately have been doing ROS-based robots. I am working on two that use a RasPi as the Linux machine and I want to use PyBoards for hard realtime. A serial connection between the two is the natural way to do that, rosserial is the ROS-ish way to connect a microcontroller over a serial line.

I sympathize with the difficulty in learning ROS. Our local robot club as a ROS special-interest-group that meets to work through issues, and I have the good fortune to live at ground-zero for ROS-based commercial robotics work so I have a lot of friends that I can quiz. If not for that, ROS progress would be very slow indeed.

What I was hoping to do with this post is surface any ROS users that are hiding in the woodwork here in the Micropython world, because I think most of the work in getting rosserial to work with Micropython is on the Micropython side of the connection, but it requires an understanding of the ROS way of doing things.

veverak
Posts: 2
Joined: Tue Jul 04, 2017 9:34 pm

Re: ROS, rosserial, and Micropython

Post by veverak » Tue Jul 04, 2017 10:08 pm

Hi!

I gained some ROS experience over last few years and now I am working on project in ros. (C++ now though)

I think that this is definetly a good idea, but I think that bigger goal should be to get full integration at the end of the road.

That is, I believe we can find a way how to design mechanism for fellow ros users nad micropython users. Where you can get _full set_ of the both worlds.

One idea that struck me is to develop tool that could collect source code from multiple ros packages (one basic package and all it's dependencis) and compile them into micropython device. Which could be just smart 'hack' of standart ROS tools. This could of course just import all needed (even custom) messages into micropython, if we can guarantee that they will be usable.

I also think that going for 'simpler' rospy library in 'c' is best course of action. Best would be to get even 'c' version of messages, but afaik C++ version is not usable and writing generator may be a lot of work.

Do you think that makes sense?

User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: ROS, rosserial, and Micropython

Post by dbc » Wed Jul 05, 2017 3:04 am

Native ROS is resource intensive, and assumes a network connection. Either roscpp or rospy based nodes have a fairly large footprint, so an entire ROS system just seems a bit too large for a Microcontroller. We (the local robot club) have done pretty well running ROS on a RasPi3, but even then you can't do any heavy computer vision. Mapping and AMCL with a LiDAR work pretty well, though. (We mostly use hacked Neato Botvac vacuum cleaners. Cheapest Lidar you can get, just throw away the vacuum cleaner it is attached to :) but actually the Neato makes a decent base for a ROS-based robot.)

My motivation for using rosserial is that it is designed to allow you to do hard realtime in a microcontroller, even as small as an Arduino, and use a serial port to send ROS messages to the larger ROS system. I think it would be very memory efficient on a PyBoard or other Micropython system. But with Micropython, you could approximate the rospi API.

What kind of things are you doing with ROS? Have you ever checked out the rosserial package?

veverak
Posts: 2
Joined: Tue Jul 04, 2017 9:34 pm

Re: ROS, rosserial, and Micropython

Post by veverak » Thu Jul 06, 2017 12:08 am

Hmm, yeah, figuring out what exactly we expect from ROS micropython devices is good point, somehow I got stuck with only esp8266 in my head...

I did a pretty a lot of thing around esp8266 (with micropython), ROS and I am currectly in heavy development of C++ app for rpi3 robot (walking robot, a lot of computation, have to spent a lot of time with optimalization). So may be out of touch with micropython a bit.

However I would gladly support any work regarding this. My ideal state is where I am able to easily connect multiple esp8266 into ROS 'network' as sensory/control modules for specific hardware.

Such as being able to deploy small robot with only esp8266 and two motors from my big rpi3 based ROS robot is awesome goal to work to.

Hmm, It looks like I didn't remembered things about rosserial correctly, anyway big question is, can we somehow connect on #micropython@freenode ?

User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: ROS, rosserial, and Micropython

Post by dbc » Thu Jul 06, 2017 7:12 pm

https://github.com/ros-drivers/rosserial
is the git repo for rosserial. the sub-directory rosserial_python contains a rosserial server (Linux host side) implementation of the rosserial protocol. It is Python 2.7 for historical reasons. I'm currently reading it to get a sound understanding of the protocol.

Other subdirectories in the repo contain a C++ host, and various rosserial clients. I'm thinking a micropython rosserial client is a doable thing, within the constraints that SRAM puts on maximum message sizes. (The maximum ROS message is 2Gbytes... and the map topic for a large warehouse can blow that away pretty quickly... not that I am doing warehouses or even think it is interesting to send the map topic to a microcontroller...)

@veverak My ESP8266 is sitting, unused, on my workbench, silently mocking me. I don't have a good feel for how much can be shoe-horned into it. IIRC there is no float on the ESP8266? The standard ROS messages contain a lot of float types. Also, since you are currently using roscpp, maybe you could comment on what you think could be stripped out of the rospy API to create a small footprint urospy to run on the client side.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ROS, rosserial, and Micropython

Post by pythoncoder » Fri Jul 07, 2017 4:28 am

ESP8266 does support float. You're probably thinking of the WiPy V1.
Peter Hinch
Index to my micropython libraries.

User avatar
dbc
Posts: 89
Joined: Fri Aug 28, 2015 11:02 pm
Location: Sunnyvale, CA

Re: ROS, rosserial, and Micropython

Post by dbc » Fri Jul 07, 2017 8:43 pm

@pythoncoder Yes, you are correct, I was confused. Thanks!

hybotics
Posts: 33
Joined: Tue Apr 03, 2018 2:58 am
Contact:

Re: ROS, rosserial, and Micropython

Post by hybotics » Tue Apr 03, 2018 3:45 am

Hi,

I have been aware of Micropython for a long time. It was not until Adafruit came out with their Circuit Python, based on Micropython, that I became interested in using Python based micros for robotics. I have been doing a lot of experimentation with Circuit Python on a Feather M0 Express and various Adafruit FeatherWing boards. This is what has brought me to the point of actually digging in and exploring Micropython for use in my robot projects.

I have been building robots for 12 years. I have done some work with ROS, including rosserial and an Arduino Mega, and it does work. I am working on a small robot based on a kit from Adafruit. I am thinking about using a Raspberry Pi 3 running ROS to talk to one or more smaller MCUs such as the Adafruit Feather boards running Adafruit's Circuit Python to handle dedicated tasks.

I am now starting to explore the possibility of using Micropython to talk to a ROS based node. I want to find out how difficult it would be to write libraries for Micropython or convert other libraries to Micropython. I am using VL53L0X sensors for distance checking, so might need to create a library for these.

I am very interested in any work that would be done to get Micropython to talk to ROS. If it can be done with an Arduino, I can not imagine it would be more difficult to do it with Micropython if rosserial is used.

8-Dale

Post Reply