inertial#
Initializing the inertial Class#
An Inertial Sensor is created by using the following constructor:
The inertial
constructor creates an inertial object using the EXP Brain’s internal Inertial Sensor.
Parameter |
Description |
---|---|
dir |
The directionType which corresponds to a positive heading value. The default is |
// Create a new object "Inertial" with the
// inertial class.
inertial Inertial = inertial();
The inertial(port, dir)
constructor creates an inertial object using the EXP Brain’s internal Inertial Sensor.
Parameter |
Description |
---|---|
|
A valid Smart Port that the Inertial Sensor is connected to. |
dir |
The directionType which corresponds to a positive heading value. The default is |
// Construct a Inertial Sensor "Inertial" with the
// inertial class.
inertial Inertial = inertial(PORT1);
This Inertial
object will be used in all subsequent examples throughout this API documentation when referring to inertial class methods.
Class Methods#
calibrate()#
This method is called in the following ways:
The calibrate()
method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving.
Returns: None.
// Start calibration.
Inertial.calibrate();
The calibrate(value)
method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving.
Parameters |
Description |
---|---|
value |
Sets the amount of calibration time. The default is 0. |
Returns: None.
// Start calibration with the calibration time set to 3 seconds.
Inertial.calibrate(3);
isCalibrating()#
The isCalibrating()
method checks if the Inertial Sensor is currently calibrating.
Returns: true
if the Inertial Sensor is calibrating. false
if it is not.
// Start calibration.
Inertial.calibrate();
// Print that the Inertial Sensor is calibrating while
// waiting for it to finish calibrating.
while(Inertial.isCalibrating()){
Brain.Screen.clear();
Brain.Screen.print("Inertial Calibrating");
wait(50, msec);
}
resetHeading()#
The resetHeading()
method resets the heading of the Inertial Sensor to 0.
Returns: None.
setHeading()#
The setHeading(value, units)
method sets the heading of the Inertial Sensor to a specified value.
Parameters |
Description |
---|---|
value |
The heading value to set. |
units |
A valid RotationUnit. |
Returns: None.
// Set the Inertial Sensor's heading to 180 degrees.
Inertial.setHeading(180);
heading()#
The heading(units)
method returns the current heading of the Inertial Sensor.
Parameters |
Description |
---|---|
units |
A valid RotationUnit. The default is |
Returns: A double representing the current heading of the Inertial Sensor in the specified units.
// Get the current heading for the Inertial Sensor.
double value = Inertial.heading();
resetRotation()#
The resetRotation()
method resets the rotation of the Inertial Sensor to 0.
Returns: None.
setRotation()#
The setRotation(value, units)
method sets the rotation of the Inertial Sensor to a specified value.
Parameters |
Description |
---|---|
value |
The rotation value to set. |
units |
A valid RotationUnit. |
Returns: None.
// Set the Inertial Sensor's rotation to 180 degrees.
Inertial.setRotation(180);
rotation()#
The rotation(units)
method returns the current rotation of the Inertial Sensor.
Parameters |
Description |
---|---|
units |
A valid RotationUnit. The default is |
Returns: A double representing the current rotation of the Inertial Sensor in the specified units.
// Get the current rotation for the Inertial Sensor.
double value = Inertial.rotation();
angle()#
The angle(units)
method returns the current angle of the Inertial Sensor.
Parameters |
Description |
---|---|
units |
A valid RotationUnit. The default is |
Returns: A double representing the current angle of the Inertial Sensor in the specified units.
// Get the current angle for the Inertial Sensor.
double value = Inertial.angle();
roll()#
The roll(units)
method returns the roll angle of the Inertial Sensor.
Parameters |
Description |
---|---|
units |
A valid RotationUnit. The default is |
Returns: A double representing the roll value of the Inertial Sensor.
pitch()#
The pitch(units)
method returns the roll angle of the Inertial Sensor.
Parameters |
Description |
---|---|
units |
A valid RotationUnit. The default is |
Returns: A double representing the pitch value of the Inertial Sensor.
yaw()#
The yaw(units)
method returns the yaw angle of the Inertial Sensor.
Parameters |
Description |
---|---|
units |
A valid RotationUnit. The default is |
Returns: A double representing the yaw value of the Inertial Sensor.
orientation()#
The orientation(axis, units)
method returns the orientation for one axis of the Inertial Sensor.
Parameters |
Description |
---|---|
axis |
A valid AxisType. |
units |
A valid RotationUnit. |
Returns: A double representing the value for the axis orientation in the units specified.
// Get the orientation value for the X axis of the
// Inertial Sensor.
double orient = Inertial.orientation(xaxis);
gyroRate()#
The gyroRate(axis, units)
method returns the gyro rate for one axis of the Inertial Sensor.
Parameters |
Description |
---|---|
axis |
A valid AxisType. |
units |
A valid VelocityUnit. |
Returns: A double representing the value for the gyro rate of the axis in the units specified.
// Get the gyro rate for the Z axis of the Inertial Sensor.
double zrate = Inertial.gyroRate(zaxis);
acceleration()#
The acceleration(axis)
method returns the acceleration of a specific axis of the Inertial Sensor.
Parameters |
Description |
---|---|
axis |
A valid AxisType. |
Returns: A double representing the value for the acceleration of the axis in units of gravity.
// Get the acceleration for the Z axis of the
// Inertial Sensor.
double accel = Inertial.acceleration(zaxis);
// Print the value of the current acceleration of the z-axis
// of the Inertial Sensor to the Brain's screen.
Brain.Screen.print(accel);
changed()#
The changed(callback)
method registers a callback function for when the Inertial Sensor heading changes.
Parameters |
Description |
---|---|
callback |
The callback function to be called when the Inertial Sensor heading changes. |
Returns: An instance of the Event class.
// Define the inertialChanged function with a void return
// type, showing it doesn't return a value.
void inertialChanged() {
// The brain will print that the Inertial Sensor changed
// on the Brain's screen.
Brain.Screen.print("accelerometer changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn the robot right.
Drivetrain.turn(right);
// Run inertialChanged when the value of the
// Inertial Sensor changes.
Inertial.changed(inertialChanged);
}
collision()#
The collision(axis, x, y, z)
method registers a callback function for when the Inertial Sensor detects a collision.
Parameters |
Description |
---|---|
axis |
A valid AxisType. |
x |
A double for the acceleration values for the x axis. |
y |
A double for the acceleration values for the y axis. |
z |
A double for the acceleration values for the z axis. |
Returns: An instance of the Event class.
timestamp()#
The timestamp()
method requests the timestamp of the last received status packet from the Inertial Sensor.
Returns: Timestamp of the last status packet as an unsigned 32-bit integer in milliseconds.
installed()#
The installed()
method returns if the Inertial Sensor is installed.
Returns: true
if the Inertial Sensor is installed. false
if it is not.