O'Reilly logo

Programming Robots with ROS by William D. Smart, Brian Gerkey, Morgan Quigley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 23. Using C++ in ROS

We chose to use Python for this book for a number of reasons. First, it’s an accessible language for people without a lot of computer science background. Second, it has a lot of useful stuff in the core packages, which lets us concentrate on higher-level concepts. Third, ROS has strong support for Python. Fourth, we wanted to pick a single language for all of the examples in the book, and Python seemed like a reasonable choice.

However, sometimes you’re going to want to use another language for your ROS development. Maybe some library that you need to use doesn’t have Python support. Maybe you’re more comfortable developing in another language. Maybe you want the (often slight) speed advantage that a compiled language brings. In this chapter, we’re going to look at how the API in C++, one of the other supported languages, differs from the Python API, and how you can translate the examples in this book to C++. All of the idioms and design patterns for C++, and any other language that has a ROS API, will be the same: we’re still going to use callbacks, we’re still going to pass messages over topics, and so on. However, the syntax and specific data structures will be a little different. Once you learn how to map the Python examples onto your language of choice, then you’ll be able to easily translate examples from one language to another.

The two best-supported language APIs in ROS are for Python and C++. In this chapter, we’ll concentrate on the C++ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required