MCPcopy Create free account
hub / github.com/arjunskumar/Robotics_CPP_Notes

github.com/arjunskumar/Robotics_CPP_Notes @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
17 symbols 35 edges 3 files 6 documented · 35% updated 26d ago★ 342

Browse by type

Functions 13 Types & classes 4
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Modern Robotics C++ Notes (C++17 / C++20 / C++23)

C++ Intro

Welcome to our Modern C++ Course, specifically tailored for Engineers focusing on Robotics.

Table of Contents

  1. Module 01: Foundations & Compilation
  2. Module 02: Variables, Types & Constants
  3. Module 03: I/O & Arithmetic
  4. Module 04: Control Flow
  5. Module 05: Loops & Iteration
  6. Module 06: Structs & Enums
  7. Module 07: Memory & Ownership
  8. Module 08: Functions & Lambdas
  9. Module 09: Project Structure & CMake
  10. Module 10: Classes & Encapsulation
  11. Module 11: Templates & Polymorphism
  12. Module 12: Concurrency
  13. Module 13: Production Deployment & Tooling
  14. Module 14: Advanced Utilities (variant, any, tuple)
  15. Module 15: Performance & Profiling Checklist
  16. Module 16: Capstone — Multi-Threaded Sensor Pipeline
  17. Appendix A: Real Robotics Failure Case Studies
  18. Appendix B: Production Design Patterns
  19. Appendix C: Testing Discipline
  20. Appendix D: ROS 2 Senior Insights

Module 01 — What is C++? Compilation & Your First Program

Phase: Foundations

C++ is a high-performance, compiled language created by Bjarne Stroustrup. In robotics, it is the industry standard for real-time systems, providing "zero-cost abstractions" that allow for high-level code with maximum hardware efficiency.

[!NOTE] Design Philosophy: This module is designed to demystify the "black box" of how code reaches hardware. Robotics involves diverse hardware (ARM/x86); if you don't understand the Linker vs. Compiler, you will be paralyzed by the first library error you hit in ROS.

[!NOTE] Modern C++ (C++17): This course focuses specifically on the C++17 Standard, which introduced critical robotics features like std::optional, std::string_view, and structured bindings.

In the world of Robotics, C++ is the undisputed king. It provides zero-cost abstractions—high-level features that compile into highly efficient machine code. When processing point clouds from a LIDAR at 10Hz or calculating inverse kinematics for a robot arm in under a millisecond, performance is critical.

Who Uses This In The Real World?

  • Tesla Autopilot — Real-time sensor fusion and vehicle control systems.
  • Open Robotics (ROS) — ROS 2 core is written in C++ for real-time distributed systems.
  • Boston Dynamics — Control software for Atlas and Spot.
  • NVIDIA Isaac — Accelerated robotics simulation and AI pipelines.

How C++ Code Becomes a Robot Action (Compilation Pipeline)

Before we write code, it's crucial to understand how your text becomes a robot action.

Stage Action Intermediate Flag
1. Preprocessor Resolves #include and #define (textual copy-paste). g++ -E robot.cpp -o robot.i
2. Compiler Translates C++ to Assembly (CPU-specific logic). g++ -S robot.cpp -o robot.s
3. Assembler Converts Assembly to Binary Machine Code (Object Files). g++ -c robot.cpp -o robot.o
4. Linker Combines .o files and libraries into a final executable. g++ -o robot_init robot.o

Header Inclusion & #pragma once

In robotics frameworks like ROS 2, modular software is broken into header files (.hpp / .h) and source files (.cpp). During compilation, the preprocessor textually pastes the content of every #include directive into the translation unit.

If multiple files include the same header (e.g., IMUSensor.hpp included by both Controller.cpp and Telemetry.cpp), the compiler might attempt to declare the same class or struct multiple times, resulting in redefinition errors.

Traditional Include Guards vs #pragma once

Feature Traditional Include Guards Modern #pragma once
Syntax #ifndef HEADER_H / #define HEADER_H / #endif #pragma once (single top line)
Mechanism Preprocessor macro tracking Compiler filesystem tracking
Standardization ISO C++ Standard Non-standard, but supported by ALL modern compilers (GCC, Clang, MSVC)
Error Risk Macro naming collisions across large projects Zero naming collision risk
Build Speed Slower (preprocessor parses file to #endif) Faster (compiler skips opening file entirely)

Legacy Guards Example:

#ifndef ROBOTICS_SENSORS_IMU_HPP
#define ROBOTICS_SENSORS_IMU_HPP

struct IMUData {
    double ax, ay, az;
    double gx, gy, gz;
};

#endif // ROBOTICS_SENSORS_IMU_HPP

Modern Best Practice:

#pragma once

struct IMUData {
    double ax, ay, az;
    double gx, gy, gz;
};

[!TIP] Industry Rule in ROS 2: Always put #pragma once at the very first line of every header file to prevent multi-inclusion build failures and accelerate CMake compile times.

Deep Dive: The One Definition Rule (ODR)

The One Definition Rule (ODR) is a foundational C++ rule that dictates how entity definitions exist across translation units (TUs) during compilation and linking.

The Three Canonical Rules of ODR

  1. Within a Single Translation Unit: An entity (variable, function, class/struct, enum) can have at most one definition.
  2. Across the Entire Program (Non-Inline Entities): Global variables and non-inline functions must have exactly one definition across all object files (.o). Violating this produces a Linker Error (multiple definition of ... or duplicate symbol).
  3. Across Translation Units (Inline & Types): Class types, structs, enums, inline functions/variables, and template definitions can appear in multiple translation units—provided every definition is token-for-token identical.

ODR Violation & Linker Crash Matrix

Code Placement Multiple Includes Behavior Linker Result Correct Fix
Non-inline function definition in header Function compiled into multiple .o files multiple definition of 'read_sensor()' Mark function inline or move definition to .cpp
Global variable definition in header Symbol defined in multiple object files multiple definition of 'robot_id' Declare as extern int robot_id; in header, define in ONE .cpp
Class / Struct definition in header Included across multiple .cpp files ✅ OK (guarded by #pragma once) Ensure #pragma once is present
inline function / template in header Included across multiple .cpp files ✅ OK (ODR exempt by standard) Header-only implementation allowed

Real-World Robotics ODR Pitfall (Linker Error):

// ❌ BAD: LidarUtils.hpp (Header file)
#pragma once

// Linker error if included by more than one .cpp file!
int global_lidar_count = 0; 

void reset_lidar() { 
    global_lidar_count = 0; 
}

Correct Modern C++ Fix:

// ✅ GOOD: LidarUtils.hpp
#pragma once

// inline variables (C++17) and inline functions allow safe multi-TU inclusion!
inline int global_lidar_count = 0; 

inline void reset_lidar() {
    global_lidar_count = 0;
}

Your First Robot Program

Let's write a simple program that outputs the status of a robot.

Code Example

#include <iostream>

int main() {
    std::cout << "[Robot System] Initializing sensors... OK\n";
    std::cout << "[Robot System] Ready for C++17 Robotics!\n";
    return 0;
}

Anatomy of the Program (Key Term

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 11
Class 3
Function 2
Enum 1

Languages

C++100%

Modules by API surface

capstone/sensor_pipeline.hpp15 symbols
capstone/test_pipeline.cpp1 symbols
capstone/main.cpp1 symbols

For agents

$ claude mcp add Robotics_CPP_Notes \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page