Arduino Balancing Itself Robot
This Robot is based on the Joop Brokking Project (YABR - Your Arduino Balancing Robot)
Adapted for my building conditions and PID adjustments.
The Robot has a very simple construction, but it has many concepts that can be learned and / or improved with the construction and adjustment of this robot.
Constraining with other self-balancing robots, you will notice that it uses step motors unlike many (the majority) who use DC motors with gearboxes that are cheaper; but the one that uses stepper motor, offers much more opportunity of an excellent control of movement. DC motors have a lot of mechanical friction and electrical differentials that degrade over time and causes changes of performance over time, since stepper motors are free of these factors with much greater durability and constancy of operation.
In this post I will show all the details of building the robot itself, also called self-balancing.
It consists of an Arduino module with an MPU (Gyroscope and Accelerometer) controlling the angle and rotation of the robot to keep it balanced on the axis vertically, the control is done by driving two step motors so that it can have the balancing action using PID control to keep the robot upright (even when an external force is applied).
A remote control, controls the drive forward and backward and left and right.
Step 1: MATERIAL LIST:
To the ROBOT:
1 x arduino pro-mini (5V) ATMEGA-328, 16MHz)
1 x wireless serial communication module for 2.4 GHZ
1 x MPU 6050 (gyroscope and accelerometer)
1 x module arduino pro-mini FTDI USB to TTL
1 x DC / DC converter - 12V to 5V
1 x LiPo battery 3 cells (11.1V) 2200 mAh
2 x step motor DRV8825 driver
1 x 2K2 Ohm resistor
1 x 3K3 Ohm resistor
1 x 4K7 Ohm resistor
1 x diode 1N4007
2 x TAMAGAWA SEIKO step motors 0,45graus 800S / R 40Ohm 0,3A per phase
2 x 65mm diameter robot wheels
1 x standard perforated plate
To the CONTROL:
1 x arduino pro mini (5V ) ATMEGA-328, 16MHz)
1 x wireles serial communication module 2.4 GHZ
1 x control wii wired nunchuk
1 DC / DC converter - 5V to 3.3V
3 x rechargeable batteries 1,5V 2200mAh
1 x case for the stacks
1 x Standard Perforated Board
Wires and cables ...
(Plywood) for the 8mm thick frame (for the base and top) and 3mm (for the sides and bottom)
Plastic spacers for printed circuit board;
Bolts / nuts ...
Miscellaneous tools ...
Step 2: CODE:
The code as well as the details of the project can be downloaded from Arduino By Myself's GitHub.
Remembering that this code is the property and responsibility of Joop Brokking , but can be distributed without authorization because it is in the public domain.
We at Arduino By Myself, are not responsible for errors and corrections in this code.
Step 3: SCHEMATICS & BOARDS:
Below the wiring diagram of the various modules.
Note that the D1 diode is imperative for two reasons:
1 - it protects the system from polarity reversal of the power supply battery
2 - it provides a necessary voltage drop for 12V at the input terminals, once the Lipo battery when fully charged has a voltage of 12.6V and the voltage drop in the diode will be approximately 0.6V, resulting in the desired 12V at the input.
The resistors R3 and R2 form a voltage divider, providing 5V on the A0 pin (coded for 1023, after the analog-digital conversion) of the Arduino when the battery voltage is 12V, and thus it is possible to monitor the battery voltage. So we can control the discharge of the battery, if it drops below 10.5V (coded for 1050 in the Arduino) the system will simply stop working indicating that the battery is low and requesting its recharge (guaranteeing the battery cell life Lipo) avoiding bigger problems.
See figure 1: The original version from Joop Brokking web site: http://www.brokking.net/
See figure 2: Arduino By Myself board version (bottom view, side of the tracks)
Note that: The board is being viewed from the side of the connections, so be very careful!
Black lines are tracks made with solder, connecting point by point of the perforated pattern plate.
Colored fine lines are wires connecting the respective start and end points.
Thick colored lines are wires at the top of the board (component side).
Gray lines are contour of the components.
Note that: In my case, since my stepper motor is for 0.45 degrees per step (800 steps per revolution), I had to use the stepper motor driver set to "full step", so may there is a + 5V connection of pin 3 (top of Driver left to right) of the step motor driver (all configuration pins for "LOW" stands for "Full Step") refer to your step motor driver manual to see how to configure ......
If you are using a stepper motor with 200 steps per revolution, and 1.8 degrees per step, you should keep the connections as is in the figure show above (set to 1/4 of step).
My step motor has 8 pins (central bypass of each coil) so I left the central branch without connection and only the coils A + A- and B + B- were connected to the step motor driver.
Remote Control Scheme:
Be very careful with the power connections on the Wii Nunchuck.
The Arduino UNO or a Pro-mini will be powered by a 4.5V battery (3 x 1.5V batteries), but the wii-nunchuck control will be powered by 3.3V coming from the Arduino UNO or if you use an Arduino Pro -mini, so… should have a voltage regulator from 5V to 3.3V
See figure 3: The original using the Arduino UNO from Joop Brokking web site: http://www.brokking.net/
See figure 4: the board version using the Arduino Pro-mini (it is my version) with the 5V to 3.3V converter:
The yellow and white wires should be connected to the Arduino Pro-mini pins A4 and A5, respectively.
A4 pin must be connected to the control SDA and pin A5 must be connected to the SCL of the control.
Step 4: ASSEMBLY & ADJUSTMENTS:
Now let's set up the robot frame;
For this you can use the imagination and the materials available, but follow the guidelines for frame sizing.
All dimensions are in millimeters (mm)
The parts can be glued or simply bolted.
See figure for dimensions details (original from Joop Brokking's web site: http://www.brokking.net/
Step 5: PHOTOS:
Follow the photos of the project to serve as a guide.
Step 6: TESTING & SETTINGS:
After mounting the frame and positioned the motors and the main board;
1 - remove the step motors from the connector;
2 - power the system, using an external bench source with current and voltage measurement, set to 12.6V;
If everything went well and everything is properly all connected (connected and operating modules);
- Arduino LED should light up and blink (initially it has the "Blink" code operative);
- The green LED on the MPU should be on;
- The blue LED on the 2.4GHz transceiver should flash for a few seconds;
3 - Check the current consumed, should not pass a 50mA;
- Measure the main voltage of the circuit (+ 12.6V at the input, + 12V at the D1 output, + 5V at the regulator output)
- In my case the stepper motor consumes 300mA per phase, so the two motors will consume 600mA, counting on the rest of the circuit the total current should not be greater than a 650mA;
- turn off the system;
- place a stepper motor in the connector, observe the current consumed;
- with a wrench adjust the potentiometer of the driver so that the current is around 300mA;
- turn off the system;
- remove the step motor and place the other step motor;
- switch on the system;
- set the current of this driver to the potentiometer, also for 300mA;
Ready! now the system is like the motors set.
Remember that if you are using engines other than those specified, these values will change and you must have the datasheet of your motor in order to know the working current per phase.
5 - Download the system test software;
- place your Robot in an upright position (on top of a bracket so that the wheels have free movement and the robot does not walk)
See figure 1: How to connect FTDI to USB adapter
- using the USB-Serial adapter
- download the file: YABR_hardware_test.ino, using the Arduino IDE;
- after the successful download, open the serial communication in the Arduino IDE, with the serial communication window set for 9600bps communication speed;
- take note of the balance value of your robot
(see figure 2 and 3)
6 - Download the robot software:
- now edit the file: Balancing_robot.ino, and place the balance value found, in the line: acc_calibration_value;
- in my case it was:
acc_calibration_value = -1356;
- Edit the PID gain values for your robot;
These values are empirical and each robot has its own.
Start with a high value of P for example 20 or 30 and a lower value for D for example 10 or 15, let the value of I is around 1 to 3
Go adjusting these values until you find the ideal value of P, I and D
In my case it was left as:
pid_p_gain = 30;
pid_i_gain = 1;
pid_d_gain = 10;
Also set the value of:
turning_speed = 50;
max_target_speed = 150;
- download the file to your robot;
(see figure 4)
- Ready! your robot should already be able to take the first steps
- slowly put the robot upright and check that it stabilizes in that position .....
repeat the PID adjustment steps until the robot finds its point of stabilization .....
Tip: if the robot is too far away .... shaking too much, reduce the P
If the robot is stable but starts to destabilize ... increase the D slightly
It is natural during the stabilization process he walk a little to brings back to stabilize, so do not despair..... this is a science ......
7 - Download the remote control SW.
- After all the hard work of adjustment of the PID we are ready to control the robot remotely;
- Download the SW for the arduino Pro-mini remote control;
- turn on the control, if everything is OK, it should already be possible to control your robot remotely;
8 - If you got here, it is because your robot is operational;
- make more adjustment with the PID find the best fit for it to run with speed and stability, congratulations !!!
Step 7: VIDEOS:
I am so sorry but the videos are in Portuguese my native language , but you can see the robot working properly and take an idea on how to build your own frame and boards etc...
First video - ABIR - Arduino Balancing Itself Robot - First Steps
Second video - ABIR - Frame Structure
Third video - ABIR - Main Module
Video Room - ABIR - Remote Control
Come back again, soon we will have more videos demonstrating the various stages of construction, testing and adjustments of this magnificent robot :-))