MicroROS code - VTAstrobotics/Documentation GitHub Wiki
Remember that everyone owns this documentation and if you find any errors or out of date information you should fix it.
Contents
Prerequisites
To understand the content on this page, you should know how to
- use ROS2 at a high level, Nodes, Topics, and messages.
- basic understanding of C++
Introduction
In MicroROS code, particularly for the Raspberry Pi pico, we need to provide some code before we do anything else. MicroROS is designed to work on any microcontroller, consequently, it has no idea how to send serial messages or get the current time.
We can see in the diagram that we need serial communications (with timestamps) to have any level of communication.
#Actual Code
NOTE: eventually Pico code will have a dedicated template in our repo to clone but that hasn't been setup yet
int clock_gettime(clockid_t unused, struct timespec *tp)
{
uint64_t m = time_us_64();
tp->tv_sec = m / 1000000;
tp->tv_nsec = (m % 1000000) * 1000;
return 0;
}
this code lets microROS call the clock_gettime function so that it can use the Picos provided clock functions in the way that it would expect. all of the math involved is just converting to the needed units.
you'll also need code to tell MicroROS how to use the serial communication interface
that code is longer and so I am linking to it until the template is made.
Header
file.cpp