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
-
Install ROS 2 Galactic on your system via the official documentation
-
Source the ROS 2 environment by entering this command
source /opt/ros/galactic/setup.bash
-
Create the workspace
mkdir -p ~/dev_ws/src
cd ~/dev_ws/src
-
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
-
Reach the root of your workspace
cd dev_ws
-
Build the packages
colcon build
-
Source the overlay by
. install/setup.bash
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
Publisher node publishes the ROS messages to the ROS topic and then the Subscriber node collects the ROS messages from that topic.
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 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
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.
Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash
ros2 run udacity_final_project userver
ros2 run udacity_final_project numserver
Open a new terminal, then
cd ~/dev_ws
source /opt/ros/galactic/setup.bash
. install/setup.bash
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
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
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.
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
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.
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 |