Robot Operating System (ROS)
The Robot Operating System (ROS) is a set of software libraries and tools that help you build robot applications. It’s a Middleware.
ROS facilitates the communication between between applications, so you don’t need to implement your own ZeroMQ.
I fully use ROS2 now, NOT ROS1.
Links
- Base Repo: https://github.com/dottantgal/ROS2_learning
- Great tutorial you how to get set up on ROS2 Foxy + Fundamentals: https://articulatedrobotics.xyz/ready-for-ros-1-what-you-need/
- Robotics backend series: https://roboticsbackend.com/category/ros2/
- Really great F1TENTH series teaching ROS (though this is ROS1): https://www.youtube.com/watch?v=HMmEURShfM4&ab_channel=MadhurBehl
- ros2_cookbook
- ROS From Scratch: https://medium.com/@nullbyte.in/ros2-from-the-ground-up-part-1-an-introduction-to-the-robot-operating-system-4c2065c5e032
- Queues in ROS https://levelup.gitconnected.com/ros-spinning-threading-queuing-aac9c0a793f
These 3 are really fundamental:
- ROS2 from the Ground Up: Part 4- Building Robust Robotics Systems with ROS2 Composition
- ROS2 from the Ground Up: Part 5- Concurrency, Executors and Callback Groups
- ROS2 from the Ground Up: Part 6- DDS in ROS2 for Reliable Robotics Communication
If you want to really get good at ROS2, understand the design philosophies: https://design.ros2.org/. See ROS Design.
can you run ROS on Mac?
For a very long time, I was super afraid because it was super annoying, but then I found this: https://robostack.github.io/GettingStarted.html. I use
NASA is a user of ROS. That is insanely cool.
You should be able to look at this diagram and understand exactly what is going on. This is because you’ve met Brian who worked at Open Robotics before and seeing his breadth of knowledge on ROS is very inspirational.
Master the concepts https://docs.ros.org/en/humble/Concepts.html.
Misc
Why do people hate ROS?
People hate the performance overhead of ROS. But is there really a better solution.
Concepts
- ROS Executor
- ROS Composition
- ROS Discovery
- ROS Interface
- ROS Callback Group
- ROS2 Action
- ROS Security
- ROS Domain ID
- ROS Memory Allocator
- ROS2 Navigation Stack
- Isaac ROS (Accelerated Computing ROS, I worked on this at NVIDIA)
- Middleware
- ROS Namespace
- Rosbag
- Quality of Service (QoS)
- DDS
- ConnextDDS
- rosidl
- Common ROS Issues
- Rosbridge
- Rviz
- Foxglove
- ROS on Mac
ROS2 Networking
ROS2 comes with networking communication out of the box, meaning if both instances are on the same network, ROS2 nodes came send messages wirelessly to each other. To test that networking works:
On 1st computer, run
On 2nd computer, run
If it doesn't work
You might need to install the demo_nodes package, run
sudo apt-get install ros-<insert-distro>-demo-nodes-cpp
Passing arguments
For a launch file
Use params_file:=
, ex:
For a ros2 node
Use the --ros-args
, and then -p
for every new flag, credits this Articulated Robotics for the info. For every new argument, you need the -p
flag.
Create a new ROS2 Node
You could use the command ros2 pkg create --build-type ament_python --node-name <node_name> <package_name>
, but we don’t like this because there are annoying ignores that you need to remove. Also, doesn’t include like launch file options, which is super annoying.
So usually, you can just copy paste a node that you already have. Then, you need to change (both NODE and PACKAGE name):
CMakeLists.txt
package
My points of references:
- Create3_lidar
- F1TENTH code
Building Packages
Use --packages-up-to
instead of --packages-select
to install all the dependencies that are defined in package.xml
colcon build --packages-up-to PACKAGE_NAME
Also always use --symlink-install
so you don’t have to rebuild every time, so
colcon build --symlink-install --packages-up-to PACKAGE_NAME
ROS2 Package with both Python and CPP nodes
I was getting stuck on launching nodes, since the files have both Python and CPP, see these tutorials which are super helpful:
- https://roboticsbackend.com/create-a-ros2-python-package/#setuppy
- https://roboticsbackend.com/create-a-ros2-cpp-package/
- https://roboticsbackend.com/ros2-package-for-both-python-and-cpp-nodes/
ahh i finally understand ros2 parameters now, in code
The above doesn’t set the parameter, so if you do ros2 param get <node_name> odom_topic
, it will tell you that the parameter has not been set. However, the odom topic has still been set.
Basic Concepts
- Node: A program that uses ROS2
- Message: A message containing data being sent by one node to another
- each message has a type, which determines what kind of data it contains
- Topic: Topics act as a bus for nodes to exchange messages. Messages are sent to topics, and nodes can listen to the topics they are interested in to receive messages sent to that topic.
- nodes communicate over topics
- Nodes can publish or subscribe to a topic
- Typically, 1 publisher and n-subscribers
- Topic is a name for a stream of messages
- nodes communicate over topics
- Publisher: Nodes can publish messages to a topic
- Subscriber: Nodes receive a message from a topic by subscribing to it
- Service: Services are another method of communication for nodes in the ROS graph. Services are based on a call-and-response model, versus topics’ publisher-subscriber model. While topics allow nodes to subscribe to data streams and get continual updates, services only provide data when they are specifically called by a client
- Package: A package can be considered a container for your ROS 2 code. If you want to be able to install your code or share it with others, then you’ll need it organized in a package. With packages, you can release your ROS 2 work and allow others to build and use it easily. A Package contains one or more nodes
Topics vs. Messages?
Topics are channels, messages are data types. Different topics can use the same message type.
- Note that the above diagram is slightly outdated since a ROS master only exists in ROS1
Going from ROS1
\rightarrow
ROS2
- Before, you did like
rostopic list
, now, you doros2 topic list
- Launch files use python scripts, not
.xml
- You don’t need to start
roscore
now
ROS2 Commands
Workspace Commands
If you do colcon build --symlink-install
, then that creates symlinks so you don’t need to rebuild everytime you update the URDF, except when you add a new file.
Basic Commands
Node Commands
ros2 run <package_name> <executable_name>
ros2 launch <package_name> <launch_name>
ros2 node list
ros2 node info <node_name>
Topic Commands
Service commands
ros2 pkg create --build-type ament_python --node-name camera_object_detection camera_object_detection # Python Package
The package.xml
file is very important. It contains all the information about the dependencies of the package:
- For dependencies only used in testing the code (e.g.
gtest
), usetest_depend
. - For dependencies only used in building the code, use
build_depend
. - For dependencies needed by headers the code exports, use
build_export_depend
. - For dependencies only used when running the code, use
exec_depend
. - For mixed purposes, use
depend
, which covers build, export, and execution
See ROS Examples for examples of nodes.