All about Robot Cars - part 1

In the next four weeks, we want to highlight small electric vehicles from all angles in our blog as the main topic. You will be amazed at how many possible combinations there are for equipping these small so-called robot cars. We start with the basic equipment, where you can choose between the two-wheel kit with support wheel and the four-wheel kit. The small DC motors are the same from almost all suppliers, but the full range of micro controllers from Raspberry Pis to AVR (Arduino compatible) and Espressif with different strengths and weaknesses is available.

For the first test, you can preprogram the commands like with the Lego ® Boost. But that gets boring quickly. A remote control is needed. With the Raspberry Pi you can use a wireless keyboard on the USB port. The WLAN-enabled MCUs can be controlled by a controller in the network, e.g. the smartphone, even with Blynk. At the end of his MQTT blog series, Jörn Weise will control a simple roll robot via his Raspberry Pi broker. And we will show you how you can build and program a radio remote control with a microcontroller board with ATmega328P, ATmega16U2, compatible with Arduino UNO R3.

Finally, we want to emulate the great models and teach our robot car to drive autonomously. With the distance sensors we can program an emergency stop or avoid obstacles. With the IR sensors we can follow a line or drive very precisely in small steps, e.g. to reverse into parking.

Let's start with the first decisions:

First you need a chassis with 2 or 4 wheels / electric motors. We don't have the kits back in our range at the moment; therefore we refer here to Amazon.

Advantages and disadvantages of the two-wheeler with support wheel: Highly mobile, can turn on the spot. But due to the (let's just say cheap) design of the motors or small bumps on the ground, straight-line stability is difficult.

 


Advantages and disadvantages of the four-wheeler: Better straight-line stability, a hooking motor is pushed, more space for MC and batteries. But straight-line stability is bought with large curve radii. And four motors also need twice as much juice from the batteries.

 


With the keyword batteries we are at the power supply of our robot cars. As you can see in the pictures, the kits contain a holder for 4 Mignon batteries / rechargeable batteries. That may be enough for first attempts; However, you reach your limits very quickly. The Mignon batteries only supply 1.2 to 1.25 V per cell, almost too little for our micro controller. And the motors, by far the larger consumers of electricity, like a little more "oomph". A holder for 6 Mignon batteries is better. It is also advisable to have a separate power supply for the motors and microcontroller, because a motor that jams for a short time can quickly cause the MCU to restart.

Most readers will know that the micro controllers cannot supply the motors directly with power and that the motor speed is controlled via pulse width modulation (PWM). So we need a motor controller that, controlled by the MCU with PWM, directs the external power supply to the motors. In the simplest case, this can be an IC module named L293D. However, shields or HATs with one or two of these chips, which are plugged directly onto the respective micro controller, are recommended. We will explain in detail in a blog how this chip, a so-called H-bridge, works.

Next we have to decide which micro computer or micro controller to choose. Here, too, there are advantages and disadvantages to the different solutions.

If you need a lot of computing power, use a micro computer, e.g. from the Raspberry Pi family: Raspberry Pi 3B, 3B +, 3A +, 4B or Zero WH are recommended. Advantages: Greatest computing power, WLAN, Bluetooth, keyboard control, many sensors, camera (!), PWM for servo motors. Python is used as the programming language with the very powerful program module gpiozero. An inexpensive motor controller is the MotoZero from ThePiHut in pHAT (Pi Zero) format for four motors. And there are other motor controllers based on the L293D. But the disadvantages must not be concealed: The RasPis need approx. 1 min to boot from the µSD card and want exactly 5.0 to 5.1 volts without interruption.

The least sensitive to the power supply are the Arduino-compatible micro controllers with Atmel processors, e.g. our microcontroller board with ATmega328P, ATmega16U2, compatible with Arduino UNO R3, for which there is a suitable motor driver shield. This combination offers further connection options for sensors, the sketch is compiled in the Arduino IDE and our robot car is ready for use immediately after switching on. Due to the lack of WLAN capability, however, we are not able to control this otherwise robust and beginner-friendly variant. But a remedy here is a radio remote control with 433MHz or 2.4GHz.

The MCUs from Espressif bring WiFi with them by default: Regardless of whether ESP8266-12F or ESP32, the minis are also suitable for our Robot Car. But here too, as with the RasPis, a DC-DC converter should be used for a stable power supply. Because e.g. two 18650 LiPo batteries deliver 7.4 to 8.4 V, 6 Mignon batteries approx. 7.2 to 7.5V, too much for our micro controllers, even if they have partially built-in voltage regulators. (These are mostly for the internal 3.3V).

What do we still need? If the cables for the power supply to the motors are not yet soldered on, we will need a soldering iron. Otherwise all connections are screwed or plugged with jumper cables. For attaching the battery compartment and individual components, I recommend double-sided adhesive tape and self-adhesive Velcro tape or cable ties.


In this general introduction I would like to refresh the basic knowledge about DC motors and pulse width modulation.

DC motors have two connections for plus and minus. The polarity determines the direction of rotation of the motor. The polarity reversal then works with the H-bridge mentioned above. First, here is the functional principle of the DC motor:

 

Image from Kampert / Scherbeck: Understanding electronics with Raspberry Pi

The left picture shows the opposing poles, which move the rotor into the horizontal position due to the Lorentz force. The middle picture shows this horizontal position, in which the current flow is interrupted, but the rotor continues to move due to the inertia. Shortly afterwards, the wipers touch the other contacts of the commutator (right picture). The polarity of the magnetic field of the rotor is reversed, and the same poles now repel each other. The rotation continues.

As an example, I show the L293D motor driver shield for Arduino Uno and compatible micro controllers, on which up to 4 motors can be connected to the screw connections. If the direction of rotation does not match - simply reverse the polarity of the respective motor connection. The screw connections for the external power supply are located in the bottom left of the picture. You don't need to worry about the connections on the micro controller - just plug it in and read the connection assignment of the motors for the sketch in the data sheet. The optional connection of two servomotors at the top left is also clearly visible.

 


All motor driver boards with the L293D are PWM capable. These electronic H-bridges can not only change the direction of rotation, but also regulate the speed of the motors.

PWM stands for pulse width modulation in German and pulse width modulation in English (PDM is also synonymous with pulse duration modulation) and this means that instead of a constant DC voltage, we emit pulses, i.e. always switch the current on and off. However, this is happening so quickly that we do not see it. As in the cinema or on TV, where 24 or 25 frames / second make a film for our eyes. How often in a second is switched on and off (the frequency, "rate" or "frequency") is one of the parameters of our PWM. Here we can use the respective presets.

The second characteristic is the ratio of the pulse duration to the total duration of a cycle, consisting of pulse + pause. This characteristic is called the "duty cycle".

 


What does this mean for our DC motors? You get the full voltage with the pulse, while the current flows only proportionally according to the duty cycle. This means that less electrical energy is supplied to the engine.

The programming is quite simple: we use the function analogWrite(), with the syntax analogWrite (pin, value)where pin is the pin number without first defining it as an output, and value is an integer number between 0 and 255 (at 8 bit PWM), i.e. e.B. 25% equals 63.

After calling analogWrite(), the function generates a continuous square wave with a specified cycle until the next call to analogWrite() (or digitalRead() or digitalWrite()) occurs on the same pin.

For more details, see arduino.cc's reference page,
https://www.arduino.cc/reference/de/language/functions/analog-io/analogwrite/
where I copied the following sample code, which is especially interesting because the analog input size has a 10-bit resolution (max. 1023), while the output value can be max. 255.

The code sets the output on the LED pin 9 proportionally (factor 4) to the value read by a potentiometer on A3. The LED represents our engine.

int ledPin = 9; LED to digital pin 9 connected

int analogPin = 3; Potentiometer on pin 3 connected

int val = 0; Variable to store the read value

void setup() {

  pinMode(ledPin, OUTPUT); // Sets the pin as output.



void loop() { 

val = analogRead(analogPin);  // Read values from analogPin

analogWrite(ledPin, val / 4);   // analogRead: values from 0 to1023,

                                //analogWrite: values from  0 to 255

}


The whole thing is almost as simple in the Python programming language on the Raspberry Pi, at least if you use the gpiozero module. This will be shown in a later blog post.


I hope I have aroused your curiosity and you will follow us in the next few weeks, when the blogger team will show different priorities in the control and regulation of robot cars.



3 comments

Guido Jensen

Guido Jensen

Cooles Project, werds jetzt doch mal probieren.

UND…ist das DER Walter Goegebeur :-)) ?

Guido

Volkert Braren

Volkert Braren

Vernünftig funktionierende Stützrollen hab ich noch nicht gefunden. An Teppichen und kleinen Stufen bleiben die gern hängen. Stattdessen setze ich ein Servo mit kleiner Möbelrolle ein. Steuerung mit der Motorsteuerung synchronisiert.
Geradeauslauf verbessern mit Tachorädern an den Motorachsen.
Grüße, Volkert

Walter Goegebeur

Walter Goegebeur

Darauf freue ich mich sehr. Es ist super das Sie sich um aktuelle Themen kümmern und uns mit Denkanstöße fördern und das für günstige Preise. Vielen Dank.

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN