Driving straight using gyroscope (Lego Dance)

From cod3v

Introduction

We create a simple code with gyroscope to drive a straight line. Sometimes starting the gyroscope fails and it starts drifting. Fix it by unplugging and plugging the cable.

Theory

The plan:

The plan

Robot drives a straight line perpendicular to its starting position. If the robot for some reason goes to different direction, the gyroscope will fix the direction. However, the final position might be different.

The code:

The code

We use loop (orange) with gyroscope (yellow) block, math add block (red) and steering (green) block. This is called as a proportional control system, P-controller.

Exercises

  1. Drive a longer distance.
  2. Add small obstacles, eg a mat or small LEGO building on the driveway to disturb the robot.
  3. What is the meaning of b in math block? Try with different values.
  4. Drive a square by creating similar Drive Straight code blocks one by one. Use gyro reset in between.

References

See the detailed instructions made by Robotiikka- ja tiedekasvatus ry here.

The Instructors

The course is held in Finnish, though English guidance is possible. The instructors are Markku Leino and Zwenkka Pietilä.

This course is supported by Meet and Code. The course is made in collaboration with Robotiikka- ja tiedekasvatus ry.