full installation @ docs.ros.org | netplan, ssh
$ sudo apt update && sudo apt install ros-dev-tools
$ sudo apt install ros-rolling-desktop
$ source /opt/ros/rolling/setup.bash (put this in .bashrc / $ gedit ~/.bashrc)
The Robot Operating System (ROS) is a set of software libraries and tools that help us build robot applications. From drivers to state-of-the-art algorithms, and with powerful developer tools, ROS has what we need for our next robotics project. And it's all open source. { awesome/ros2 } & programming multiple robots with ros2.
ROS Framework Overview | ROS 2 : Rolling Ridley | github/ros2 | ETH Z : Programming for Robotics - ROS | ubuntu/what is ros? | ROSCON | ROS2 Humble Crash course | turtlebot-4 | Building a Legged Robot with ROS (Péter Fankhauser) | @jamesbruton | mini-pupper
ROS processes are represented as nodes in a graph structure, connected by edges called topics. ROS nodes can pass messages to one another through topics, make service calls to other nodes, provide a service for other nodes, or set or retrieve shared data from a communal database called the parameter server. A process called the ROS Master makes all of this possible by registering nodes to itself, setting up node-to-node communication for topics, and controlling parameter server updates. Messages and service calls do not pass through the master, rather the master sets up peer-to-peer communication between all node processes after they register themselves with the master. This decentralized architecture lends itself well to robots, which often consist of a subset of networked computer hardware, and may communicate with off-board computers for heavy computing or commands. List of ROS tools, versions and releases and configuring your ros2 environment.
$ ros2 run demo_nodes_cpp talker ( $ ros2 run package_module nodename )
$ ros2 run demo_nodes_cpp listener
$ rqt_graph
$ ros2 run turtlesim turtlesim_node
$ ros2 run turtlesim turtle_teleop_key (listen to keystrokes)
$ ros2 topic list
$ ros2 node list
$ ros2 run rplidar_ros rplidar_node
$ ros2 service list
$ ros2 service call /stop_motor
$ ros2 service call /stop_motor std_srvs/srv/Empty
ros2 workspace:
$ sudo apt install python3-colcon-common-extensions
$ cd /usr/share/colcon_argcomplete/hook/
$ gedit ~/.bashrc ( source /usr/share/colcon_argcomplete/hook/)
$ mkdir ros2_ws > $ cd ros2_ws
$ mkdir src
(ros2_ws) $ colcon build > $ ls
$ gedit ~/.bashrc ( source ~/ros2_ws/install/setup.bash )
ros2 parameters and remapping:
$ ros2 run rplidar_ros rplidar_node --ros-args -p serial_ports:=/dev/ttyUSB0 -r scan:=scan_1
$ ros2 run rplidar_ros rplidar_node --ros-args -p serial_ports:=/dev/ttyUSB1 -r __ns:=/scanner2
parameters
(-p) are a way to change the behaviour of ros nodes and remapping
(-r) is similar to reconfiguring of nodes to publish and subscribe to correct nodes. Use --ros-args
for ros2 parameters and remapping and __ns
to change namespace.
ros2 launch files make everything simple in one go $ ros2 launch testlaunch.py
.
go to 'ros2_ws' and build the package (forming the workspace):
$ mkdir -p dev_ws/src
$ cd dev_ws/
$ colcon build --symlink-install
$ ls
We will see that colcon has built build
, install
, log
, src
in teh current directory. Packages live inside the src
directory.
ros2 application (create packages in src):
$ ros2 pkg create my_robot_controller --build-type ament_
$ ros2 pkg create my_robot_controller --build-type ament_cmake my_package
$ ros2 pkg create my_robot_controller --build-type ament_python --dependencies rclpy
$ ls (rclpy in the py package for ros2)
'colcon' is the build tool and 'ament' is the build system. We can have multiple nodes in a package and packages can be dependent on each other. In the package folder > 'package.xml' for meta information. The flag ament_cmake
is for cpp projects and ros2 will create directories and files: inlcude
, src
, CMakelists.txt
, package.xml
. Inlcude a new directory launch
inside the packagename and create the talker.py
& lister.py
.
Reflect the changes in CMakelists.txt
;
install (DIRECTORY launch
DESTINATION /share${PROJECT_NAME}
)
This will tell colcon on how to install the launch
directory. The package.xml
file tells us about dependencies on other packages. Inside the package directory do $ git init
to start syncing code with git version control. To run package $ ros2 launch my_package talker.py
.
python features and packages:
$ cd packagename
$ touch feature.py > $ chmod +x feature.py
feature.py:
# /usr/bin/env python3
import rclpy
from rclpy.node import Node
class MyNode(Node):
def __init__(self):
super().__init__('first_node') #name of node
self.get_logger().info('Hello from ROS 2')
def main(args=None):
rclpy.init(args=args) #initialize ros2 communication
node = MyNode() #create node
rclpy.spin(node) #run node indef until killed
rclpy.shutdown()
if __name__ == '__main__':
main()
Add in setup.py
of the package to run ros function from terminal. After adding do $ colcon build
> $ source ~/.bashrc
> $ ros2 run packagename
:
.
.
entry_points=[
'console_scripts': [
"test_node = packagename.nodename:functionname"
],
]
$ ros2 run packagename
will give us option to run test_node
: $ ros2 run packagename test_node
. For CI/CD of py scripts do : $ colcon build --symlink-install
> $ source ~/.bashrc
.
class MyNode(Node):
def __init__(self):
super().__init__("first_node")
self.counter_ = 0
self.create_timer(1.0, self.timer_callback) # every 1 sec prints "Hello"
def timer_callback(self):
self.get_logger().info("Hello" + str(self.counter_))
self.counter_ += 1
$ ros2 node list
> $ ros2 node info /first_node
to list all nodes and introspect.
topics: $ rqt_graph
> $ ros2 topic list
> $ ros2 topic info /chatter
> $ ros2 interface show std_msgs/msg/String
.
$ ros2 topic echo /chatter
( it creates a subscriber node ).
ros2 publisher in python node: $ touch tele.py
:
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import Twist
class DrawCircleNode(Node):
def __init__(self):
super().__init__("draw circle")
self.cmd_vel_pub_ = self.create_publisher(Twist, '/turtle1/cmd_vel', 10)
self.timer = self.create_timer(0.5, self.send_velocity_command)
self.get_logger().info("circle node has been started")
def send_velocity_command(self):
msg = Twist()
msg.linear.x = 2.0
msg.angular.z = 1.0
self.cmd_vel_pub.publish(msg)
def main(args=None):
rclpy.init(args=args)
node = DrawCircleNode()
rclpy.spin(node)
rclpy.shutdown()
. #in setup.py
.
.
entry_points=[
'console_scripts': [
"draw_circle = packagename.filename:main"
],
]
In package.xml
add <depend>geometry_msgs</depend>
, <depend>turtlesim</depend>
. Check data type with : $ros2 topic info /turtle1/cmd_vel
.
ROS 2 Subscriber: $ ros2 topic info /turtle1/pose
> $ ros2 interface show turtlesim/msg/Pose
> $ touch pose_subscriber.py
import rclpy
from rclpy.node import Node
from turtlesim.msg import Pose
class PoseSubscriberNode(Node):
def __init__(self):
super.__init__("pose_subscriber")
self.pose_subscriber_ = self.create_subscription(Pose, "/turtle1/pose", self.pose_callback, 10)
def pose_callback(self, msg: Pose):
self.get_logger().info(str(msg))
def main(args=None):
rclpy.init(args=args)
node = PoseSubscriberNode()
rclpy.spin(node)
rclpy.shutdown()
ros2 service : $ ros2 service list
> $ ros2 run demo_nodes_cpp add_two_ints_server
> $ ros2 service
> $ ros2 service type /add_two_ints
.
example service call : $ ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{'a' : 2,'b' : 5}"
.
Quality of Service (QoS) : QoS helps to set standard configurations in ros2.
$ ros2 topic pub /test std_msgs/msg/Int32 "data: 42" --qos-reliability "best_effort"
$ ros2 topic echo /test --qos-reliability "best_effort"
Broadcasting Static Transforms:
$ ros2 run tf2_ros static_transform_publisher x y z yaw pitch roll parent_frame child_frame
$ ros2 run tf2_ros static_transform_publisher 1 0 0 0 0 0 robot_1 robot_2
$ ros2 run tf2_ros static_transform_publisher 2 1 0 0.785 0 0 world robot_1
$ ros2 run rviz2 rviz2
Broadcasting Dynamic Transforms:
$ sudo apt install ros-foxy-xacro ros-foxy-joint-state-publisher-gui
Coordinate Transformations - How robots move through space, The ROS Transform System (TF), Understanding the Rotation Matrix
URDF file (parameters, robot decription) → robot_state_publisher → [ /tf_static ] (fixed joint transforms), [ /tf ] (Non-fixed joint transforms), [/robot_description] (Copy of URDF).
Instead of having to broadcast whole transforms, all we need to do is publish [/joint_states] → [/robot_state_publisher]. [/simulated_actuator_feedback] → [/joint_states]. Guide: Install ros2 in vm with linux.
$ ros2 run robot_state_publisher robot_state_publisher --ros-args -p robot_description:="$( xacro -/ex_robot.urdf.xacro )"
$ ros2 run joint_state_publisher_gui joint_state_publisher_gui
$ ros2 run tf2_tools view_frames.py
ROS 2 Notes : URDF, Gazebo, RGB:RGB-D:LiDAR, ros2_control, SLAM | Nav2, Deep Learing with ROS2, ROS2 with Docker
+ ROS 2 Navigation: @rosnav
+ ROS 2 Robotic Arm 6 DoF: @rosarm
+ ROS 2 Point Cloud: @rospcloud
ROS 2 RESOURCES: An Updated Guide to Docker and ROS 2, @webviz, @rosbag.js, Web-Based Visualization using ROS JavaScript Library : ROS Bridge
ROS-Industrial is an open-source project that extends the advanced capabilities of ROS software to industrial relevant hardware and applications.
ROS 2 packages: Navigation Framework and System : nav2, Robotic Manipulation Platform : MoveIt 2, n-D Point Cloud and Geometry processing : pcl_ros, 3D Robot Visualizer : rviz.
How do we add LIDAR to a ROS robot? How to get your robot to see in 3D! (Depth Cameras in ROS) Making Your First ROS Package How do we describe a robot? With URDF! , ROS Aerial Robotics WG meeting, 6 degrees of Freedom Robot Manipulator Modeling in ROS2 and Visualization in RViz2 - URDF and Python, Robot Operating System (ROS) Course
resources: Articulated Robotics, Robotics Back End, Learn robotics with ROS, ROS Developers OPEN Class