motor#
Para que los comandos del motor aparezcan en VEXcode V5, se debe configurar un motor en la ventana Dispositivos.
Para obtener más información, consulte estos artículos:
Constructor de motores#
Un motor V5 se puede instanciar de diferentes maneras utilizando uno de los siguientes constructores:
motor Motor1 = motor(int32_t índice, bool inverso);
index
= the SmartPort the Motor is connected to.reverse
= a boolean to keep or reverse the direction the motor spins.
motor Motor1 = motor(int32_t índice, engranajeAjuste engranajes);
index
= the SmartPort the Motor is connected to.gears
= the gear ratio of the Motor Cartridge.
motor Motor1 = motor(int32_t índice, gearSetting engranajes, bool revertir);
index
= the SmartPort the Motor is connected to.gears
= the gear ratio of the Motor Cartridge.reverse
= a boolean to keep or reverse the direction the motor spins.
// Construct a V5 Motor that runs in reverse.
motor Motor1 = motor(PORT1, true);
// Construct a V5 Motor with a 6:1 Turbo Gear Cartridge.
motor Motor1 = motor(PORT1, ratio6_1);
// Construct a V5 Motor with a 36:1 Torque Gear Cartridge
// that runs in reverse.
motor Motor1 = motor(PORT1, ratio36_1, true);
Motor.spin()#
The Motor.spin(direction, velocity, units)
command is used to spin a Motor in the specified direction forever, until another motion command is used, or the project is stopped.
To use this command, replace Motor
with the desired Motor, for example: armMotor.spin(direction, velocity, units)
.
Esta es una función sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
dirección |
Un directionType válido. |
velocidad |
Optional. The velocity at which the Motor will spin. The default velocity set by the |
unidades |
Optional. A valid velocityUnit. The default is |
Devoluciones: Ninguna.
// Spin Motor forward.
Motor1.spin(forward);
Motor.spinToPosition()#
The Motor.spinToPosition(rotation, units, velocity, units_v, wait)
command is used to spin a Motor to an absolute position using the provided arguments.
To use this command, replace Motor
with the desired Motor, for example: armMotor.spinToPosition(rotation, units, velocity, units_v, wait)
.
This function can be a waiting or non-waiting command depending on if the wait
parameter is used.
Parámetros |
Descripción |
---|---|
rotación |
La posición a la que debe girar el motor. |
unidades |
Optional. A valid rotationUnit. The default is |
velocidad |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
unidades_v |
Optional. A valid velocityUnit. The default is |
esperar |
Optional. Determines whether the command will block subsequent commands ( |
Devoluciones: Ninguna.
// Spin Motor to 180 degrees.
Motor1.spinToPosition(180);
Motor.spinFor()#
The Motor.spinFor(direction, value, units, velocity, units_v, wait)
command is used to spin the Motor for a specific duration, rotations, or until a specific encoder value is reached. The position is relative to the current position of the Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.spinFor(direction, value, units, velocity, units_v, wait)
.
This can be a waiting or non-waiting command depending on if the wait
parameter is used.
Parámetros |
Descripción |
---|---|
dirección |
Un directionType válido. |
valor |
El valor al que debe girar el motor. |
unidades |
Optional. A valid rotationUnit. The default is |
velocidad |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
unidades_v |
Optional. A valid velocityUnit. The default is |
esperar |
Optional. Determines whether the command will block subsequent commands ( |
Devoluciones: Ninguna.
// Spin 180 degrees from the current position.
Motor1.spinFor(forward, 180);
Motor.stop()#
The Motor.stop(mode)
command is used to stop a Motor, setting them to 0 velocity and configuring the current stopping mode.
To use this command, replace Motor
with the desired Motor, for example: armMotor.stop(mode)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
modo |
Optional. A valid brakeType. The default is |
Devoluciones: Ninguna.
// Stop the Motor.
Motor.stop();
Motor.setVelocity()#
The Motor.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.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setVelocity(velocity, units)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
velocidad |
La nueva velocidad a establecer para el motor. |
unidades |
Optional. A valid velocityUnit. The default is |
Devoluciones: Ninguna.
Motor.setReversed()#
The Motor.setReversed(value)
command sets the Motor direction to be reversed.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
valor |
Valor booleano para establecer la dirección invertida o no. |
Devoluciones: Ninguna.
Motor.setStopping()#
The Motor.setStopping(mode)
command is used to set the stopping mode for a Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setStopping(mode)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
modo |
Optional. A valid brakeType. The default is |
Devoluciones: Ninguna.
Motor.resetPosition()#
The Motor.resetPosition()
command resets the Motor position to 0.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devoluciones: Ninguna.
Motor.setPosition()#
The Motor.setPosition(value, units)
command is used to set the position of a Motor. The position that is returned by the Motor.position()
function will be updated to this new value.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setPosition(value, units)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
valor |
La nueva posición a fijar para el motor. |
unidades |
Optional. A valid rotationUnit. The default is |
Devoluciones: Ninguna.
Motor.setTimeout()#
The Motor.setTimeout(value, units)
command is used to set the timeout for a Motor. The position that is returned by the Motor.getTimeout()
function will be updated to this new value.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setTimeout(value, units)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
valor |
El nuevo tiempo de espera que se debe establecer para el motor. |
unidades |
Optional. A valid timeUnit. The default is |
Devoluciones: Ninguna.
Motor.getTimeout()#
The Motor.getTimeout()
command returns the current timeout for a Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.getTimeout()
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devuelve: El valor de tiempo de espera actual en milisegundos.
Motor.isSpinning()#
The Motor.isSpinning()
command returns if the Motor is currently spinning.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devuelve: Verdadero si el motor está girando. Falso si no lo está.
Motor.isDone()#
The Motor.isDone()
command returns if the Motor has completed its movement.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devuelve: Verdadero si el motor ha completado su movimiento. Falso si no lo ha hecho.
Motor.setMaxTorque()#
The Motor.setMaxTorque(value, units)
command is used to set the maximum torque for a Motor. The torque can be set as torque, current, or a percent of maximum torque.
To use this command, replace Motor
with the desired Motor, for example: armMotor.setMaxTorque(value, units)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
valor |
El nuevo par máximo para un motor. |
unidades |
A valid torqueUnit, |
Devoluciones: Ninguna.
// Set maximum torque to 2 Newton Meters.
Motor1.set_max_torque(2, Nm);
Motor.convertVelocity()#
The Motor.convertVelocity(velocity, units, unitsout)
command converts the velocity in the given units to specified units based on the Motor gearing.
To use this command, replace Motor
with the desired Motor, for example: armMotor.convertVelocity(velocity, units, unitsout)
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
velocidad |
La velocidad a convertir. |
unidades |
Una velocityUnit válida para el valor de velocidad. |
unidades fuera |
Optional. A valid velocityUnit for the returned velocity. The default is |
Devuelve: Devuelve la velocidad convertida a velocidad en las unidades especificadas.
Motor.getMotorCartridge()#
The Motor.getMotorCartridge()
command returns the gear cartridge setting for the Motor.
To use this command, replace Motor
with the desired Motor, for example: armMotor.getMotorCartridge()
.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devoluciones: La configuración del cartucho de engranaje del motor.
Dirección del motor()#
The Motor.direction()
command returns the current direction the Motor is spinning in.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devuelve: El directionType actual en el que está girando el motor.
Posición del motor()#
The Motor.position(units)
command returns the current position of the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid rotationUnit. The default is |
Devuelve: La posición actual del motor en las unidades especificadas.
Motor.velocidad()#
The Motor.velocity(units)
command returns the current velocity of the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid velocityUnit. The default is |
Devuelve: La velocidad actual del motor en las unidades especificadas.
Corriente del motor()#
The Motor.current(units)
command returns the current being used by the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. The only valid unit for current is |
Devuelve: La corriente que consume el motor en las unidades especificadas.
Potencia del motor()#
The Motor.power(units)
command returns the power being consumed by the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. The only valid unit for power is |
Devuelve: La potencia consumida por el motor en las unidades especificadas.
Par motor()#
The Motor.torque(units)
command returns the torque being generated by the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid torqueUnit. The default is |
Devuelve: El torque generado por el motor en las unidades especificadas.
Eficiencia del motor()#
The Motor.efficiency(units)
command returns the efficiency of the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. The only valid unit for efficiency is |
Devuelve: La eficiencia del motor como porcentaje.
Temperatura del motor()#
The Motor.temperature(units)
command returns the temperature of the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid temperatureUnit. The default is |
Devuelve: La temperatura del motor en las unidades especificadas.
Motor.comando()#
The Motor.command(units)
command returns the last velocity sent to the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid velocityUnit. The default is |
Devuelve: La velocidad del comando del motor en las unidades especificadas.
Motor.instalado()#
The Motor.installed()
command checks if the Motor is connected.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devuelve: Verdadero si el motor está conectado. Falso si no lo está.
Motor.valor()#
The Motor.value()
command returns the value of the Motor.
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Devuelve: Un entero que representa el valor del motor.