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

index

El Puerto en el cerebro EXP al que está conectado el motor.

reverse

A boolean value to reverse the direction the Motor spins forward in. The default is false.

// 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

index

El Puerto en el cerebro EXP al que está conectado el motor.

gears

El gearSetting insertado en el motor.

// 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

index

El Puerto en el cerebro EXP al que está conectado el motor.

gears

El gearSetting insertado en el motor.

reverse

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

director

Un directionType válido.

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

director

Un directionType válido.

velocidad

La velocidad a la que girará el motor.

unidades

A valid velocityUnit or percent.

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

director

Un directionType válido.

Voltaje

El voltaje al que girará el motor.

unidades

Una voltageUnit válida.

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

rotación

La posición a la que debe girar el motor.

unidades

Una rotationUnit válida.

esperar a que se complete

Determines whether the command will block subsequent commands (waitForCompletion=true) or allow immediate execution (waitForCompletion=false). If unspecified, the default for the waitForCompletion parameter is waitForCompletion=true.

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

rotación

La posición a la que debe girar el motor.

unidades

Una rotationUnit válida.

velocidad

La velocidad con la que girará el motor.

unidades_v

Una velocityUnit válida.

esperar a que se complete

Determines whether the command will block subsequent commands (waitForCompletion=true) or allow immediate execution (waitForCompletion=false). If unspecified, the default for the waitForCompletion parameter is waitForCompletion=true.

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

tiempo

La cantidad de tiempo durante el cual debe girar el motor.

unidades

Una unidad de tiempo válida.

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

director

Un directionType válido.

tiempo

La cantidad de tiempo durante el cual debe girar el motor.

unidades

Una unidad de tiempo válida.

// 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

tiempo

La cantidad de tiempo durante el cual debe girar el motor.

unidades

Una unidad de tiempo válida.

velocidad

La velocidad con la que girará el motor.

unidades_v

Una velocityUnit válida.

// 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

director

Un directionType válido.

tiempo

La cantidad de tiempo durante el cual debe girar el motor.

unidades

Una unidad de tiempo válida.

velocidad

La velocidad con la que girará el motor.

unidades_v

Una velocityUnit válida.

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

rotación

El valor de rotación que debe girar el motor.

unidades

Una rotationUnit válida.

esperar a que se complete

Determines whether the command will block subsequent commands (waitForCompletion=true) or allow immediate execution (waitForCompletion=false). If unspecified, the default for the waitForCompletion parameter is waitForCompletion=true.

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

director

Un directionType válido.

rotación

El valor de rotación que debe girar el motor.

unidades

Una rotationUnit válida.

esperar a que se complete

Determines whether the command will block subsequent commands (waitForCompletion=true) or allow immediate execution (waitForCompletion=false). If unspecified, the default for the waitForCompletion parameter is waitForCompletion=true.

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

rotación

El valor de rotación para que gire el motor.

unidades

Una rotationUnit válida.

velocidad

La velocidad con la que girará el motor.

unidades_v

Una velocityUnit válida.

esperar a que se complete

Determines whether the command will block subsequent commands (waitForCompletion=true) or allow immediate execution (waitForCompletion=false). If unspecified, the default for the waitForCompletion parameter is waitForCompletion=true.

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

director

Un directionType válido.

rotación

El valor de rotación que debe girar el motor.

unidades

Una rotationUnit válida.

velocidad

La velocidad con la que girará el motor.

unidades_v

Una velocityUnit válida.

esperar a que se complete

Determines whether the command will block subsequent commands (waitForCompletion=true) or allow immediate execution (waitForCompletion=false). If unspecified, the default for the waitForCompletion parameter is waitForCompletion=true.

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

modo

Un brakeType válido.

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

velocidad

La nueva velocidad a establecer para el motor.

unidades

A valid velocityUnit or percent.

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

valor

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

modo

Un brakeType válido.

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

valor

La nueva posición que debe establecerse para el codificador del motor.

unidades

Una rotationUnit válida.

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

valor

El nuevo tiempo de espera que se debe establecer para el motor.

unidades

Una unidad de tiempo válida.

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

valor

El nuevo par máximo para un motor.

unidades

Una torqueUnit válida.

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

valor

El nuevo par máximo para un motor.

unidades

The only valid unit is amp.

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

valor

El nuevo par máximo para un motor.

unidades

The only valid unit is percent.

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

velocidad

La velocidad a convertir.

unidades

Una velocityUnit válida para la velocidad de entrada.

unidades fuera

Una velocityUnit válida para la velocidad de salida.

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.

Devuelve: Un valor directionType que representa la dirección actual en la que está girando el motor.

position()#

The position(units) command returns the current rotation of the Motor.

Parámetros

Descripción

unidades

Una rotationUnit válida.

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

unidades

A valid velocityUnit or percent.

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

unidades

The only valid units for current are amp or percent.

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

unidades

A valid voltageUnit. The default is volt.

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

unidades

The only valid unit for power is watt.

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

unidades

Una torqueUnit válida.

Devuelve: El torque del motor en las unidades especificadas.

efficiency()#

The efficiency(units) command returns the efficiency of the Motor.

Parámetros

Descripción

unidades

The only valid unit for efficiency is percent.

Devuelve: La eficiencia del motor como porcentaje.

temperature()#

The temperature(units) command returns the current temperature of the Motor.

Parámetros

Descripción

unidades

A valid temperatureUnit or percent.

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.