电机29#

初始化 motor29 类#

使用以下构造函数之一创建用于控制电机 393 的电机控制器 29。

The motor29(port) constructor creates a motor29 object in the specified Three Wire Port.

范围

描述

port

The 3-Wire Port that the Motor Controller 29 is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

The motor29(port, reverse) constructor creates a motor29 object in the specified Three Wire Port with the reverse flag set to the specified value.

范围

描述

port

The 3-Wire Port that the Motor Controller 29 is connected to, whether it’s a port on the Brain, or a 3-Wire Expander.

reverse

Set this Motor to be reversed or not. If set to true, the Motor will spin in the opposite rotation. The default is false.

A Brain or 3-Wire Expander must be created first before they can be used to create an object with the motor29 Class constructor.

// Create the Brain.
brain Brain;
// Construct a Motor Controller 29 "mc29" with the motor29 class.
motor29 mc29 = motor29(Brain.ThreeWirePort.A);

This mc29 object will be used in all subsequent examples throughout this API documentation when referring to Motor29 class methods.

类方法#

spin()#

这是一种非等待方法,允许下一个方法无延迟运行。

该方法通过以下方式调用:

The spin(dir) method spins the motor in a specified direction at the default velocity. The motor is assumed to have a maximum velocity of 100 rpm.

参数

描述

dir

A valid directionType.

// spin motor forward.
mc29.spin(forward);

The spin(direction, velocity, units) method spins the motor in a specified direction at the specified velocity. The motor is assumed to have a maximum velocity of 100 rpm.

参数

描述

direction

A valid directionType.

velocity

旋转电机的速度。

units

A valid velocityUnit.

// spin motor forward at 100 rpm.
mc29.spin(forward, 100, rpm);

**返回:**无。

stop()#

The stop() method stops the motor.

**返回:**无。

setVelocity()#

The setVelocity(velocity, units) method sets the velocity of the motor. This will be the velocity used for subsequent calls of the spin() method that do not specify a velocity.

这是一种非等待方法,允许下一个方法无延迟运行。

参数

描述

velocity

要设置的速度值。

units

The only valid unit for velocity in this usecase is percent.

**返回:**无。

setReversed()#

The setReversed() method sets the motor direction to be reversed or not.

参数

描述

value

用于设置方向是否反转的布尔值或二进制值。

**返回:**无。