In the WPI Robotics Library all sensors, motors, driver station elements, and more are all objects. For the
most part, objects correspond to the physical things on your robot. Objects include the code and the data
that makes the thing operate. Let’s look at a Gyro. There are a bunch of operations, or methods, you can
perform on a gyro:

• Create the gyro object – this sets up the gyro and causes it to initialize itself
• Get the current heading, or angle, from the gyro
• Set the type of the gyro, i.e. its Sensitivity
• Reset the current heading to zero
• Delete the gyro object when you’re done using it
Creating a gyro object is done like this:

Gyro robotHeadingGyro(1);

robotHeadingGyro is a variable that holds the Gyro object that represents a gyro module connected to
analog port 1. That’s all you have to do to make an instance of a Gyro object.
Note: by the way, an instance of an object is the chunk of memory that holds the data
unique to that object. When you create an object that memory is allocated and
when you delete the object that memory is deallocated.

To get the current heading from the gyro, you simply call the GetAngle method on the gyro object.
Calling the method is really just calling a function that works on the data specific to that gyro instance.
float heading = robotHeadingGyro.GetAngle();

This sets the variable heading to the current heading of the gyro connected to analog channel 1.



Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates