# ModernRoboticsCpp: a robotics library written to be read

> There is a category of code that is not meant to be used but to be understood: the reference implementation that accompanies a textbook, where every function is written to look like the equation in the book. ModernRoboticsCpp is that for a well known robotics text, and the readme says its purpose in a sentence that is unusual in software: the code is optimized neither for efficiency nor robustness.

**Le0nX/ModernRoboticsCpp** — Modern Robotics: Mechanics, Planning, and Control C++ Library --- The primary purpose of the provided software is to be easy to read and educational, reinforcing the concepts in the book. The code is optimized neither for efficiency nor robustness. http://modernrobotics.org/

- Repository: https://github.com/Le0nX/ModernRoboticsCpp
- Stars: 548 · Forks: 164
- Language: C++
- License: not declared
- Published: 2026-10-22 · Updated: 2026-10-22 · Language: en
- Canonical page: https://hysenlabs.com/projects/le0nx-modernroboticscpp

## What it is, and the sentence that defines it

This repository contains the code library accompanying a robotics textbook on mechanics, planning and control, written by two authors and published by a university press in 2017. The library site is linked from the readme, and so is the user manual, which lives in the documentation directory of the upstream repository rather than here.

So the arrangement is worth understanding before reading any of the code. The book is the primary artefact. The code is a companion to it, and the upstream project also publishes the same functions in Python, in MATLAB and in Mathematica, as separate packages.

The primary purpose of the provided software is stated plainly: it is meant to be easy to read and educational, reinforcing the concepts in the book. And then the sentence that makes the whole design legible: the code is optimized neither for efficiency nor robustness.

That is an unusual thing to write in a readme, and it is doing the work of a specification. A robotics library that is neither fast nor defensive is a library whose job is to be read by a person who wants to understand what a homogeneous transform is, or how a screw axis becomes a product of exponentials, or why a control law has the form it does. Every design decision that follows from that sentence is a decision about legibility.

Which is not to say the code is careless. It is a matrix library underneath, so the numerical primitives are somebody else's problem, and the parts that are this library's own are the parts that carry the book's ideas. The optimisation claim is about the library's own layer.

And that also tells you the right way to use it. This is code to read with a book in one hand and an editor in the other, and to copy from when you are building something and want the structure of a solution rather than its performance. The licence is not one of the standard ones that the hosting site could classify, which is a small oddity for a project of this kind and worth checking in the licence file if you intend to depend on it.

## How the code is documented, and what is left out

The documentation model is stated in one sentence, and it is the detail that makes the library usable on its own rather than only alongside the book.

Each function has a commented section above it explaining the inputs required for its use, as well as an example of how it can be used and what the output will be.

Three things in that sentence, and each of them solves a different problem.

The inputs first, because the natural language of a robotics book is a diagram and a derivation, and a function signature does not tell you what a four by four matrix is supposed to contain. A reader who has read the chapter knows; a reader who has found the function in a search result does not.

Then an example, which is what makes a function teachable. An example call with real numbers and a stated result lets you check your own understanding against the library's, and it lets you adapt the call without working out the argument order from the signature.

And then the output, stated rather than left implicit, which is the part most libraries omit. In a robotics function the output is a matrix whose layout conventions are the whole difficulty, and a comment that says which convention is in use saves the reader a trip back to the book.

The other half of the documentation model is what is deliberately absent. The basic functions, such as calculating the magnitude of a vector, normalizing a vector, testing whether a value is near zero, and performing matrix operations such as multiplication and inverses, are not documented here.

That exclusion is a design decision, and a good one. Those operations are what the matrix library is for, and documenting them again would mean maintaining a second copy of the documentation for somebody else's API. The library's surface is therefore exactly the robotics content, and the numerical substrate is assumed.

And the organisation follows the book. The functions are grouped by the chapter in which they are introduced, so the source tree is a table of contents and a reader who has read chapter four knows which directory to open. A pdf overview of the available functions is also included, written in the syntax of the matrix language, which makes it usable as a lookup table whichever language you are programming in.

## One library, four languages

The readme lists the languages the functions are available in, and the list is the C++ one plus three packages hosted in the upstream repository: Python, MATLAB and Mathematica.

That is a deliberate choice about how a textbook's code is delivered, and it is worth thinking about which of the four is the reference.

The matrix language one is the natural home for a robotics reference implementation. A robotics function is a matrix operation, the matrix language is a matrix language, and the notation in the book maps almost one to one onto the syntax. A transformation is written the way it is in the book, and the reader can compare the two side by side.

The Python package is the one most readers will actually run, because Python is how most people try a robotics idea, and because a Python implementation of a book is the one you can paste into a notebook and step through.

The Mathematica package completes the set for a different reason: it is the language where symbolic manipulation is easiest, and a large part of a robotics course is symbolic manipulation of the equations the book derives.

And the C++ library, the one this repository holds, is the odd one out in that order. It is the version for a course that teaches C++, or for a project that has to run somewhere without a scripting environment, and it is the version whose readability matters most, because a C++ reader looking for the implementation of a chapter is usually reading code rather than running it.

The choice of the matrix library underneath is the other thing the four-language arrangement implies. The dependency is a header-only matrix library with a licence compatible with commercial use, which is what you would expect from a reference implementation that a university course and a research lab both build on. The consequence is that the C++ code is short, because the matrix work is a one-line expression, and that the code you read in this repository is almost entirely the robotics logic and almost none of the numerics.

That is a good property for a teaching library, and it is the direct consequence of the decision to not reimplement the basics.

## Building it, and the two commands that differ by platform

The installation instructions are short, and the first step is the dependency.

On a Mac it is a single package manager command, and on Linux it is the distribution's development package for the matrix library.

```console
foo@bar:~$ brew install eigen
```

```console
foo@bar:~$ sudo apt-get install libeigen3-dev
```

The second step is to make a build directory and go into it, which is the standard out-of-source build arrangement, and it is worth noting that the directory name in the example is deliberately generic.

```console
foo@bar:~$ mkdir build && cd build
```

Then the configure step, and here the readme does something considerate: it shows how to install into a custom directory as well as how to accept the defaults.

```console
foo@bar:build $ cmake .. -DCMAKE_INSTALL_PREFIX=../_install
```

```console
foo@bar:build $ cmake ..
```

The note above those two lines explains what the default is: the build installs into the system directories, and the flag overrides that. That ordering, showing the special case first and the default second, is a small piece of documentation craft, because the reader who is following along quickly will get the right thing either way and the reader who cares about not polluting their system will find the flag immediately.

The build and install are then a single pair of commands, which is the conventional make arrangement and the one most people will recognise.

```console
foo@bar:build $ make all && make install
```

And the directory name in the install prefix example is worth a second look, because it starts with an low dash. That is the convention for a directory you do not want a search tool to walk into, and in a repository where the prefix points at a sibling of the build directory, it is a directory full of generated headers and libraries. Using the convention means a recursive search for a header in the parent tree skips it.

The whole build is thus: install a header-only dependency, configure with the build system, make, install. For a library with a matrix dependency and no compiled extension of its own, that is about as short as a build can be.

## Testing, and what the repository contains

There is one command for the tests, run from the build directory.

```console
foo@bar:build $ ./lib_test
```

The name of the binary is the interesting part. It is not a test file with a framework's naming convention; it is a program you run. That is consistent with a library whose purpose is to be read and run, and it is also how a course would use it: a student compiles the library, runs the test program, and sees the functions produce the numbers the book says they should.

The repository supports that with two build files at the root, and the second one has the test framework's name in it, which is the convention for a separate configuration that pulls in an external dependency. Having a second configuration rather than a flag means the test dependency is not required for an ordinary build, which matters for a library that somebody might build on a machine with no network access to the test framework's sources.

The source itself is split into a public headers directory and a source directory, which is the conventional layout for a library whose headers are meant to be included by others. For a header-only style project the source directory holds the implementation units and the headers directory holds the interface, and the distinction is what tells a build system what to install.

There is a git ignore file and nothing else in the root, which tells you the project is small enough that the readme, the two build files and the source are the whole of it. No continuous integration badge appears in the readme, no contribution guide, no change log. For a companion to a book that was published in 2017 and whose upstream repository carries the documentation and the other language packages, that is a reasonable shape: the reference code is stable, the interesting development happens upstream, and this repository is where the C++ port lives.

What a reader should take from all of this is the sentence in the readme. This library is for understanding and for teaching, and it says so before it says anything else. If you are building a robot, use it as a reference for the shape of a solution and not as a dependency, because the readme has told you plainly that the performance and the defensive behaviour are not there.

## Conclusion

ModernRoboticsCpp fits a student or an engineer who wants to see a rigid body transform, a product of exponentials, a trajectory generator or a feedback law written the way the textbook writes it. It does not fit a production robotics system, and the readme says so. Verify first which functions the library actually covers, because the basic linear algebra is deliberately left to the matrix library rather than reimplemented, and that the version of the textbook you are reading matches the chapter the functions are filed under, since the organisation of the source follows the organisation of the book.

## FAQ

### What is the ModernRoboticsCpp library?

It is the C++ code library accompanying the Modern Robotics textbook on mechanics, planning and control. The same functions are published in Python, in MATLAB and in Mathematica in the upstream repository, and this one exists for courses and projects that teach or use C++.

### Why is the ModernRoboticsCpp code not optimised for speed or robustness?

Because its stated purpose is to be easy to read and educational, reinforcing the concepts in the book. The readme says the code is optimised neither for efficiency nor robustness, which tells a reader to treat it as reference code to study and adapt rather than as a production dependency.

### How is each function in ModernRoboticsCpp documented?

With a commented section above it giving the inputs the function needs, an example of how to call it, and what the output will be. The functions are also grouped by the chapter of the book that introduces them, and a pdf overview of the whole catalogue is included in the matrix language's syntax.

### Which functions does ModernRoboticsCpp deliberately not provide?

The basic numerical ones: the magnitude of a vector, normalising a vector, testing whether a value is near zero, and matrix multiplication and inverses. Those are left to the underlying matrix library, so the library's own surface is exactly the robotics content rather than a second copy of somebody else's numerical API.

### How do I build and test the ModernRoboticsCpp library?

Install the header-only matrix library with the platform's package manager, make a build directory and enter it, configure with the build system, optionally passing an install prefix to avoid the system directories, then run the make targets for the library and the install. The tests are a single program you run from the build directory, and a second build configuration keeps the test framework out of an ordinary build.

## Sources

- [Issues](https://github.com/Le0nX/ModernRoboticsCpp/issues)
- [Le0nX/ModernRoboticsCpp on GitHub](https://github.com/Le0nX/ModernRoboticsCpp)
- [README](https://github.com/Le0nX/ModernRoboticsCpp/blob/master/README.md)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/le0nx-modernroboticscpp
