No version for distro humble. Known supported distros are highlighted in the buttons above.
No version for distro jazzy. Known supported distros are highlighted in the buttons above.
No version for distro kilted. Known supported distros are highlighted in the buttons above.
No version for distro rolling. Known supported distros are highlighted in the buttons above.
![]() |
example_waypoint_flier package from ros2_examples repoexample_plugin_manager example_plugins vision_examples vision_examples_utils example_waypoint_flier example_waypoint_flier_simple ros2_examples ros2_lib sub_pub_torture_test |
Package Summary
Tags | No category tags. |
Version | 1.0.0 |
License | MIT |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Examples for individual ROS2 functionalities inc. Subscribers, Publishers, Timers, Services, Parameters. ... |
Checkout URI | https://github.com/ctu-mrs/ros2_examples.git |
VCS Type | git |
VCS Version | master |
Last Updated | 2025-05-23 |
Dev Status | UNKNOWN |
CI status | No Continuous Integration |
Released | UNRELEASED |
Tags | cpp examples robot-operating-system ros2 |
Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Package Description
The Example Waypoint Flier
Additional Links
No additional links.
Maintainers
- Matej Petrlik
Authors
- Matej Petrlik
WaypointFlier ROS example
This package was created as an example of how to write ROS nodelets. The package is written in C++ and features custom MRS libraries and msgs.
Functionality
- Desired waypoints are loaded as a matrix from config file
- Service
fly_to_first_waypoint
prepares the UAV by flying to the first waypoint - Service
start_waypoint_following
causes the UAV to start tracking the waypoints - Service
stop_waypoint_following
stops adding new waypoints. Flight to the current waypoint is not interrupted.
How to start
./tmux/start.sh
Then, call the services prepared in the terminal window either by:
- Pressing tmux binding (
Ctrl + b
orCtrl + a
) - Pressing the down arrow to change to the terminal below
- Pressing the up arrow to bring up the prepared terminal command
Or typing the following command into a terminal connected to the ROS server:
ros2 service call /uav1/waypoint_flier/start_waypoints_following std_srvs/srv/Trigger
Package structure
See ROS2 packages
-
src
directory contains all source files -
launch
directory contains.py
launch files which are used to parametrize the node. Command-line arguments, as well as environment variables, can be loaded from the launch files, the node can be put into the correct namespace (each UAV has its namespace to allow multi-robot applications), config files are loaded, and parameters passed to the node. See launch files -
config
directory contains parameters in.yaml
files. See .yaml files -
package.xml
defines properties of the package, such as package name and dependencies. See package.xml - CMakeLists.txt contains instructions for building the package using the colcon build tool
Example features
Some of the following features are wrapped in mrs_lib
interface to provide added functionalities, improved performance, and ease of use. Therefore, their interface can differ from the original ROS2 features.
- Node initialization
- Subscriber, publisher, and timer initialization
- Service servers and clients initialization
- Loading parameters with
mrs_lib::ParamLoader
class - Loading Eigen matrices with
mrs_lib::ParamLoader
class - Checking node initialization status in every callback
- Checking whether subscribed messages are coming
- Throttling text output to a terminal
-
Thread-safe access to variables using
std::scoped_lock
- Using
ConstPtr
when subscribing to a topic to avoid copying large messages - Storing and accessing matrices in
Eigen
classes - Remapping topics in the launch file
Coding style
For easy orientation in the code, we have agreed to follow the ROS C++ Style Guide when writing our packages. Also check out our general C++ good/bad coding practices tutorial.
Naming variables
- Member variables are distinguished from local variables by underscore at the end:
-
position_x
- local variable -
position_x_
- member variable
-
- Also, we distinguish parameters which are loaded as parameters by underscore at the beginning
- Descriptive variable names are used. The purpose of the variable should be obvious from the name.
-
sub_odom_uav_
- member subscriber to uav odometry msg type -
pub_reference_
- member publisher of reference msg type -
srv_server_start_waypoints_following_
- member service server for starting following of waypoints -
ExampleWaypointFlier::callbackTimerCheckSubscribers()
- callback of timer which checks subscribers -
mutex_odom_uav_
- mutex locking access to variable containing odometry of the UAV
-
Good practices
- Do not use raw pointers! Smart pointers from
<memory>
free resources automatically, thus preventing memory leaks. - Lock access to member variables! Nodelets are multi-thread processes, so it is our responsibility to make our code thread-safe.
- Use
c++17
scoped_lock
which unlocks the mutex after leaving the scope. This way, you can’t forget to unlock the mutex.
- Use
{
std::scoped_lock lock(mutex_odom_uav_);
odom_uav_ = *msg;
}
- Use
mrs_lib::ParamLoader
class to load parameters from launch files and config files. This class checks whether the parameter was actually loaded, which can save a lot of debugging. Furthermore, loading matrices into config files becomes much simpler. - For printing debug info to terminal use
RCLCPP_INFO()
,RCLCPP_WARN()
,RCLCPP_ERROR()
macros. Do not spam the terminal by printing a variable every time a callback is called, use for exampleRCLCPP_INFO_THROTTLE(node_->get_logger(), *clock_, 1.0, "dog")
to print dog not more often than every second. Other animals can also be used for debugging purposes. - If you need to execute a piece of code periodically, do not use sleep in a loop, or anything similar. The ROS API provides
rclcpp::TimerBase
class for this purposes, which executes a callback every time the timer expires. - Always check whether all subscribed messages are coming. If not, print a warning. Then you know the problem is not in your nodelet and you know to look for the problem in topic remapping or the node publishing it.
CHANGELOG
No CHANGELOG found.
Wiki Tutorials
This package does not provide any links to tutorials in it's rosindex metadata.
You can check on the ROS Wiki Tutorials page for the package.
Package Dependencies
Deps | Name |
---|---|
ament_cmake | |
ament_cmake_ros | |
rclcpp | |
rclcpp_components | |
rclcpp_lifecycle | |
launch | |
launch_ros | |
geometry_msgs | |
nav_msgs | |
mrs_msgs | |
mrs_lib |
System Dependencies
No direct system dependencies.
Dependant Packages
No known dependants.
Launch files
No launch files found
Messages
No message files found.
Services
No service files found
Plugins
No plugins found.
Recent questions tagged example_waypoint_flier at Robotics Stack Exchange
No version for distro noetic. Known supported distros are highlighted in the buttons above.
No version for distro galactic. Known supported distros are highlighted in the buttons above.
No version for distro iron. Known supported distros are highlighted in the buttons above.
No version for distro melodic. Known supported distros are highlighted in the buttons above.