Chapter 15. Your Own Sensors and Actuators

Up until now, we’ve looked at how you can use ROS to interact with existing sensor and actuator hardware. Although ROS covers a wide variety of popular sensors and actuators, it doesn’t cover all of them. As new hardware becomes available, we’ll have to bring it into ROS, so that it can be used by the community.

In this chapter, we’ll see how you can integrate new sensors and actuators into the ROS ecosystem. This process is, for the most part, relatively painless; it involves writing ROS wrappers around the APIs that you’re already using to access these devices. We’ll start off with adding your own sensors.

Adding Your Own Sensors

How do you add a new sensor to ROS? We’re going to assume that the sensor already has a Python API that you can call to get measurements from it, and that you know how to use this API. We’re also going to assume that everything is wired up correctly and that you’ve been able to use this API to successfully read the sensor. Although this seems like common sense, you should always verify that things are working as expected before you start to wrap up a sensor in ROS. If you know that the sensor is working, then anything that goes wrong will be a problem with the ROS wrapper, which will make things easier to debug.

A (Fake) Sensor

For this chapter, we’re going to use a fake sensor (called FakeSensor) with a simple API. This Python class is going to simulate a real sensor, allowing us to show you how to wrap ...

Get Programming Robots with ROS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.