EV3RT CXX API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
GyroSensor Class Reference

Class GyroSensor. API for working with gyro sensor. More...

#include <ev3cxx_gyro_sensor.h>

Inheritance diagram for GyroSensor:
Sensor

Public Member Functions

 GyroSensor (SensorPort port)
 Constructor of class GyroSensor. More...
 
int angle ()
 Get angle in degrees from gyro. More...
 
int rate ()
 Get angular speed from gyro. Speed = degrees per seconde. More...
 
void reset ()
 Reset gyro. More...
 
void resetHard ()
 Hard reset gyro. Solve the problem with drifting value after standard reset(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from Sensor
 Sensor (SensorPort port, sensor_type_t type)
 Constructor of class Sensor. More...
 
virtual ~Sensor ()
 Destructor of class Sensor.
 
sensor_port_t getPort ()
 Get sensor port set in constructor. More...
 
sensor_type_t getType ()
 Get actual sensor type. More...
 
- Protected Attributes inherited from Sensor
sensor_port_t m_port
 
sensor_type_t m_type
 

Detailed Description

Class GyroSensor. API for working with gyro sensor.

Definition at line 20 of file ev3cxx_gyro_sensor.h.

Constructor & Destructor Documentation

◆ GyroSensor()

GyroSensor ( SensorPort  port)
inline

Constructor of class GyroSensor.

Parameters
portPort index (1-4).

Definition at line 28 of file ev3cxx_gyro_sensor.h.

References GyroSensor::resetHard().

28  : Sensor(port, GYRO_SENSOR) {
29  resetHard();
30  }
Sensor(SensorPort port, sensor_type_t type)
Constructor of class Sensor.
Definition: ev3cxx_sensor.h:38
void resetHard()
Hard reset gyro. Solve the problem with drifting value after standard reset().

Member Function Documentation

◆ angle()

int angle ( )
inline

Get angle in degrees from gyro.

Not recommended use angle() and rate() in same time => call rate() reset initial position in angle().

Returns
Number of degrees of robot rotation from initial position. Range: from -32768 to 32767 (after overflow, the value goes to the opposite range: +32767 +1 => -32768)

Definition at line 39 of file ev3cxx_gyro_sensor.h.

Referenced by GyroSensor::resetHard().

39  {
40  return ev3_gyro_sensor_get_angle(m_port);
41  }

◆ rate()

int rate ( )
inline

Get angular speed from gyro. Speed = degrees per seconde.

Not recommended use angle() and rate() in same time => call rate() reset initial position in angle().

Returns
Range: 0 - 100

Definition at line 49 of file ev3cxx_gyro_sensor.h.

Referenced by GyroSensor::resetHard().

49  {
50  return ev3_gyro_sensor_get_rate(m_port);
51  }

◆ reset()

void reset ( )
inline

Reset gyro.

Set the zero value on gyro when the robot not move => affect the angle() and rate() values Doesn't work everytime: https://bricks.stackexchange.com/questions/7115/how-can-ev3-gyro-sensor-drift-be-handled Then you need resetHard().

Definition at line 60 of file ev3cxx_gyro_sensor.h.

Referenced by GyroSensor::resetHard().

60  {
61  ev3_gyro_sensor_reset(m_port);
62  }

◆ resetHard()

void resetHard ( )
inline

Hard reset gyro. Solve the problem with drifting value after standard reset().

Set firstly gyro to one mode (angle) => then reset() => second mode (rate) => reset() => first mode (angle)

Definition at line 69 of file ev3cxx_gyro_sensor.h.

References GyroSensor::angle(), GyroSensor::rate(), and GyroSensor::reset().

Referenced by GyroSensor::GyroSensor().

69  {
70  angle();
71  reset();
72  rate();
73  reset();
74  angle();
75  }
void reset()
Reset gyro.
int angle()
Get angle in degrees from gyro.
int rate()
Get angular speed from gyro. Speed = degrees per seconde.