inercial#
Inicializando la clase inercial#
Un sensor inercial se crea utilizando el siguiente constructor:
The inertial
constructor creates an inertial object using the EXP Brain’s internal Inertial Sensor.
Parámetro |
Descripción |
---|---|
director |
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.
Parámetro |
Descripción |
---|---|
|
Un Puerto inteligente válido al que está conectado el sensor inercial. |
director |
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.
Métodos de clase#
calibrate()#
El sensor giroscópico o inercial ajustará automáticamente sus valores dependiendo de la orientación del EXP Brain durante la calibración para que permanezca consistente en todas las posibles orientaciones del EXP Brain.
Este método se llama de las siguientes maneras:
The calibrate()
method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.
Devoluciones: Ninguna.
// Start calibration.
Inertial.calibrate();
The calibrate(value)
method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.
Parámetros |
Descripción |
---|---|
valor |
Establece el tiempo de calibración. El valor predeterminado es 0. |
Devoluciones: Ninguna.
// 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.
Devoluciones: Ninguna.
setHeading()#
The setHeading(value, units)
method sets the heading of the Inertial Sensor to a specified value.
Parámetros |
Descripción |
---|---|
valor |
El valor del encabezado a establecer. |
unidades |
Una rotationUnit válida. |
Devoluciones: Ninguna.
// 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.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit. The default is |
Devuelve: Un doble que representa el rumbo actual del sensor inercial en las unidades especificadas.
// 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.
Devoluciones: Ninguna.
setRotation()#
The setRotation(value, units)
method sets the rotation of the Inertial Sensor to a specified value.
Parámetros |
Descripción |
---|---|
valor |
El valor de rotación a establecer. |
unidades |
Una rotationUnit válida. |
Devoluciones: Ninguna.
// 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.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit. The default is |
Devuelve: Un doble que representa la rotación actual del sensor inercial en las unidades especificadas.
// 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.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit. The default is |
Devuelve: Un doble que representa el ángulo actual del sensor inercial en las unidades especificadas.
// 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.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit. The default is |
Devuelve: Un doble que representa el valor de balanceo del sensor inercial.
pitch()#
The pitch(units)
method returns the roll angle of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit. The default is |
Devuelve: Un doble que representa el valor de paso del sensor inercial.
yaw()#
The yaw(units)
method returns the yaw angle of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
unidades |
A valid rotationUnit. The default is |
Devuelve: Un doble que representa el valor de guiñada del sensor inercial.
orientation()#
The orientation(axis, units)
method returns the orientation for one axis of the Inertial Sensor.
Parámetros |
Descripción |
---|---|
eje |
Un axisType válido. |
unidades |
Una rotationUnit válida. |
Devuelve: Un doble que representa el valor de la orientación del eje en las unidades especificadas.
// 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.
Parámetros |
Descripción |
---|---|
eje |
Un axisType válido. |
unidades |
Una velocityUnit válida. |
Devuelve: Un doble que representa el valor de la velocidad del giroscopio del eje en las unidades especificadas.
// 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.
Parámetros |
Descripción |
---|---|
eje |
Un axisType válido. |
Devuelve: Un doble que representa el valor de la aceleración del eje en unidades de gravedad.
// 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.
Parámetros |
Descripción |
---|---|
llamar de vuelta |
La función de devolución de llamada que se llamará cuando cambie el rumbo del sensor inercial. |
Devuelve: Una instancia de la clase Event.
// 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.
Parámetros |
Descripción |
---|---|
eje |
Un axisType válido. |
incógnita |
Un doble para los valores de aceleración para el eje x. |
y |
Un doble para los valores de aceleración para el eje y. |
z |
Un doble para los valores de aceleración para el eje z. |
Devuelve: Una instancia de la clase Event.
timestamp()#
The timestamp()
method requests the timestamp of the last received status packet from the Inertial Sensor.
Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.
installed()#
The installed()
method returns if the Inertial Sensor is installed.
Returns: true
if the Inertial Sensor is installed. false
if it is not.