Building a robot presents exciting challenges, especially when integrating crucial components like motors. For instance, the popular L298N motor driver, while cost-effective, typically experiences a voltage drop, meaning an 11-12 volt battery supply might only deliver 9-10 volts to your motor. This limitation can significantly impact performance, causing motors to run at approximately 75% of their maximum speed.
The video above provides an excellent foundational guide to navigating the complexities of using **motors in robotics**, from basic wiring to advanced ROS integration. This accompanying article will expand on these concepts, offering deeper insights and practical considerations for hobbyists and budding roboticists alike.
Deconstructing Robotic Motion: The “Onion” Approach
Complex robotics problems, like successfully controlling motors, can be effectively tackled by breaking them down into simpler, manageable layers. This “onion” analogy allows us to understand each component’s role and how they interact to achieve robust motion control.
1. **The Motor: Your Robot’s Muscle**
At its core, a robot’s ability to move hinges on its motors. For many beginner projects, brushed DC motors are a popular choice due to their simplicity and availability. Applying the correct supply voltage directly will make a brushed DC motor spin, as demonstrated with a 12-volt motor connected to a 12-volt battery.
However, this basic setup offers no control over speed, direction, or remote operation. To unlock these functionalities, additional layers of electronics and programming are essential for effective **motors in robotics** applications.
2. **The Motor Driver: Bridging Power and Control**
Directly connecting a motor to a microcontroller like a Raspberry Pi or Arduino is generally not feasible. Motors require significantly higher voltages and currents than these microcontrollers’ pins can safely provide. This is where a motor driver becomes indispensable, acting as an amplifier between the low-power control signal and the high-power motor.
Motor drivers typically receive a low-voltage, low-current signal, often in the form of Pulse Width Modulation (PWM). They then use the main power supply to amplify this signal, delivering the necessary high-voltage and high-current feed to the motors. PWM works by varying the “on-time” versus “off-time” ratio within a series of rapid pulses; a longer on-time, or higher duty cycle, translates to a faster motor speed.
Consider the L298N driver, a commonly used and very affordable option. While it supports up to 2 amps of current per motor (with 3-amp spikes), suitable for motors with a 1.8-amp stall current, it introduces a noticeable voltage drop. This means if you supply 12 volts, the motor might only receive 9-10 volts, limiting its maximum speed to around three-quarters of its potential. Choosing the right motor driver is crucial for optimal performance in your **robotics projects**.
3. **The Motor Controller: The Brain for Motion**
Distinguishing between a motor driver and a motor controller is vital for clear understanding. A motor driver blindly amplifies an input signal, whereas a motor controller is a “smarter” circuit. It takes higher-level commands, such as a target speed or position, and calculates the precise PWM signal required for the driver to achieve that command.
Open-Loop Control: Simple, but Limited
The simplest form of motor control is open-loop control, which relies on a predefined mapping between input and output signals. For instance, a joystick’s 0-100% input could directly translate to a motor’s 0-100% speed. While straightforward and sufficient for some basic applications, this method lacks adaptability.
Open-loop systems do not account for external factors that can influence motor speed, such as changes in load, battery charge, or even inconsistencies between forward and reverse motion. To achieve truly robust automation in **DIY robotics**, a more sophisticated approach is necessary.
Closed-Loop Control: Precision Through Feedback
For accurate and consistent motor performance, closed-loop control (also known as feedback control) is paramount. This system continuously measures the motor’s actual speed or position and feeds this data back to the controller. The controller then adjusts its output signal until the motor’s measured performance matches the desired target.
A widely adopted methodology for closed-loop control is PID (Proportional-Integral-Derivative) control. This algorithm calculates the error between the desired setpoint and the measured process variable, then applies corrections based on the proportional, integral, and derivative components of that error. This allows for precise and stable motion, making it a cornerstone for sophisticated **motion control** in robotics.
4. **Encoders: The Eyes and Ears of Your Motors**
To enable closed-loop control, the motor controller needs a reliable way to measure the motor’s speed or position. Encoders serve this critical function by providing real-time feedback. Many brushed DC gear motors come with pre-installed encoders, often visible as small black discs at the motor’s rear.
These encoders typically use Hall effect sensors to detect changes in a magnetic field as the disc spins, generating a series of electrical pulses. A common encoder might produce anywhere from 8 to over 100 pulses per revolution. Crucially, because these discs are often located before a gearbox, a single revolution of the output shaft can correspond to many hundreds or even thousands of internal encoder counts, providing high resolution for speed measurement.
Empirical Measurement: Knowing Your Counts Per Revolution
To convert encoder pulses into a meaningful speed (like RPM or degrees per second), you need to know the total “counts per revolution” (CPR) of the output shaft. While datasheets can provide this information, empirical measurement offers a more reliable approach, especially for generic or un-documented motors. As demonstrated in the video, resetting the encoder count and then physically rotating the motor shaft multiple times (e.g., 32 revolutions) allows you to calculate the precise CPR. For the example motors, 110,337 counts over 32 revolutions yields approximately 3,448 counts per revolution, rounded to 3,450 for practical use. This accurate CPR value is essential for precise **robotic motors** control.
5. **Communication: Orchestrating the Robotic System**
In more advanced robots, it is common to separate the high-level “robot controller” (e.g., a Raspberry Pi) from the lower-level “motor controller” (e.g., an Arduino). This modularity offers several advantages. Firstly, it allows for easier swapping of components; if you decide to upgrade your motor controller or switch your main robot controller, the separate layers minimize system disruption. Secondly, it isolates critical control functions. Offloading real-time tasks like PID loops to a dedicated microcontroller prevents potential interruptions from other high-processor-usage tasks on the main robot controller, ensuring consistent and reliable motor performance.
Communication between these controllers typically occurs over a serial line. Common serial protocols include RS232, RS422, RS485, CAN, I2C, or even dedicated PWM lines. In many hobbyist setups, serial communication over USB, connecting a Raspberry Pi to an Arduino, is a convenient and effective solution. This setup allows the Raspberry Pi to send target speed requests to the Arduino, which then executes the precise motor control, potentially feeding back information like current speed or position.
6. **ROS Integration: Advanced Control for Your Robot**
For building complex, autonomous robots, integrating your motor control system with the Robot Operating System (ROS) is a powerful step. ROS provides a flexible framework for managing various robot components, from sensors to actuators, through a publish-subscribe model. The `ros2_control` libraries are specifically designed for managing hardware interfaces in ROS 2, offering robust solutions for motor control.
The video demonstrates a practical integration using a custom ROS node (`serial_motor_demo`) running on a Raspberry Pi. This node listens for desired motor speeds on a ROS topic and translates them into serial commands for the Arduino motor controller. On a separate development machine, a graphical user interface (GUI) node allows for user-friendly control, sending commands over ROS topics via Wi-Fi. Key parameters for the ROS driver node include the serial port (`/dev/ttyUSB0`), baud rate (`57600`), control loop rate (`30` loops per second), and the empirically determined encoder counts per revolution (`3450`).
This higher-level integration allows for seamless control, whether testing open-loop raw PWM commands (e.g., `O 255 255` for full speed) or closed-loop feedback control (e.g., `M 115 115` to achieve one revolution per second for motors with 3,450 CPR and a 30 Hz PID loop). The ability to manage **electronic speed control** through a comprehensive framework like ROS significantly enhances the capabilities of your **robot building** endeavors.
Your Robotics Motor Q&A: From Torque to Troubleshooting
What is the main purpose of a motor in a robot?
Motors are essentially the “muscles” of a robot, enabling it to move. For beginners, brushed DC motors are a popular choice because they are simple to use.
Why can’t I connect a robot motor directly to a Raspberry Pi or Arduino?
You generally cannot connect motors directly to microcontrollers like Raspberry Pi or Arduino because motors require significantly higher voltages and currents than these devices can safely provide.
What is a motor driver and what does it do?
A motor driver acts as an amplifier, bridging the gap between a low-power control signal from a microcontroller and the high-power needs of a motor. It takes a low-voltage signal and uses a main power supply to deliver the necessary power to the motors.
What is the difference between open-loop and closed-loop motor control?
Open-loop control relies on a predefined input-output relationship without checking the motor’s actual performance. Closed-loop control, however, continuously measures the motor’s real speed or position and adjusts its output until it matches the desired target.
What are encoders used for in robotics?
Encoders provide real-time feedback about a motor’s speed or position, often by generating electrical pulses as the motor spins. This feedback is crucial for closed-loop control systems to ensure accurate and consistent motor performance.

