motor#
Inicializando la clase del motor#
Un motor EXP se puede instanciar de diferentes maneras utilizando uno de los siguientes constructores:
This motor constructor creates a motor object with gears defaulting to ratio18_1.
Parámetro |
Descripción |
|---|---|
|
The |
|
A boolean value to reverse the direction the Motor spins forward in. The default is |
// Construct a Motor connected to Port 1 which runs
// in reverse.
motor Motor1 = motor(PORT1, true);
This motor constructor creates a motor object with reverse defaulting to false.
Parámetro |
Descripción |
|---|---|
|
The |
|
The |
// Construct a Motor connected to Port 1 with a 6:1
// High Speed Motor Cartridge.
motor Motor1 = motor(PORT1, ratio6_1);
This motor constructor creates a motor object with no default parameter values.
Parámetro |
Descripción |
|---|---|
|
The |
|
The |
|
Un valor booleano para invertir la dirección en la que el motor gira hacia adelante. |
// Construct an EXP Motor with a 36:1 Torque Gear Cartridge
// that runs in reverse.
motor Motor1 = motor(PORT1, ratio36_1, true);
This Motor1 object will be used in all subsequent examples throughout this API documentation when referring to motor class methods.
Métodos de clase#
spin()#
Esta es una función sin espera y permite que el siguiente comando se ejecute sin demora.
Este método se llama de las siguientes maneras:
The spin(dir) command is used to spin a Motor in the specified direction forever at the default velocity set by the setVelocity() command, until a spin or stop command is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
// Spin Motor1 forward.
Motor1.spin(forward);
The spin(dir, velocity, units) command is used to spin a Motor in the specified direction forever at a specified velocity until a spin or stop command is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
La velocidad a la que girará el motor. |
|
A valid |
Devoluciones: Ninguna.
// Spin Motor1 forward at 100 rpm.
Motor1.spin(forward, 100, rpm);
The spin(dir, voltage, units) command is used to spin a Motor in the specified direction forever at a specified voltage until a spin or stop command is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
El voltaje al que girará el motor. |
|
A valid |
Devoluciones: Ninguna.
// Spin Motor1 forward at 100 millivolts.
Motor1.spin(forward, 100, voltageUnits::mV);
spinToPosition()#
This function can be a waiting or non-waiting command depending on if the waitForCompletion parameter is used.
Este método se llama de las siguientes maneras:
The spinToPosition(rotation, units, waitForCompletion) command is used to spin a Motor to an absolute rotation in the specified units.
Parámetros |
Descripción |
|---|---|
|
La posición a la que debe girar el motor. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 to the absolute position 1080 degrees.
Motor1.spinToPosition(1080, degrees);
The spinToPosition(rotation, units, velocity, units_v, waitForCompletion) command is used to spin a Motor to an absolute rotation in the specified units.
Parámetros |
Descripción |
|---|---|
|
La posición a la que debe girar el motor. |
|
A valid |
|
La velocidad con la que girará el motor. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 to the absolute position 1080 degrees
// at 100 percent velocity.
Motor1.spinToPosition(1080, degrees, 100, percent);
spinFor()#
This can be a waiting or non-waiting command depending on if the waitForCompletion parameter is used.
Este método se llama de las siguientes maneras:
The spinFor(time, units) command is used to spin the Motor for a specified duration.
Parámetros |
Descripción |
|---|---|
|
La cantidad de tiempo durante el cual debe girar el motor. |
|
A valid |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 for 10 seconds
Motor1.spinFor(10, seconds);
The spinFor(dir, time, units) command is used to spin the Motor for a specified duration in a specified direction.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
La cantidad de tiempo durante el cual debe girar el motor. |
|
A valid |
// Spin Motor1 forward for 10 seconds
Motor1.spinFor(forward, 10, seconds);
The spinFor(time, units, velocity, units_v) command is used to spin the Motor for a specified duration at a specified velocity.
Parámetros |
Descripción |
|---|---|
|
La cantidad de tiempo durante el cual debe girar el motor. |
|
A valid |
|
La velocidad con la que girará el motor. |
|
A valid |
// Spin Motor1 for 10 seconds at 100 rpm.
Motor1.spinFor(10, seconds, 100, rpm);
The spinFor(dir, time, units, velocity, units_v) command is used to spin the Motor for a specified duration at a specified velocity in a specified direction.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
La cantidad de tiempo durante el cual debe girar el motor. |
|
A valid |
|
La velocidad con la que girará el motor. |
|
A valid |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 forward for 10 seconds at 100 rpm.
Motor1.spinFor(forward, 10, seconds, 100, rpm);
The spinFor(rotation, units, waitForCompletion) command is used to spin the Motor for a specific rotation. The rotation is relative to the current rotation of the Motor.
Parámetros |
Descripción |
|---|---|
|
El valor de rotación que debe girar el motor. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 for 1000 degrees.
Motor1.spinFor(1000, degrees);
The spinFor(dir, rotation, units, waitForCompletion) command is used to spin the Motor for a specific rotation in a specific direction. The rotation is relative to the current rotation of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
El valor de rotación que debe girar el motor. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 forward for 1000 degrees.
Motor1.spinFor(forward, 1000, degrees);
The spinFor(rotation, units, velocity, units_v, waitForCompletion) command is used to spin the Motor for a specific rotation. The rotation is relative to the current rotation of the Motor.
Parámetros |
Descripción |
|---|---|
|
El valor de rotación para que gire el motor. |
|
A valid |
|
La velocidad con la que girará el motor. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 for 1000 degrees at 25 rpm.
Motor1.spinFor(1000, degrees, 25, rpm);
The spinFor(dir, rotation, units, velocity, units_v, waitForCompletion) command is used to spin the Motor for a specific rotation in a specific direction. The rotation is relative to the current rotation of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
El valor de rotación que debe girar el motor. |
|
A valid |
|
La velocidad con la que girará el motor. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el motor ha alcanzado la rotación objetivo.
// Spin Motor1 forard for 1000 degrees at 25 rpm.
Motor1.spinFor(forward, 1000, degrees, 25, rpm);
stop()#
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Este método se llama de las siguientes maneras:
The stop() command is used to stop a Motor, setting the Motor to 0 velocity and configuring the current stopping mode. The default Brake Type is coast, unless previously changed using the setStopping() command.
Devoluciones: Ninguna.
// Spin Motor1 for 2.5 seconds.
Motor1.spin(forward);
wait(2.5 seconds);
// Stop Motor1.
Motor1.stop();
The stop(mode) command is used to stop a Motor using a specific Brake Type.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
// Spin Motor1 for 2.5 seconds.
Motor1.spin(forward);
wait(2.5 seconds);
// Stop Motor1 using the hold Brake Type.
Motor1.stop(hold);
setVelocity()#
The setVelocity(velocity, units) command is used to set the default velocity for a Motor. This velocity setting will be used for subsequent calls to any motion functions if a specific velocity is not provided.
Parámetros |
Descripción |
|---|---|
|
La nueva velocidad a establecer para el motor. |
|
A valid |
Devoluciones: Ninguna.
setReversed()#
The setReversed(value) command sets the Motor direction to be reversed. Constructing a Motor with the reverse parameter set to true has the same result as Motor1.setReversed(true).
Parámetros |
Descripción |
|---|---|
|
Un valor booleano para establecer si la dirección del motor se invierte o no. |
Devoluciones: Ninguna.
setStopping()#
The setStopping(mode) command is used to set the stopping mode for a Motor. This will be the stopping mode used when the stop() command is called.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
resetPosition()#
The resetPosition() command resets the Motor’s encoder value to 0.
Devoluciones: Ninguna.
setPosition()#
The setPosition(value, units) command is used to set the value of a Motor’s encoder to a specific value. The position that is returned by the position() command will be updated to this new value.
Parámetros |
Descripción |
|---|---|
|
La nueva posición que debe establecerse para el codificador del motor. |
|
A valid |
Devoluciones: Ninguna.
setTimeout()#
The setTimeout(value, units) command is used to set the timeout for motor commands. If a Motor does not reach its’ commanded position prior to the completion of the timeout, the Motor will stop.
Parámetros |
Descripción |
|---|---|
|
El nuevo tiempo de espera que se debe establecer para el motor. |
|
A valid |
Devoluciones: Ninguna.
isSpinning()#
The isSpinning() command returns if the Motor is currently rotating to a specific target.
Returns: true if the Motor is on and is rotating to a target. false if it is done rotating to a target.
isDone()#
The isDone() command returns if the Motor is done rotating to a specific target.
Returns: true if the Motor is done rotating to a target. false if it is on and rotating to a target.
setMaxTorque()#
Este método se llama de las siguientes maneras:
The setMaxTorque(value, units) command is used to set the maximum torque for a Motor.
Parámetros |
Descripción |
|---|---|
|
El nuevo par máximo para un motor. |
|
A valid |
Devoluciones: Ninguna.
// Set maximum torque to 2 Newton Meters.
Motor1.set_max_torque(2, Nm);
The setMaxTorque(value, units) command is used to set the maximum torque for a Motor.
Parámetros |
Descripción |
|---|---|
|
El nuevo par máximo para un motor. |
|
The only valid unit is |
Devoluciones: Ninguna.
// Set maximum torque to ,05 amps.
Motor1.set_max_torque(.05, amp);
The setMaxTorque(value, units) command is used to set the maximum torque for a Motor as a percentage.
Parámetros |
Descripción |
|---|---|
|
El nuevo par máximo para un motor. |
|
The only valid unit is |
Devoluciones: Ninguna.
// Set maximum torque to 75 percent.
Motor1.set_max_torque(75, percent);
convertVelocity()#
The convertVelocity(velocity, units, unitsout) command converts the velocity in the given units to the given output units based on the Motor gearing.
Parámetros |
Descripción |
|---|---|
|
La velocidad a convertir. |
|
A valid |
|
A valid |
Devuelve: Un doble que representa la velocidad convertida a las unidades de salida especificadas.
getMotorCartridge()#
The getMotorCartridge() command returns the gear cartridge setting for the Motor.
Devoluciones: La configuración del cartucho de engranaje del motor.
direction()#
The direction() command returns the current direction the Motor is spinning in as a directionType.
Returns: A directionType value representing current direction that the Motor is spinning in.
position()#
The position(units) command returns the current rotation of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa la rotación actual del motor en las unidades especificadas.
velocity()#
The velocity(units) command returns the current velocity of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa la velocidad actual del motor en las unidades especificadas.
current()#
The current(units) command returns the current being used by the Motor.
Parámetros |
Descripción |
|---|---|
|
The only valid units for current are |
Devuelve: Un doble que representa la corriente consumida por el motor en las unidades especificadas.
voltage()#
The voltage(units) command returns the electrical voltage of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa el voltaje eléctrico del motor en las unidades especificadas.
power()#
The power(units) command returns the power being consumed by the Motor.
Parámetros |
Descripción |
|---|---|
|
The only valid unit for power is |
Devuelve: Un doble que representa la potencia actual del motor en las unidades especificadas.
torque()#
The torque(units) command returns the torque of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: El torque del motor en las unidades especificadas.
efficiency()#
The efficiency(units) command returns the efficiency of the Motor.
Parámetros |
Descripción |
|---|---|
|
The only valid unit for efficiency is |
Devuelve: La eficiencia del motor como porcentaje.
temperature()#
The temperature(units) command returns the current temperature of the Motor.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: La temperatura actual del motor en las unidades especificadas.
installed()#
The installed() command returns if the Motor is connected to the EXP Brain.
Returns: true if the Motor is connected to the EXP Brain. false if it is not.