/ROS2-PROJECT-UDACITY

This repository provides demonstration of ROS 2 communication methods such as messages via topics using a Publisher and Subscriber, ROS 2 services using Server and Clients, and ROS 2 Actions using Action Server and Action Clients.

Primary LanguageC++

ROS2-PROJECT-UDACITY

This is my project for the final assessment of the C++ Udacity nano Degree.

In here, i have implemented the main concepts of the ROS 2 in C++, such as ROS 2 publishers, subscribers, messages , topics, services, clients and Actions. In reference to the ROS-2 Official Tutorial

Setup

  1. Install ROS 2 Galactic on your system via the official documentation

  2. Source the ROS 2 environment by entering this command source /opt/ros/galactic/setup.bash

  3. Create the workspace

    mkdir -p ~/dev_ws/src
    cd ~/dev_ws/src

  4. Clone my packages in the src folder

    Publishers,subscribers, server, and client package
    - git clone https://github.com/SHIVOH/ROS2-PROJECT-UDACITY.git
    ROS action server and client package
    -git clone https://github.com/SHIVOH/ROS2-ACTIONS.git
    dependency packages
    - git clone https://github.com/SHIVOH/tutorial_interfaces.git
    - git clone https://github.com/ros/ros_tutorials.git -b galactic-devel
    - git clone https://github.com/SHIVOH/action_tutorials_interfaces.git

  5. Reach the root of your workspace cd dev_ws

  6. Build the packages colcon build

  7. Source the overlay by . install/setup.bash

ROS 2 File structure

dev_ws
│   
│      
│
└───src
│   │   
│   │   
│   │
│   └───udacity_final_project
│       │   CMakeLists.txt
│       │   include
│       │   package.xml
│       │   README.md
│       │   src
│       │     └─── multiply_three_ints_client.cpp
│       │          multiply_three_ints_server.cpp
│       │          multiply_two_ints_client.cpp
│       │          multiply_two_ints_server.cpp
│       │          num_publisher_member_function.cpp
│       │          num_subscriber_member_function.cpp
│       │          publisher_member_function.cpp
│       │          subscriber_member_function.cpp
│       │ 
│       action_tutorials_cpp
│       action_tutorials_interfaces
│       ros_tutorials
│       tutorial_interfaces
│        ...
│   
└───build
│    
───install
│  
└───log  

Running the ROS 2 nodes

Publisher and Subscriber nodes for ROS 2 message transfer

Publisher node publishes the ROS messages to the ROS topic and then the Subscriber node collects the ROS messages from that topic.

Publisher node

Publisher node will publish a message to the ROS topic named "topic".

To run the Publisher ros node
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash
ros2 run udacity_final_project utalker

Subscriber node

Subscriber node will subscribe to the ROS topic named "topic" and get the messages published in the same.

To run the subscriber ros node
Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash
ros2 run udacity_final_project ulistener

Example of execution

Server and clients nodes for a ROS 2 service

Services are another method of data transmission in the ROS 2. In here, the client node request a service to the server client and the server process the request and sent the data to the client node.

To run the server node

Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash

to compute multiplication of two numbers we give as input.

ros2 run udacity_final_project userver

to compute multiplication of three numbers we give as input.

ros2 run udacity_final_project numserver

To run the client node

Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash

to compute multiplication of two numbers we give as input.

ros2 run udacity_final_project uclient X Y
In here, the X and Y represent any number that you wish to multiply.
eg ros2 run udacity_final_project uclient 5 6

to compute multiplication of three numbers we give as input.

ros2 run udacity_final_project uclient X Y Z
In here, the X and Y represent any number that you wish to multiply.
eg ros2 run udacity_final_project uclient 5 6 9

Example of execution Example of execution

Actions in ROS 2

Actions are yet another method of communication in ROS 2. In here, an action client request the action server for a goal completion. The Action server do the task and return the result to the client. Moreover, it also provide feedback regarding how the task is progressing.

To run the Action server node

Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash
ros2 run action_tutorials_cpp fibonacci_action_server

To run the Action client node

Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash
ros2 run action_tutorials_cpp fibonacci_action_client

In this specific example, you are creating an action in which the client sends the goal to the server to print out the specific [here it is 15] number of fibonacci numbers as the output.Each calculation is send as a feedback to the client too.

To change the number, go to the folder dev_ws/src/action_tutorials_cpp/src
then, edit the 47th line of the fibonacci_action_client.cpp file
goal_msg.order = 15;
Set the goal_msg.order to the required number of fibonacci terms required.

Example of execution

Reference

For the grading of the project
Criteria Meets Specifications
A README with instructions is included with the project Completed
The README indicates which project is chosen. Completed
The README includes information about each rubric point addressed. Completed
The submission must compile and run. Tested
The project demonstrates an understanding of C++ functions and control structures. Yes. eg: multiply_two_ints_server.cpp line 6 to 13
The project accepts user input and processes the input. yes, eg: ros2 run udacity_final_project uclient 5 6 (takes input 5 and 6)
Classes use appropriate access specifiers for class members. yes, eg: num_publisher_member_function.cpp ,line 11 and 20
Classes follow an appropriate inheritance hierarchy. Yes, eg: dev_ws/src/action_tutorials_cpp/src/fibonacci_action_client.cpp, line 15
The project uses smart pointers instead of raw pointers. yes, eg: dev_ws/src/action_tutorials_cpp/src/fibonacci_action_server.cpp line 35 (shared_ptr)
The project uses multithreading. Yes, dev_ws/src/action_tutorials_cpp/src/fibonacci_action_server.cpp line 57-58