So, let’s first complete the wiring.
Each motor needs 2 signals, one for the clockwise movement, one for the counterclockwise movement.
I’m using the GPIO 18 ,23,24,25 connected directly to the 4 inputs of the bridge. See the diagram below.
Consider Motor 1. When GPIO 18 is high , the bridge set the Out1 also High and Out2 is the ground. And the motor turns cw. When GPIO23 is High the bridge inverts the outputs, so Out1 become the ground and Out2 is High and the motor turns ccw.
Finally , as we see in preview post, modulating the pulse width of the signal we can control the speed of the motors.
So let’s start by moving the rover!
In my case I have 2 DC gear-motors with this specifications:
- Gearbox: 4.8~7.2V
- No load current:190mA(max.250mA)
- Stall current: ~1A
- No load speed: 90±10rpm
- Torque: 800gf.cm
The control of this type of motor is really simple: when power on, it moves, when disconnected it stay still. Simple!
So what we can do is tuning the motor speed by power on and off the motor itself using pulses of different width: we will use the PWM (pulse width modulation).
So consider to send a pulse every 20ms (subcycle=20ms) and the pulse width is 16ms, than the motor stays on for the 80% of the time, while if the pulse width is 10ms it stays on for 50% of the time.
The motor can drain up to 250mA .It is too much for our raspberry output, so we need a bridge in between than can guaranty this current.
That’ s why in the Bill Of Material I have the L298N bridge.
This board receive the input from rpi and send an output of the same width , with a signal level (voltage and current) depending on the power in you connect ( the used battery pack).
In particular , the bridge I’m using can drive up to 2 motors.
Below the schema for the power connection. Note that the bridge can also provide a 5 V output than can be used to power the raspberry.
In the next post, I’l explain how to connect the outputs and how to control them by software.
Under the xmas tree, Santa put a present for me including:
- Dagu 4D Magician Chassis (including 4 DC motors, and 2 plastic plates,4 x AA battery holder) -21 Eur
- HC-SR04 sensor (a ultrasound sensor for measuring distance) -4 Eur
- L298N bridge ( a bridge for controlling up to 2 motors) -4,5 Eur
In addition I had already:
- raspberry pi
- Pi cam
- a wifi adapter
- an omniwheel (spherical)
- an empty tic-tac candy holder
- 4 X aa Batteries
- a smartphone battery pack (2.5 A)
So I put every togheter and it pops out myR: a super Rover!!!
Nothing special under the sky, but an interesting project to test autonomous veicles. So, to reach that goal , I’m now working on a rover that can act in this 4 modes:
- Jog mode, moved by operator ( my 5 years old son…).
- Program mode: it is possible to create a sequence of movements and the rover can repeat them.
- Discover mode: the rover can move randomly aroud the appartment avoid any obstacle in fornt of him.
- Search mode: the rover can search and reach a ball placed or moved around.
As always I’m developing this features using python and using object-oriented programming: for each item I create a module that implements all the necessary features for this item.
In the next weeks I’ll post the development steps.
Happy new year and Keep in touch!