Case 11 - Self-Balancing Robot Simulation

Case 11 - Self-Balancing Robot Simulation

 

Part 1   Objective

After you compile the program, you can rotate the gyro sensor to simulate tilting to the left or right, to control the rotation of the motors to turn left or right.

40.gif

Part 2   Preparation

  • MegaPi x 1

  • MegaPi RJ25 adapter x 1

  • MegaPi encoder/DC motor driver x 2

  • Gyro sensor x 1

  • RJ25 cable x 1

  • Photoelectric encoder motor 185RPM with wheel x 2

  • Encoder motor cable x 2

  • Plastic wheel 90T x 2

  • USB cable (Type-B) x 1

  • Battery holder with 6 AA batteries x 1

  • Computer with network access x 1

Install the MegaPi RJ25 adapter and the MegaPi encoder/DC motor drivers on MegaPi, connect the gyro sensor to MegaPi by using the RJ25 cable, connect the encoder motors to MegaPi by using the encoder motor cables, connect the battery holder to MegaPi, connect MegaPi to the computer by using the USB cable, open mBlock 5 (PC client, web version, or mobile app), click +add, select Ultimate 2.0 from Device Library, click Connect, and select the Live mode.

41.gif
42.gif

Part 3   Programming

Self-balancing robot simulation: In Live mode, create 3 variables to detect the x-axis, y-axis and z-axis angles respectively, and then judge the deviation angle from the x-axis. When the deviation angle from the x-axis is less than minus 20 degrees, it indicates tilting to the right and the self-balancing robot turns right. When the deviation angle from the x-axis is larger than 20 degrees (the actual angle is affected by the installation position and angle of the gyro sensor), it indicates tilting to the left and the self-balancing robot turns left.

43.gif

Part 4   Practice

Try to use the gyro sensor to simulate tilting forward or backward to control the motors to run forward or backward.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.