Qty. | Item | Image | Description | Link | Price |
---|---|---|---|---|---|
2 | 12V DC encoder motor kit | 12V DC motor JGA25-371 with encoder, 130rpm reductor, 65mm wheel, coupling, mounting bracket | Amazon | 30,33€ | |
1 | Raspberry Pi 4B | Amazon | |||
1 | Arduino Nano V3 | AZDelivery Nano V3.0 with ATmega328 Chip CH340 soldered version with USB cable (Arduino Nano V3 clone) | Amazon | 18,99€ | |
1 | Arduino Nano Shell | Amazon | 6,99€ | ||
1 | L298N Motor driver | Amazon | 9,99€ (2 uds) | ||
1 | 35W Buck-Boost DC Converter | ARCELI Buck-Boost Converter with display, DC 5.5-30V 12v to DC 0.5-30V 35W | Amazon | 12,99€ | |
1 | 5" 800x480 Resistive Touchscreen | Waveshare 5" HDMI LCD 800x480 Resistive Touchscreen TFT Display with Case for Raspberry Pi 4 | Amazon | 52,99€ | |
1 | DTOF Lidar LD06 | LD06 Lidar, came bundled with Minipupper | Amazon | 99,99€ | |
1 | Pi Camera | Pi Camera v1.3 with acrilic support | |||
1 | Gamepad | PS4-compatible Bluetooth game controller. Mine came bundled with Minipupper | Fnac | 17,90€ | |
1 | Chassis | Based on a 29 x 19 x 12.4 cm Keeeper Hubert + Hilda plastic storage box with tray, used for the chassis of the robot. I purchased mine in the local Leroy Merlin. | Amazon | 8,63€ | |
1 | Battery | HRB Battery RC LiPo 5000mAh 11.1V 3S 50C XT60 Connector with 4 adapter parts. 308 g. | Amazon | 35,99€ | |
1 | Balance charger | WANGCL IMAX B6AC Lipo Battery charger B6 80W Digital LCD Lipo Cargador 11-18V con adaptador para plomo ácido NI-CD/NI-MH 1-6S LI-PO | Amazon | 42,99€ | |
1 | Mega4 USB Hub | UUGEAR MEGA4: 4-Port USB 3.1 PPPS Hub for Raspberry Pi 4B | The Pi Hut | £29,00 |
- 12V from bench power source
- A split takes the 12V to the buck converter and the motor driver.
- Buck converter takes 12V at IN+ /IN- and yields 5V at OUT+/OUT- to power the RPi
- RPi takes 5V at pin 4 (5V)/ pin 6(GND) - How do I power my Raspberry Pi
- Arduino Nano powered from RPi via USB
- Motor Driver is powered by 12V at 12V/GND pins. 5V jumper is installed, 5V terminal not connected - Could I use this to power the RPi?
- OUT1/OUT2 are connected to the Red/White of the motor. The remaining 4 cables of the encoder are disconnected.
- Connecting the IN1 / IN2 to 5V (e.g. to the 5V pin of the Arduino Nano, cfr. the Nano pinout in this tutorial) makes the Motor rotate CV / CCV
Before switching off the power supply, SSH into the RPi to shut it down:
(RPi) $ sudo shutdown -h now
Note: Powering the adafruit USB hub https://forums.adafruit.com/viewtopic.php?p=930206&hilit=external+power+usb+hub#p930206
- installed fuse and switch
- replaced split with AWG22 cable
- installed second motor
- connected Pi camera, LD06 lidar and LCD screen
- made a USB-C pigtail to connect RPi (powering from pins cannot run accesories)
- ordered spacers, USB-C pigtails, a flat HDMI cable and a USB hub
- installed flat HDMI cable, USB-C pigtail
- discarded USB hub (not needed)
Code: ./code/arduino/motor_joystick/motor_joystick.ino
The script was originally inspired on this example code for the joystick and this script for controlling motors, and later refined with this implementation (using Arduino's map() function ) and this discussion on translating joystick positions to motor speeds.
Notes:
- For motors A and B connect only motor voltage (WHITE, RED) to the motor driver L298N, keeping encoder disconnected (BLUE,GREEN, BLACK,YELLOW)
- In the motor driver L298N, remove the brakers in ENA and ENB
- Connect as per following table and diagram:
Description | Component pin | Arduino pin |
---|---|---|
Motor A speed (analog) | ENA | D9 |
Motor A direction | IN1 | D8 |
Motor A direction | IN2 | D7 |
Motor B speed (analog) | ENB | D3 |
Motor B direction | IN3 | D5 |
Motor B direction | IN4 | D4 |
Joystick: command rotation (analog) | VRX | A0 |
Joystick: command forward / backward motion (analog) | VRY | A1 |
- Analog output of VRX, VRY is in the range 0 - 1023.
- Analog input of ENA and ENB in the range 0-255.
- To change direction of rotation of Motor A reverse input to IN1 - IN2 from HIGH - LOW to LOW - HIGH
- Idem for Motor B, IN3, IN4
The script allows to control the motors with the joystick. Moving the stick in the Y direction turns both wheels forward / backward. Moving the stick in X direction moves the wheels in opposite directions to make the robot turn. The script also prints output through serial.
- install
miniterm
in PC and RPi
$ sudo apt install python3-serial
- add the user to the dialout group:
$ sudo adduser mhered dialout
- usage:
$ miniterm
--- Available ports:
--- 1: /dev/ttyAMA0 'ttyAMA0'
--- 2: /dev/ttyUSB0 'USB2.0-Ser!'
--- Enter port index or full name: 2
--- Miniterm on /dev/ttyUSB0 9600,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
(X, Y): (508, 517) | motorA: 0% | motorB: 1%
(X, Y): (510, 517) | motorA: 0% | motorB: 1%
(X, Y): (510, 517) | motorA: 0% | motorB: 1%
(X, Y): (510, 516) | motorA: 0% | motorB: 1%
(X, Y): (510, 22) | motorA: -96% | motorB: -95%
(X, Y): (493, 0) | motorA: -100% | motorB: -96%
(X, Y): (510, 517) | motorA: 0% | motorB: 1%
(X, Y): (510, 1023) | motorA: 99% | motorB: 100%
(X, Y): (510, 1022) | motorA: 99% | motorB: 100%
(X, Y): (1023, 1023) | motorA: 100% | motorB: 0%
(X, Y): (1023, 850) | motorA: 100% | motorB: -34%
(X, Y): (1023, 517) | motorA: 100% | motorB: -99%
(X, Y): (661, 517) | motorA: 29% | motorB: -28%
(X, Y): (0, 517) | motorA: -99% | motorB: 100%
(X, Y): (0, 517) | motorA: -99% | motorB: 100%
...
Note: to stop miniterm
with a Spanish keyboard press Ctrl + Alt Gr + ]
Check out this video on how to write and upload to arduino from the laptop and through the RPi: https://www.youtube.com/watch?v=2BJ-iJF04VA
Highlights of the installation:
- Copy & Paste only the path of the folder where the
arduino
executable is, e.g. in the case below paste only/home/mhered/Applications/arduino-1.8.19/
:
$ ls -l `which arduino`
lrwxrwxrwx 1 root root 48 Sep 9 02:02 /usr/local/bin/arduino -> /home/mhered/Applications/arduino-1.8.19/arduino
- No need to select a programmer, see here
- Edit
.vscode/arduino.json
to add"output":"build"
to avoid the message that it cannot use precompiled files
Highlights of the usage:
- To launch Remote SSH click in the green square in the bottom left corner of VS Code, select Connect to Host and select the host, then enter the password
- Every new session: Open the Command panel with
Ctrl + Shift + P
then start typing "Select" for Arduino: Select Sketch. The file.vscode/arduino.json
stores the selection ofport
,sketch
,board
,configuration
,output
otherwise select manually in the lower blue bar. - To compile: command Arduino: Verify. Monitor progress on the OUTPUT / Arduino window. Wait for it to finish before uploading.
- To flash: command Arduino: Upload. Wait for compile to complete before uploading. Does not work if
miniterm
is running. - To monitor serial: use
miniterm
in a new Terminal - To add libraries: command Arduino: Library Manager
- First test on the chassis
- All aboard! - including the rubber duckie
- Adding details: casters, grommets, a switch...
- All the electronics back in
- Some order inside the chassis:
- A selfie to celebrate that the camera onboard the
manolobot_uno
is broadcasting!
- Screen, safe reset/shutdown button and 3D printed camera support
- Clone
ROSArduinoBridge
from https://github.com/joshnewans/ros_arduino_bridge.git to./code/arduino/
- removed the.git
folder to disconnect it from original repo - Upload software to the Arduino
- Rewire Arduino:
Description | From | To |
---|---|---|
Motor A (Left) , power + (can be reversed with White to move motor forward and reverse) | Motor A (Left) , Red | L298, OUT1 |
Motor A (Left), power - (can be reversed with Red to move motor forward and reverse) | Motor A (Left) , White | L298, OUT2 |
Motor B (Right), power + (can be reversed with White to move motor forward and reverse) | Motor B (Right), Red | L298, OUT4 |
Motor B (Right), power - (can be reversed with Red to move motor forward and reverse) | Motor B (Right), White | L298, OUT3 |
Motor A (Left) direction | L298, IN1 | Arduino, D10 |
Motor A (Left) direction | L298, IN2 | Arduino, D6 |
Motor B (Right) direction | L298, IN3 | Arduino, D9 |
Motor B (Right) direction | L298, IN4 | Arduino, D5 |
- Run
miniterm
to test it (-e
for interactive and specify the baud rate or it won't work at 9600):
(RPi):$ $ miniterm -e /dev/ttyUSB0 57600
--- Miniterm on /dev/ttyUSB0 57600,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
o 150 150
OK
o -200 200
OK
--- exit ---
Wiring:
Description | From | To |
---|---|---|
Motor A (Left) , power + (can be reversed with Red to move motor forward and reverse) | Motor A (Left) , Red | L298, OUT1 |
Motor A (Left), Encoder power - (Voltage range 3.3-5V. Positive and negative can not be connected incorrectly) | Motor A (Left) , Black | Arduino, GND |
Motor A (Left), Encoder A phase signal feedback (11 signals per turn of the motor) | Motor A (Left) , Yellow | Arduino, D3 |
Motor A (Left), Encoder B phase signal feedback (11 signals per turn of the motor) | Motor A (Left) , Green | Arduino, D2 |
Motor A (Left), Encoder power supply + (Voltage range 3.3-5V. Positive and negative can not be connected incorrectly) | Motor A (Left) , Blue | Arduino, 5V |
Motor A (Left), power - (can be reversed with Red to move motor forward and reverse) | Motor A (Left) , White | L298, OUT2 |
Motor B (Right), power + (can be reversed with Red to move motor forward and reverse) | Motor B (Right), Red | L298, OUT4 |
Motor B (Right), Encoder power - (Voltage range 3.3-5V. Positive and negative can not be connected incorrectly) | Motor B (Right), Black | Arduino, GND |
Motor B (Right), Encoder A phase signal feedback (11 signals per turn of the motor) | Motor B (Right), Yellow | Arduino, A4 |
Motor B (Right), Encoder B phase signal feedback (11 signals per turn of the motor) | Motor B (Right), Green | Arduino, A5 |
Motor B (Right), Encoder power supply + (Voltage range 3.3-5V. Positive and negative can not be connected incorrectly) | Motor B (Right), Blue | Arduino, 5V |
Motor B (Right), power - (can be reversed with Red to move motor forward and reverse)e | Motor B (Right), White | L298, OUT3 |
Motor A (Left) direction | L298, IN1, Green | Arduino, D10 |
Motor A (Left) direction | L298, IN2, Yellow | Arduino, D6 |
Motor B (Right) direction | L298, IN3, Orange | Arduino, D9 |
Motor B (Right) direction | L298, IN4, Red | Arduino, D5 |
See https://www.youtube.com/watch?v=-PCuDnpgiew
encoder_cpr
empirically estimated as 1975 encoder counts / revolution
loop_rate
(or PID_RATE
) is set to 30 Hz (PID loops/s)
To set a wheel speed of R rev/s we send to the closed loop a command in counts per PID loop so:
(R rev/s) * (1975 counts/rev) /(30 PID loops/s) = R*1975/30 counts/PID loop = 66 R counts/PID loop
i.e. to rotate both wheels forward at 1 rev/s: m 66 66
to rotate both wheels backwards at 2 rev/s: m -132 -132
etc
- connect motors
- install and test basic motor software
- configure and test camera
- configure and test lidar
- purchase and install battery
- soft powerdown button
- USB hub
- solve issues with screen
- 3D printed parts
- connect and test encoders
- command motor through ROS
- teleoperation with gamepad
- improve layout of components inside chassis
- configure face in screen