Smartcar Shield
Public Member Functions | List of all members
GY50 Class Reference

#include <GY50.hpp>

Inheritance diagram for GY50:
Inheritance graph
Collaboration diagram for GY50:
Collaboration graph

Public Member Functions

 GY50 (Runtime &runtime, int offset, unsigned long samplingInterval=smartcarlib::constants::gy50::kDefaultSamplingInterval)
 Constructs a GY50 gyroscope. More...
 
int getHeading () override
 Returns the current heading of the vehicle. More...
 
void update () override
 Updates the sensor's readings. More...
 
int getOffset (int measurements=smartcarlib::constants::gy50::kDefaultCalibrationMeasurements)
 Get the sensor's offset which is the value the sensor returns when still. More...
 
- Public Member Functions inherited from HeadingSensor
virtual ~HeadingSensor ()=default
 

Detailed Description

The class representing a GY-50 gyroscope module based on the L3G4200D sensor. This sensor allows you to get the current angular displacement, in degrees, since the beginning of the measurement in the range of [0,360). By the default setup, clockwise movement increases the degree count and counter-clockwise decreases them. If you have different set up (orientation of gyroscope) you will have to adapt accordingly. This method will measure the angular displacement (rotation) since the first GY50::update was called.

Always remember to use GY50::update in your main loop along with this method.

Definition at line 33 of file GY50.hpp.

Constructor & Destructor Documentation

◆ GY50()

GY50::GY50 ( Runtime runtime,
int  offset,
unsigned long  samplingInterval = smartcarlib::constants::gy50::kDefaultSamplingInterval 
)

Constructs a GY50 gyroscope.

Parameters
runtimeThe runtime environment you want to run the class for
offsetThe sensor-specific measurement value when idle. Find the value for your sensing with GY50::getOffset.
samplingIntervalHow often to upate the heading

Example:

ArduinoRuntime arduinoRuntime;
int offset = 37; // The offset we have acquired via the getOffset method
GY50 gyro(arduinoRuntime, offset);

Definition at line 21 of file GY50.cpp.

Member Function Documentation

◆ getHeading()

int GY50::getHeading ( )
overridevirtual

Returns the current heading of the vehicle.

Returns
The current heading of the vehicle in the range of [0-360)

Example:

sensor.getHeading();

Implements HeadingSensor.

Definition at line 31 of file GY50.cpp.

◆ getOffset()

int GY50::getOffset ( int  measurements = smartcarlib::constants::gy50::kDefaultCalibrationMeasurements)

Get the sensor's offset which is the value the sensor returns when still.

Parameters
measurementsThe amount of measurements to conduct to determine the offset
Returns
The sensor's offset

Example:

// Initialize it with any value, it does not play a role during calibration
GY50 gyro(0);
// Discover the offset and use it in the constructor next time
int offset = gyro.getOffset();

Definition at line 89 of file GY50.cpp.

Here is the call graph for this function:

◆ update()

void GY50::update ( )
overridevirtual

Updates the sensor's readings.

This method must be be able to be executed as often as possible.

Example:

void loop() {
sensor.update();
// More code
}

Implements HeadingSensor.

Definition at line 40 of file GY50.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
GY50
Definition: GY50.hpp:33
ArduinoRuntime
Definition: ArduinoRuntime.hpp:11