EasyManua.ls Logo

SunFounder 3in1 Kit - Speed Calibration

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
5.12 11. Speed Calibration
In getting the car to move forward, you may find that the car does not travel in a straight line. This is because the two
motors may not have the same speed at the factory. But we can write offset to the two motors to make their rotational
speeds converge.
In this project, we will learn to store the offset into EEPROM, the point of this is that after each calibration, all projects
can get the offset value directly from the EEPROM, so that the car can go in a straight line smoothly.
Wiring
This project is the same wiring as 2. Move by Code.
How to play?
1. Open the 11.speed_calibration.ino file under the path of 3in1-kit\car_project\11.
speed_calibration. Or copy this code into Arduino IDE.
2. After the code is uploaded successfully, connect the car with 9V battery, put it on the ground and let it move
forward to see which side it is offset to.
If the car moves to the left front, it means the right motor speed is too fast and needs to be reduced.
EEPROM.write(1, 100) // 1 means the right motor, 100 means 100% speed, can
˓be set to 90, 95, etc., depending on the actual situation.
If the car moves to the right, it means the left motor speed is too fast and needs to be reduced.
EEPROM.write(0, 100) // 0 means the right motor, 100 means the speed is 100
˓%, can be set to 90, 95, etc., depending on the actual situation. 3.
3. After modifying the code, upload the code to R4 board to see the effect. Repeat the above steps until the car is
almost straight.
4. This offset will be recorded in EEPROM, you only need to read this offset when you use it in other projects, take
5. Play with Obstacle Avoidance Module as an example.
#include <EEPROM.h>
float leftOffset = 1.0;
float rightOffset = 1.0;
const int A_1B = 5;
const int A_1A = 6;
const int B_1B = 9;
const int B_1A = 10;
const int rightIR = 7;
const int leftIR = 8;
void setup() {
Serial.begin(9600);
//motor
pinMode(A_1B, OUTPUT);
pinMode(A_1A, OUTPUT);
pinMode(B_1B, OUTPUT);
(continues on next page)
5.12. 11. Speed Calibration 263

Related product manuals