Effective use of multi spinner threads, different queues in ROS

Robot Operating System (ROS)¹ is a popular framework for developing robotics application. One of the main facilities that ROS provides is the publisher-subscriber communication² that is used for message-passing between components. While it is easy to implement the publisher-subscriber, it is not obvious what is going on underneath it and how we can tailor it to our specific problems in practice. In this post, I will talk about the mechanisms behind the publisher-subscriber in ROS such as its execution model, threading, queuing mechanism. To keep the discussion in practical level, I will use simple reference programs that were derived from…


Memory orderings for multi thread programming in C++

Photo by Andrew Ridley on Unsplash

Introduction

As many know, since C++11, std::atomic<T> was introduced as a part of the standard library. Probably the most obvious part of the functionality is that each instantiated type of std::atomic<T> can be atomically operated on from different threads without causing any data race. But also, there is another aspect of std::atomic<T>that is important to know in order to avoid having tricky bugs, or to improve performance of your programs. The aspect is related to memory model¹ ,especially memory ordering².

There are six memory orderings that are specified in the C++ standard: memory_order_relaxed, memory_order_consume, memory_order_acquire, memory_order_release, memory_order_acq_rel and memory_order_seq_cst³. …


add_subdirectory vs include, function vs macro in CMake

Introduction

As you may already know, CMake is a popular open source tool that manages the build process of software.

With CMake, you can define variables along with a set of directives and instructions to describe your project processes (building, testing, packaging etc). You can consider the variables in CMake like variables in other programming languages. Now, you must be thinking that variable is a basic concept in programming and there is no complication around it. However, the concept of the “scope” of CMake variables could be tricky to understand, and potentially it could slow down your daily development if you…


Introduction of the popular meta-programming pattern

Introduction

Templates are a useful feature with which we can define a generic function or a generic class that can be used with different types. Among all other cool things you can do with Templates, there is a popular templates technique called “detection idiom”.

Detection idiom is a kind of pattern with Templates that can detect if certain expressions are valid or ill-formed for given types in compile time. People often use it to selectively choose between different implementations of template function. …


Effective preprocessor meta programming tips

C/C++ preprocessor¹ is a tool that is used to process source codes before the compilation process. The preprocessors process certain directives that begin with hash(#) symbol in source codes. There are several preprocessor directives. The most famous one might be #include directive that is used to include a specific file.

#include <iostream> // Includes standard library iostream header

Also, there are#if, #ifdef, #ifndef, #elif, #endifdirectives which can be used for conditional compilation² as other examples of preprocessor directives. In this post, I decided to talk about #definedirective and its usage because among all of the…


Introduction of “type identity” trick and introduction of std::common_type

Templates are a useful feature with which we can define a generic function or a generic class that can be used with different types. To use the templates function, we need to specify the concrete types as the templates arguments on each call to the function. In practice, explicitly specifying all types for template functions can quickly become tedious, so instead of specifying them explicitly, we often let compiler to automatically determine the intended types. This is called templates argument deduction.

The basic argument deduction process compares the type of the passed argument with the corresponding templates parameter T and…


Things to know about endianness in programming

Photo by Markus Spiske on Unsplash

Endianness

The terms endian and endianness refer to the convention that decides the ordering of bytes when processor stores a word data from its register to memory or the other way around, loads a word data from memory to its register. Word data is nothing but a conventional unit of data (bunch of bits) that is associated to a specific processor architecture. The association is a bit fuzzy because some processors use a different unit of data for the different aspects of the design (instruction set size, bus size between processor and memory, register…


Introduction of X-in-the-loop test method

Photo by Harrison Broadbent on Unsplash

Even though the topic “self-driving car” has become trendy recently, the technology itself had been known for a long time already, more than decades. In fact, there are many companies and academic institutions that successfully demonstrated running self-driving car. However, as of today, we don’t see self-driving cars operating in public roads¹. This is because there is a big difference in difficulties between building just a prototype car that only operates in controlled environment and producing hundreds of thousands cars that are used in different environment by drivers with wide range of driving experiences. Car…


A short introduction of Conan package manager concepts and workflow

https://commons.wikimedia.org/wiki/File:Conan_package_manager_logo.png

When you are developing a library or an executable program, sometimes you are going to use external libraries for your software instead of writing them on your own in order to avoid reinventing the wheels.

Even though this happens no matter which tool you are using to manage the build process, since CMake¹ has become the de facto tool for C/C++ packages, I focus on the topic with CMake.

Classic approaches for resolving dependencies to the external libraries while using CMake is copying the source codes of the external libraries into the subdirectories, then use add_subdirectory() in your CMakeLists.txt …


Explanation of advanced C++ templates concept “SFINAE”

As you know, C++ includes a powerful feature called Templates¹. Using Templates, you can write functions and classes that can be reused for different types. Things are easy until you come to situations where you need to use different implementations of a template function for specific types or specific constraints.

Let’s say we defined a trivial utility function template called Print like below,

#include <iostream>
#include <string>
#include <chrono>
#include <ctime>
template<class T>
void Print(const T& arg) {
auto time_point = std::chrono::system_clock::now();
std::time_t ttp = std::chrono::system_clock::to_time_t(time_point);
std::cout << "["<< std::ctime(&ttp) <<"] " << arg << std::endl;
}

Print function takes…

Kohei Otsuka

Software architect in automotive industry. Interested in technology, Science. www.linkedin.com/in/kohei-otsuka-4362bbb5

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store