Month: May 2019

I’ve always been a robotics geek and have started exploring ROS. This might help as a ‘how to get started’ post if you’ve wondered how to use ROS with the Raspberry Pi and want to stick to Python.

Why ROS?

Using ROS is likely absolute overkill for most home projects but I am working up to quite a complex project involving different sensors, GPS and at least two motors, so ROS is actually a good fit for where I’m headed.

It will also allow me to keep everything very decoupled and simple. ROS has a heap of features that will come in handy in the future e.g. logging, data play back, data management, test framework, state and config management and more.

I intuitively like the architecture because I know it will keep things simple and it has decent Python libraries which will make for speedy development. I don’t want to be writing a framework, rather I want to focus on motor, sensor and logic code.

Caveat

ROS only supports up to Python 2.7 which’ll be a problem if your Raspberry Pi HATs or pHATs have supporting Python 3 libs only.

Assumptions

I’m going to assume you know some programming, are comfortable on the linux shell, know the basics about Raspberry PI GPIO pins so won’t do much extra explanation.

‘heading’ is just a variable name that corresponds to a compass heading where the buttons turn left or right deducting or subtracting 15 degrees from the previous value.

What’s next?

In this example, we see ROS decoupling sensor reading code from the action code. It would be possible to add more hardware to the PI and wire it together with more publisher/subscriber code and custom logic. See more on publishers and subscribers.

logic could be triggered to drive a motor, move a servo or trigger a solenoid. With a more complicated robot, ROS is ideal to keep the application simple and all parts decoupled, and allow incremental development.