But, Self-Driving Car Engineers don’t need to know C/C++, right?

Miguel Morales
7 min readJan 31, 2017

--

According to Paysa.com, over 90% of the applicants need to know C++, and over 70% need to know C. But, I feel your pain. I, too, came out of school knowing C/C++ right into a web/app development shop. I spent way too much time using other languages and only recently started brushing up my memory allocation. Did you get that?

In this post, I intent to do an in-depth review on how is C/C++ utilized when solving Self-Driving Car problems. I do this after reviewing over many Self-Driving Car job postings for a couple of weeks. I compiled all the most common technological requirements, and all the common algorithms asked for. I then looked for common tools in which they intersect. Additionally, I looked into Udacity’s Self-Driving Car Nanodegree second term syllabus for cross-reference.

What the difference between C and C++? You may ask. Even, what is the difference between C, C++ and C/C++. The answer to this question can be surprising. C is actually not the same language than C++, but because you can use C++ to write C code, the C++ language is commonly referred to as C/C++. Note, however, that many top class C developers despise C++ code. Often referring to it as bloated and the cause of bad design choices. Now, take this for what is worth, remember the Linux kernel is all written in pure C and a subset of assembly, and it is well know as a high-performance operating system. However, there are lots of applications that are written in C++ and still perform very well. I’ll be referring to C++ as C/C++ only to include both. If there is a need to make a distinction, I’ll do so.

How will you use C/C++ as a Self-Driving Car Engineer?

The C and the C++ programming languages are both well known for speed. Many of the applications that are either real-time or that use a parallel architecture are written in C/C++. For example, look at this job posting, see the need for RTOS, CUDA, Computer Vision. All of these should come to you as C/C++. Also, take a quick look at this one. See ROS? Well, I bet this will be ROS with the C/C++ programming interface. Look at this one too. See the real-time constraints? Yeah, that is C/C++ right there.

This is just a sample set, but it generalizes well. Self-Driving Car Engineers use C/C++ to squeeze as much speed out of the machine as possible. Remember, all processing in autonomous vehicles is done in real-time and even sometimes in parallel architectures, so you will have to learn to code for the CPU but also the GPU. It is vital for you to deliver software that can process large amount of images (think about the common fps — 15, 30 or even 60) every second.

Now, knowing the language is not enough. Often top C/C++ developers say that badly written C/C++ code can perform worse that a well written piece of Java. However, if you learn some good optimizations techniques you should be able to write high-quality, high-performance code. That should be your goal if you are looking to get yourself a Self-Driving Car Engineer position.

Now that I put forth some of the reasons why it is a good idea for you to learn C/C++, let’s go into more detail regarding the tools and libraries that you will most likely be coding against in this language. Make sure to check the references section for a list of the books I’ve been reading recently and that I recommend.

ROS

Robot Operating System (ROS) is not an Operating System. I know, weird. ROS is a framework composed of tools and libraries for writing robot software. The ROS framework can be easily installed on Ubuntu, and you can be up and running in no time.

One of the reasons ROS is used for developing self-driving cars is its design conventions. ROS helps you implement modular and distributed code by using a Publisher and Subscriber architecture. Additionally, ROS was created with open-source in mind, so lots of implementation of the most common algorithms use in robotics are readily available for you to use or modify. You can find Kalman Filters, Particle Filters, Lane detection pipelines, etc.

You can actually use other programming languages to leverage ROS libraries, packages and tools, but most of the production code will be written in C/C++ so make sure to review it.

The following is a ROS “Hello World” example:

#include <ros/ros.h>

int main(int argc, char** argv) {
ros::init(argc, argv, "hello_world");
ros::NodeHandle nh;
ROS_INFO_STREAM("Hello, world!");
}

I read the book “A Gentle Introduction to ROS” by Jason M. O’Kane, and I can definitely recommend.

CUDA

Most of the time code is written for the CPUs to do the computations. However, sometimes it is the GPU, a Graphical Processing Unit, that computes. Here is the thing, CPUs are really good at doing sequential work, that is, one thing at a time, even if you have multiple threads. They are just extremely fast. So fast, that to give the illusion of processing multiple things at once. However, there is this other processing unit that is optimized for parallel processing. For a very long time now, few great companies have been pleasing games appetite creating faster and sharper gaming experiences every year. Little we knew that the same processing units optimized to update many many pixels at the same time in order to create a realistic gaming experience would be later used to speed up Deep Learning algorithms. Yes, thank you gamers!

CUDA is a library that you can use to create parallel code. Again, there are other programming languages that can leverage the power of CUDA and GPUs, however, it’ll be C/C++ what will go into the live system. Make sure to learn your bit of CUDA C. Remember matrix multiplication from college? Well, that can be made into parallel code with CUDA C. Actually, lots of image pre-processing techniques as well as deep learning computations can leverage the power of GPUs.

Here is the corresponding CUDA “Hello World” example by Cyril Zeller:

__global__ void mykernel(void) {
}

int main(void) {
mykernel<<<1,1>>>();
printf("Hello World!\n");
return 0;
}

The book I can recommend if you are interested in learning more about CUDA and parallel programming is “Professional CUDA C Programming” by John Chen et al.

RTOS (Real-Time Operating Systems or just real-time programming)

There is often confusion when someone refers to an RTOS. RTOS literally means Real-time Operating System, however, often time people just mean an application that must respond to events as data comes in. The responses of these systems are often required on a time constraint, say 10 ms, 50 ms, or 100 ms. However, this often does not need to be constraint to a specific operating system. Let me put it this way, Linux is not a real-time operating system, however, it is often used for real-time applications.

This being said, there are other operating systems that are consider real-time, like QNX and VxWorks, and there are some architectural decision and coding principles that you might want to know when implementing solutions with very tight time requirements.

For brushing up your RTOS skills I would recommend 2 things. First, go get a book about the Linux kernel. I can recommend “Linux Kernel Development (3rd Edition)” by Robert Love. This will help you understand operating systems in general. The process management and scheduling, timers, memory management and so on, are very important to the speed of real-time applications. Then, go and get a book on Real-Time Systems. I can recommend “Real-Time Systems Design and Analysis: Tools for the Practitioner 4th Edition” by Phillip A. Laplante et al. This book will show you not only the foundations, architecture and details of RTOS, but it also goes into programming best practices, requirements engineering and other software development processes as it related to RTOS.

OpenCV

I’ve used lot of OpenCV but I often use Python instead of C/C++. It is important for you to know that OpenCV also has C/C++ bindings. So, a very likely workflow as a self-driving car engineer will be to prototype a pipeline for image pre-processing using Python and OpenCV, polish it, and then translate it into C/C++ code. Make sure to at least use the OpenCV C/C++ bindings a couple of time before you go into an interview.

Deep Learning

I know, Deep Learning is not a “library”. But I just wanted to mention this here because there most of the deep learning libraries out there are coded with C/C++ and only have APIs available for you to call in some of the other languages like Python, for example. It might be the case, that you will be asked to prototype your deep learning pipelines in something like Keras, but then move it to either TensorFlow C++ or even CUDA C, though this last one might be a stretch. So, learn to use TensorFlow C++ API before you apply!

The Self-Driving Car train is just around the corner (Did you get it?), do not waste this opportunity to become the greatest you. Work really hard every day to become the best C/C++ software engineer you can, and you will be one step closer to becoming a Self-Driving Car Engineer.

If you like this posts, subscribe. I’m planning to add a couple more posts regarding other programming languages and tools. Most of my post will be related to Self-Driving Cars, Deep Learning and Reinforcement Learning. Also, leave a comment if you have any questions or suggestions. And good luck to you!

References

  • A Gentle Introduction to ROS by Jason M. O’Kane
  • Professional CUDA C Programming by John Chen et al.
  • Linux Kernel Development (3rd Edition) by Robert Love.
  • Real-Time Systems Design and Analysis: Tools for the Practitioner 4th Edition by Phillip A. Laplante et al.

--

--