ROS 2 LearningJune 05, 20257 min read

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.

How to Collect Raw Sensor Data for Robotics with ROS 2

Share :

Quick answer

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.

Quick Answer

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.

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.

Go Beyond the Blink: When Your Robot Starts toFeel The first time your robot reacts rather than merely moves, something energizes you. The sensors pulse; the gears hum; for once the robot knows, not only acts. In this blog, we'll discuss how to collect raw sensor data for robotics with ROS 2. From encoder ticks to IMU readings, this is where autonomy starts. Want to have your robot listen to the planet?

1. Wire the "Throttle Cable" - L298D <-> ESP32

**Analogy:**The ESP32 is the driver's hand, the L298D is the gas pedal.**Why It Matters:**Before your robot can read the world, it must first be able to move through it. Connecting the ESP32's GPIO pins (17-20) to the L298D motor driver establishes the basic motor interface.**How:**Flash a basic C++ sketch that delivers a forward PWM pulse:

analogWrite(17, 128); // IN1
analogWrite(18, 0); // IN2
analogWrite(19, 128); // IN3
analogWrite(20, 0); // IN4

This delivers a balanced 50% PWM to both motors-enough to see the wheels turn in place. This foundational connection ensures your robot cancollect raw sensor data for robotics and respond to drive commands in real-time, enabling motion tests and eventual mapping.

2. Install micro-ROS - The "Walkie-Talkie" Between Brains

**Analogy:**A two-way radio letting the Pi shout orders and hear back.**Why It Matters:**You can't collect data if your microcontroller and your main compute unit (like a Raspberry Pi) don't speak the same protocol. micro-ROS bridges that gap by integrating low-power embedded systems into the ROS 2 ecosystem. How:

  1. Build micro-ROS firmware with colcon build on the ESP32 side.
  2. On the Pi, launch the agent:
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0

3. Translate /cmd_vel to Motor PWM

**Analogy:**GPS voice ("turn left") becomes a nudge on the steering wheel.**Why It Matters:**Commanding motion with /cmd_vel (the standard ROS velocity command topic) means your robot is now responding to high-level input-just like steering a car.**How:**Subscribe to /cmd_vel, then map the linear.x and angular.z components to left/right motor PWM values. Here's the pseudocode:

left_pwm = speed + rotation;
right_pwm = speed - rotation;

Then set PWM using analogWrite() accordingly. This simple transform converts velocity commands into direct action, helping your robot collect raw sensor data for robotics and ground its mobility.

4. Measure Reaction Time

**Analogy:**Stopwatch from driver shout to wheel spin.**Why It Matters:**Responsiveness is critical for real-time robotics. Latency in command execution affects path accuracy and control stability. Measuring round-trip time helps fine-tune performance.**How:**Publish a quick /cmd_vel, then listen on /motor_state or a custom feedback topic. Use ROS 2 timestamps to measure round-trip delay:

ros2 topic echo /motor_state

You're aiming for <80 ms. If not, investigate buffer sizes, Wi-Fi stability, or firmware bottlenecks.

5. IMU, The Robot's Inner Ear

**Analogy:**Your sense of balance when eyes are closed.**Why It Matters:**Inertial Measurement Units (IMUs) provide angular velocity and linear acceleration-essential for orientation, stabilization, and inertial navigation. You can read more about IMU fundamentals in robotics in this primer by VectorNav, a leading provider of precision inertial sensors. How:

  • Connect via I2C (typically SDA/SCL pins)
  • Calibrate flat
  • Publish data to /imu On the Pi:
ros2 topic echo /imu

Visualize using the RViz IMU plugin to verify pitch, roll, and yaw. This data enables accurate motion estimation even in the absence of external localization.

6. Encoders - The Odometer

**Analogy:**Car trip-meter counting wheel clicks.**Why It Matters:**Encoders track wheel rotation, essential for measuring distance traveled. It's your robot's main dead-reckoning tool-indispensable for environments without GPS.**How:**Use interrupt service routines (ISRs) on the ESP32 to read encoder channels A and B. Convert tick counts to distance using known wheel circumference and gear ratio.

void IRAM_ATTR encoderISR() {
 ticks++;
}

Publish to /wheel_odom as a ROS 2 topic, and monitor:

ros2 topic echo /wheel_odom

7. Broadcast the Full Telemetry Pack

**Analogy:**Group chat channels-the Pi listens on "drive" and reads "feelings."**Why It Matters:**Collecting raw sensor data in robotics isn't useful unless it's shared in real time. ROS 2's pub-sub architecture makes this seamless.**How:**On ESP32:

  • Publish: /imu_raw, /wheel_odom
  • Subscribe: /cmd_vel Spin at 50 Hz using rclc_executor for responsive telemetry. Each message completes a feedback loop that enhances your robot's responsiveness and self-awareness.

8. Quick Track Test

How:

  • Drive with:
ros2 run teleop_twist_keyboard teleop_twist_keyboard
  • Watch /imu change as you turn.
  • Record session:
ros2 bag record /imu /wheel_odom /cmd_vel

This creates a full-time log of your robot's responses, essential for debugging, replay, and testing algorithms like SLAM.

9. Why It Matters for Autonomy

This step unlocks the sensory foundation of autonomous navigation:

  • Motion: ROS 2's /cmd_vel becomes actual PWM motor movement.
  • Perception: Sensors feed live information into the control loop.
  • Odometry: Wheel and IMU data feed into SLAM and localization. Without real-time sensor data collection, autonomy is guesswork. By collecting raw sensor data for robotics, you're building a robot that understands both where it is and where it's going. The fusion of encoder and IMU data creates reliable odometry through kinematic equations, which will soon anchor your robot to a digital map.

What's Next After You Collect Raw Sensor Data for Robotics: From Raw Data to Maps

Now that you can collect raw sensor data for robotics from your robot using ROS 2, you're ready to map the world. Next in the series: Mapping 101, using LiDAR and odometry to build SLAM maps. Want to build smarter, more autonomous machines? Robotisim offers in-depth ROS 2 insights, expert blogs, and real-world engineering strategies to help you integrate sensors, actuators, and autonomy in your next robotics project. Explore robotics deeper at Robotisim, and take the next step toward building intelligent, sensor-driven robots that navigate with confidence.

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 Add Custom Libraries to a ROS 2 Python Package
  • How to Start Developing in ROS 2: A Beginner-Friendly Guide
  • How to Finish Your First ROS Robotics Project
  • How to Start with ROS 2

Learn Next

  • 3D Printing Robotics Hardware for an Autonomous Robot Build
  • How to Add Custom Libraries to a ROS 2 Python Package
  • How to Start Developing in ROS 2: A Beginner-Friendly Guide
  • How to Finish Your First ROS Robotics Project
  • How to Start with ROS 2
  • ROS 2 Foundation Path

FAQ

Is How to Collect Raw Sensor Data for Robotics with ROS 2 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 Collect Raw Sensor Data for Robotics with ROS 2 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.

Connected learning path

This article supports ROS 2 Foundation Path, especially ROS 2.

Learn with Robotisim

Start learning ROS 2 step by step inside Robotisim.

Explore the academy

Learn next

3D Printing Robotics Hardware for an Autonomous Robot Build
Jun 03, 2025|7 min read

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 Add Custom Libraries to a ROS 2 Python Package
Jun 02, 2024|6 min read

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
Jun 02, 2024|8 min read

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
How to Finish Your First ROS Robotics Project
Jul 24, 2025|8 min read

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.

Read more