How to Finish Your First ROS Robotics Project
Struggling to finish your first ROS 2 project? This step by step guide helps you go from hardware setup to obstacle avoidance using micro ROS and ESP32.

Share :
Quick answer
Struggling to finish your first ROS 2 project? This step by step guide helps you go from hardware setup to obstacle avoidance using micro ROS and ESP32.
Quick Answer
Struggling to finish your first ROS 2 project? This step by step guide helps you go from hardware setup to obstacle avoidance using micro ROS and ESP32.
Who This Is For
- ROS 2 Learner
- Robotics Student
- Software Developer
What You Will Learn
- What ROS 2 means in practical robotics.
- How this topic connects to real robot projects.
- What to learn or build next after this article.
It can be both an exciting and intimidating challenge to build your first ROS 2 project. After building a basic robot with an Arduino, you may feel ready to explore the world of ROS 2-the industry-standard robotics framework. However, once you dive into tutorials, you're quickly overwhelmed by the abundance of workspaces, packages, nodes, and commands. As frustration mounts, your robot sits motionless in the corner. Does that sound familiar? The purpose of this guide is to help you steer clear of that situation. By adopting a methodical approach, decomposing the intricate ideas into digestible chunks, and avoiding needless diversions, we will concentrate on completing your first ROS 2 project successfully. Here, changing your perspective is crucial. Rather than attempting to construct the world's most advanced robot right away, focus on building a simple, functional system that works reliably-one that helps you learn the fundamentals without burnout or confusion.
Phase 1: The Foundation - A Simple, Reliable Robot for Your First ROS 2 Project
Before diving into the world of ROS, it's essential to ensure that your robot hardware works independently, without relying on the ROS system. This will help you isolate hardware issues from software problems later on. Here's how you can approach this: Chassis and Components
- Chassis: Start with a simple 2-wheel or 4-wheel drive chassis. This will be the base for your robot.
- Microcontroller: Use an** ESP32**. The ESP32 is crucial here due to its built-in WiFi capability, which will later allow communication with ROS 2. Note that an Arduino Uno won't suffice for this guide.
- Sensors: Use an ultrasonic sensor like the HC-SR04, which provides clean and reliable distance readings.
- Motor Control: Implement a motor driver board such as the L298N or DRV8833 to control your robot's movement.
- Pre-ROS Test: Start by writing a simple Arduino sketch for the ESP32. The sketch should have basic functions like goForward(), turnLeft(), etc. In your loop, read the ultrasonic sensor's distance. If the distance is less than 20cm, stop and turn.
Why This Step Matters
By ensuring your hardware works independently of ROS, you can troubleshoot motor wiring, sensor calibration, and power supply issues without worrying about the complexities of ROS 2 communication. This step lays a solid foundation for your first ROS 2 project, ensuring you're ready to move on to the next phase with confidence.
Phase 2: The Blueprint - Answering the Key QuestionsBeforeYou Code
Planning is crucial before jumping into the coding phase. This phase will help you understand how ROS 2 works and how to structure your system efficiently. Key Questions for Building a ROS 2 System
- What Are Our ROS 2 Building Blocks (Nodes and Topics)? In ROS 2, we break the problem intonodes that communicate throughtopics. Let's define the nodes and topics for the obstacle avoidance problem:
- Sensor Data Node (microROS_node on ESP32): This node is responsible for reading the ultrasonic sensor data and publishing the distance to a topic.
- Topic: /ultrasonic_distance (Float32 message)
- Obstacle Avoidance Node (logic_node on PC): The logic node runs on your main computer and decides the robot's actions based on the sensor data. It subscribes to the /ultrasonic_distance topic and publishes movement commands.
- Topic: /cmd_vel (geometry_msgs/msg/Twist message containing linear and angular velocity)
- Motor Driver Node (microROS_node on ESP32): This node subscribes to the /cmd_vel topic and translates movement commands into motor control signals. Here's a simple flow diagram of how these nodes communicate:
yaml
[ESP32: Sensor] -----> Publishes on /ultrasonic_distance -----> [PC: Logic Node]
^ |
| | (decides to turn)
| V
[ESP32: Motors] <----- Subscribes to /cmd_vel <----------------- [PC: Logic Node]
Why This Architecture?
This architecture isolates concerns effectively. The logic node on your PC handles the decision-making, while the ESP32 deals with low-level hardware control. This clear separation simplifies debugging and modification crucial advantages when working on your first ROS 2 project. 2. How Will the ESP32 Communicate with ROS 2? The ESP32 communicates with ROS 2 throughmicro-ROS. It's a library that turns the microcontroller into a full-fledged participant in the ROS 2 network. Themicro-ROS Agent runs on your PC, receiving data from the ESP32 over WiFi and forwarding it to the rest of the ROS 2 system. 3. How Will We Control the Motors? While ROS 2 has a more sophisticated solution calledros2_control, for this basic project, we'll stick with a simpler approach. The motor driver on the ESP32 will subscribe to the /cmd_vel topic and convert linear and angular velocity data into motor speeds. Here's a simplified C++ example:
cpp
void cmdVelCallback(const Twist& msg) {
float forward_speed = msg.linear.x;
float turn_speed = msg.angular.z;
// Simple differential drive math
float left_motor_speed = forward_speed - turn_speed;
float right_motor_speed = forward_speed + turn_speed;
// Convert these speeds to PWM signals for motors
setMotorSpeeds(left_motor_speed, right_motor_speed);
}
This method avoids the complexity of ros2_control while still introducing you to the basic principles of communication in ROS 2. 4. How Can We "See" What the Sensor Sees? Debugging without visual feedback can be challenging, which is why RViz, ROS's 3D visualizer, is invaluable. We'll create a visualization node to display what the robot's ultrasonic sensor detects.
- Task: The visualization node will subscribe to the /ultrasonic_distance topic and display a marker in RViz, showing the distance from the robot to any detected obstacle.
By adding RViz, you gain a powerful tool to visualize your robot's surroundings and troubleshoot sensor issues effectively.

Phase 3: The Execution - Build One Piece at a Time
Now that we've laid out the plan, it's time to start coding. Follow this step-by-step process to build your ROS 2 system.
Step 1: Set Up micro-ROS on Your ESP32
First, you need to set up micro-ROS on your ESP32. This step is essential in your first ROS 2 project, as it involves compiling and uploading the necessary code to enable your ESP32 to publish and subscribe to ROS 2 topics.
Step 2: Test the Link
Start the micro-ROS agent on your PC and run the following command in your terminal to verify that the ESP32 is sending data:
bash
ros2 topic echo /ultrasonic_distance
You should see the distance data from your sensor. This confirms that your ESP32 is properly connected to ROS 2.
Step 3: Write the Logic Node
Now, write the ROS 2 logic node that will subscribe to the /ultrasonic_distance topic and publish movement commands to the /cmd_vel topic. Use Python or C++ to accomplish this.
Step 4: Test the Full Loop
Once you have the logic node running, place your hand in front of the ultrasonic sensor. The robot should begin to move in response to the sensor data. Congratulations, you've completed the first step in building a ROS 2 robot!
Step 5: Add Visualization
Write the visualization node and open RViz. Add a Marker display that listens to the /marker topic, and you'll see a virtual obstacle appear when the sensor detects it.
Conclusion
By breaking down the process into clear phases and focusing on understanding the core ROS 2 communication system, you've successfully completed your first ROS 2 project a robot that can avoid obstacles using ROS 2. What's more, you've learned how to communicate between nodes, use micro-ROS, and visualize sensor data in RViz. These skills will serve as the foundation for more complex projects down the road. For more in-depth guides and support on ROS 2, you can explore the ROS 2 Documentation or visit micro-ROS for specific details on using micro-ROS with ESP32. If you're looking to go further-from beginner-level robots to fully autonomous systems our Mobile Robotics Engineering course at Robotisim offers structured, hands-on learning with expert guidance. We'll help you move from "just trying to make it work" to building robots that actually work.
Practical Example
A practical way to use this article is to connect the concept to a small robot workflow: identify the input, the processing step, and the output you expect from the robot. If the article involves ROS 2, test the idea in a small workspace or simulation before applying it to a larger robot project.
Common Mistakes
- Trying to memorize the term without connecting it to a robot behavior.
- Skipping the prerequisite concepts that make the workflow easier to debug.
- Copying commands or code without checking what each node, topic, file, or parameter is responsible for.
- Treating one tutorial as a complete roadmap instead of linking it to the next concept.
How This Connects to Other Topics
- 3D Printing Robotics Hardware for an Autonomous Robot Build
- How to Collect Raw Sensor Data for Robotics with ROS 2
- How to Add Custom Libraries to a ROS 2 Python Package
- How to Start Developing in ROS 2: A Beginner-Friendly Guide
- How to Start with ROS 2
Learn Next
- 3D Printing Robotics Hardware for an Autonomous Robot Build
- How to Collect Raw Sensor Data for Robotics with ROS 2
- How to Add Custom Libraries to a ROS 2 Python Package
- How to Start Developing in ROS 2: A Beginner-Friendly Guide
- How to Start with ROS 2
- ROS 2 Foundation Path
FAQ
Is How to Finish Your First ROS Robotics Project suitable for beginners?
Yes. The article is written to make the concept easier to understand, while still connecting it to practical robotics work.
What should I learn before this topic?
Start with the prerequisite ideas listed in the article, then connect them to a small project or simulation so the concept becomes concrete.
How does this topic connect to real robots?
It helps you understand how software, sensors, control, simulation, or career decisions show up in practical robot development.
What should I do after reading this article?
Pick one related concept from the Learn Next section and build a small example that uses it.
Can I learn this through Robotisim?
Yes. Robotisim connects these concepts to structured learning paths and project-based robotics practice.
Final Summary
How to Finish Your First ROS Robotics Project is part of the broader ROS 2 Learning learning path. The key is to understand the concept, connect it to a real robot workflow, and then practice it through a focused project instead of learning it in isolation.
This article supports ROS 2 Foundation Path, especially ROS 2.
Learn with Robotisim
Start learning ROS 2 step by step inside Robotisim.
Explore the academyLearn next

3D Printing Robotics Hardware for an Autonomous Robot Build
Discover how to 3D print robotics hardware for building autonomous robots. Learn key steps from assembly to motion control with ROS 2
Read more
How to Collect Raw Sensor Data for Robotics with ROS 2
Learn to integrate sensors with ROS 2 and collect raw sensor data for robotics. Guide on real time data processing and sensor fusion for autonomous robots.
Read more
How to Add Custom Libraries to a ROS 2 Python Package
Learn to create custom libraries for ROS 2 Python packages. Enhance your robotics projects with reusable code and improve your development workflow!
Read more
How to Start Developing in ROS 2: A Beginner-Friendly Guide
Begin your ROS 2 development journey with our guide. Learn key concepts and setup for creating effective robotics applications in no time!
Read more