VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_gyro.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2017, All rights reserved. */
4/* */
5/* Module: vex_gyro.h */
6/* Author: James Pearman */
7/* Created: 7 July 2017 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_GYRO_CLASS_H
15#define VEX_GYRO_CLASS_H
16
17/*-----------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22/*-----------------------------------------------------------------------------*/
24/*-----------------------------------------------------------------------------*/
25namespace vex {
26 class gyro : public device {
27 public:
32 gyro( int32_t index, bool calibrate=false, turnType dir = turnType::left );
33 ~gyro();
34
35 bool installed();
36
41 int32_t value();
42
48 double value( rotationUnits units = rotationUnits::deg );
49
56 bool startCalibration( gyroCalibrationType value = gyroCalibrationType::calNormal, bool waitForCompletion=true );
57
58 void calibrate( gyroCalibrationType value = gyroCalibrationType::calNormal, bool waitForCompletion=true ) {
59 startCalibration( value, waitForCompletion );
60 }
61
67
72
77
83 void setHeading( double value, rotationUnits units );
84
90 void setRotation( double value, rotationUnits units );
91
97 double angle( rotationUnits units = rotationUnits::deg );
98
104 double heading( rotationUnits units = rotationUnits::deg );
105
111 double rotation( rotationUnits units = rotationUnits::deg );
112
118 double rate( rateUnits units = rateUnits::dps );
119
124 void changed( void (* callback)(void) );
125
130 void setTurnType( turnType dir );
131
136 turnType getTurnType();
137
138 private:
139 enum class tSensitivity {
140 low = 1, // 62.5 degrees per second
141 normal = 3, // 250 degrees per second
142 high = 6, // 2000 degrees per second
143 };
144
145 enum class tEventType {
146 EVENT_CHANGED = 2,
147 EVENT_POLL = 4
148 };
149
150 int32_t _absolute;
151 int32_t _value;
152 int32_t _offset_h;
153 int32_t _offset_r;
154 tSensitivity _sensitivity;
155 int32_t _rate;
156 bool _calInit;
157 uint8_t _mode;
158
159 void getAngleAndRate( void );
160 bool calibrationFlagGet( void );
161 void setSensitivity( tSensitivity s );
162 double rawToAngle( int32_t raw, rotationUnits units );
163 int32_t angleToRaw( double angle, rotationUnits units );
164 };
165};
166
167#endif // VEX_GYRO_CLASS_H
double angle(rotationUnits units=rotationUnits::deg)
Gets the angle of the gyro sensor.
void resetRotation()
reset the gyro sensor rotation to 0
double heading(rotationUnits units=rotationUnits::deg)
Gets the angle of the gyro sensor.
bool isCalibrating()
Returns true while the gyro sensor is performing a requested recalibration, changing to false once re...
void setRotation(double value, rotationUnits units)
set the gyro sensor rotation to angle
double rotation(rotationUnits units=rotationUnits::deg)
Gets the absolute angle of the gyro sensor.
turnType getTurnType()
Get direction for positive angles.
gyro(int32_t index, bool calibrate=false, turnType dir=turnType::left)
Creates a new gyro object on the port specified in the parameter.
void changed(void(*callback)(void))
Calls a function when the gyro sensor value changes.
bool startCalibration(gyroCalibrationType value=gyroCalibrationType::calNormal, bool waitForCompletion=true)
Starts recalibration of the gyro.
int32_t value()
Gets the angle of the gyro sensor.
double value(rotationUnits units=rotationUnits::deg)
Gets the angle of the gyro sensor.
void resetHeading()
reset the gyro sensor angle to 0
double rate(rateUnits units=rateUnits::dps)
Gets the turn rate of the gyro sensor.
void setHeading(double value, rotationUnits units)
set the gyro sensor angle to angle
void setTurnType(turnType dir)
Set direction for positive angles.
Bumper switch device class
Definition vex_brain.h:24