How to use gyroscope

From cod3v
Other languages:
English • ‎suomi

Introduction

The gyroscope is very powerful tool in navigation. The gyroscope is similar to a compass, and it gives the angle with respect to robot orientation at the reset. The gyroscope can be used to steer the correct amount, or to drive straight at given angle. These gyroscope algorithms are proportional, but it is easy to implement with e.g. the PID algorihm, too.

The gyroscope driving functions should be done as MyBlock so that they are easy to use at your own codes.

We show two different methods, (i) the robot drives straights, and (ii) the robot steers to a given angle.

Robot

Almost any robot will do, though these examples are done by using Verne/ Asimov 2.

Sensors

The gyroscope sensor is used.

Example Videos

The two different methods are shown.

Theory

The limitations of gyroscope sensor should be known. E.g. the magnetic field affects the sensor values. Also, the sensor should be exactly still while starting the sensor. Otherwise, it might start drifting. If the sensor starts drifting, the easiest method to make it work properly is to unplug and plug the sensor again. Usually it works on the first replugging.


Example Code

The first example code explains the resetting, and how to use proportional algorithm to drive straight. The second code employs the proportional algorithm to follow a given compass direction.


The gyro drives to 0 degrees.
The MyBlock version of gyro program to drive the given angle.

Exercises

  • Make the robot to always turn the shorter distance.
  • Make the robot to always turn the longer distance.
  • Use the Modulo operator to fix the number of turns the robot makes during the drive.
  • Make a MyBlock that drives, and turns the robot as LEGOs steering block, but while using the gyro sensor.


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

MeetAndcodeLogo.png

Back to Meet_and_Code_2020_I:_Ev3-G