Checking signs and calibrating the encoders.


We will check the signs of the wheel rotation as measured by the encoders and the motor drivers, and then calibrate the encoders.


Use the program test_picoencoder to see if the encoder readings increase as the wheels rotate in such a way as to move the robot forward. The front of the robot has the plastic piece sticking out. The three rows of pins on the controller board should point to the rear of the robot.

If the signs are not correct, flip the signs in the code below found in test_picoencoder.ino, and in any subsequent code provided.

// forward is positive rotation
int left_position = -left_encoder.position; // change this to + to flip
int right_position = +right_encoder.position; // change this to - to flip
Then, after putting a piece of tape on each wheel and putting an edge of that tape vertical, rotate each wheel forward exactly one turn, and see what increment you get. If it is close to 84480 = 11 (counts/revolution) * 4 (quadrature pulse counting) * 30 (gear ratio) * 64 (multiplier used in PicoEncoder), you have an 11 count encoder on the motor, and the full revolution (2*pi radians) should be 84480 counts. If it is close to 99840, or some other value off by 10,000 let the TA know. You may have a 13 counts/revolution encoder. The Tumbller originally came with the 13 count encoder, but Tumbllers sold after November 2024 seem to have 11 count encoders.


Using the program test_motor to make sure the wheels rotate in such a way as to move the robot forward. If not, change:
motor_left_command( command );
motor_right_command( command );
to
motor_left_command( -command );
motor_right_command( -command );
in test_motor.ino, and any subsequent code provided.


Make sure your battery is on for this.

See section on Phase calibration on the PicoEncoder Github page for an explanation of calibrating the phases of the encoder. The relative sizes of the phases is represented by 4 numbers. A perfectly symmetric set of phases would have the numbers 64, 64, 64, 64, or 0x40404040 in hex if these numbers are combined in 8 bytes. Since the sum of the numbers is 256, we only have to represent 3 of them: 64, 64, 64, or 0x404040 in hex, or 4210752 in decimal. The program calibrate_encoders runs a calibration program to estimate the phases every time you type g, and averages the results. I run it at least 10 times for good luck: Make sure the battery is on, and the voltage printed out is over 8. Note that the voltage is lower after each test, and then rises again.

calibrate_encoders
motor_init done.
Initialized encoders
Wheels should be off the ground.
Type g  to run test, s  to stop.
Typing window is at the top of the Arduino serial monitor window.
Type into the main window of a Putty serial monitor window.
Current voltage 8.34 1367.00
Left encoder phases: 5002768, 0x4C5610, 78, 76, 86, 16
Right encoder phases: 5326873, 0x514819, 78, 81, 72, 25
Calibration 1 done.
Current voltage 8.23 1349.00
Go!
Current voltage 8.30 1361.00
Left encoder phases: 5002768, 0x4C5610, 78, 76, 86, 16
Right encoder phases: 5457689, 0x534719, 77, 83, 71, 25
Calibration 2 done.
Current voltage 8.31 1362.00
Go!
Current voltage 8.33 1366.00
Left encoder phases: 4937488, 0x4B5710, 78, 75, 87, 16
Right encoder phases: 5523480, 0x544818, 76, 84, 72, 24
Calibration 3 done.
Current voltage 8.30 1361.00
	...
Go!
Current voltage 8.31 1363.00
Left encoder phases: 4937488, 0x4B5710, 78, 75, 87, 16
Right encoder phases: 5457689, 0x534719, 77, 83, 71, 25
Calibration 19 done.
Current voltage 8.17 1339.00
Go!
Current voltage 8.30 1361.00
Left encoder phases: 4937488, 0x4B5710, 78, 75, 87, 16
Right encoder phases: 5457689, 0x534719, 77, 83, 71, 25
Calibration 20 done.
Current voltage 8.22 1347.00
These numbers are then inserted into any subsequent code provided as:
left_encoder.setPhases( 0x4B5710 );
right_encoder.setPhases( 0x534719 );
You can enter the decimal number instead of the hex number if you prefer, it doesn't make any difference.