传动系统#

初始化传动系统类#

使用以下构造函数创建动力传动系统:

The drivetrain constructor creates a drivetrain object.

范围

描述

lm

左侧 电机电机组 的名称。

rm

右侧 电机电机组 的名称。

wheelTravel

驱动轮的周长。默认值为 300 毫米。

trackWidth

传动系统的轮距。默认值为 320 毫米。

wheelBase

传动系统的轴距。默认值为 320 毫米。

units

A valid distanceUnit for the units that wheelTravel, trackWidth and wheelBase are specified in. The default is mm.

externalGearRatio

如果使用齿轮传动,则电机的 gearSetting 用于补偿驱动距离。

必须先创建 Motors 和/或 Motor Groups,然后才能使用传动系统类构造函数创建对象。

// Create the Motors.
motor left_motor = motor(PORT1,false);
motor right_motor = motor(PORT2, true);
// Construct a 2-Motor drivetrain "Drivetrain" with the
// drivetrain class.
drivetrain Drivetrain = drivetrain(left_motor, right_motor, 259.34, 320, 40, mm, ratio18_1);

如果制作 4 电机传动系统,则需要先单独创建 电机,然后再将它们分组到 电机组中。

// Create the left Motors and group them under the
// motor_group "leftMotors".
motor leftMotorA = motor(PORT1, false);
motor leftMotorB = motor(PORT2, false);
motor_group leftMotors = motor_group(leftMotorA, leftMotorB);
// Create the right Motors and group them under the
// MotorGroup "rightMotors".
motor rightMotorA = motor(PORT3, true);
motor rightMotorB = motor(PORT4, true);
motor_group rightMotors = motor_group(rightMotorA, rightMotorB);
// Construct a 4-Motor drivetrain "Drivetrain" with the
// drivetrain class.
drivetrain Drivetrain = drivetrain(leftMotors, rightMotors, 259.34, 320, 40, mm, ratio18_1);

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

要在您的动力传动系统中加入 惯性传感器陀螺仪传感器 以增强转弯功能,您可以在使用 smartdrive 类构造函数创建对象时将其包含在内。

类方法#

drive()#

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

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

The drive(dir) method is used to drive the drivetrain in the specified direction forever at the default velocity as specified by the setDriveVelocity() method, until another drivetrain movement method is used, or the project is stopped.

参数

描述

目录

有效的 DirectionType

**返回:**无。

// Drive the drivetrain forward.
Drivetrain.drive(forward);

The drive(dir, velocity, units) method is used to drive the drivetrain in the specified direction forever at a specified velocity, until another drivetrain movement method is used, or the project is stopped.

参数

描述

目录

有效的 directionType

速度

传动系统移动的速度。

单位

有效的 velocityUnit

**返回:**无。

// Drive the drivetrain forward at 100 rpm.
Drivetrain.drive(forward, 100, rpm);

driveFor()#

This can be a waiting or non-waiting method depending on if the waitForCompletion parameter is used.

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

The driveFor(distance, units, waitForCompletion) method is used to drive the drivetrain for a specified distance at the default velocity.

参数

描述

距离

传动系统移动的距离。

单位

A valid DistanceUnit. The default is inches.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已达到目标距离。

// Drive the drivetrain for 10 inches.
Drivetrain.driveFor(10, inches);

The driveFor(dir, distance, units, waitForCompletion) method is used to drive the drivetrain in a specified direction for a specified distance at the default velocity.

参数

描述

目录

有效的 directionType

距离

传动系统移动的距离。

单位

A valid distanceUnit. The default is inches.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已达到目标距离。

// Drive the drivetrain forward for 10 inches.
Drivetrain.driveFor(forward, 10, inches);

The driveFor(distance, units, velocity, units_v, waitForCompletion) method is used to drive the drivetrain for a specified distance at the default velocity.

参数

描述

距离

传动系统移动的距离。

单位

A valid distanceUnit. The default is inches.

速度

The velocity the drivetrain will move with. The default velocity set by the setDriveVelocity() method will be used if not provided.

单位

A valid velocityUnit. The default is rpm.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已达到目标距离。

// Drive the drivetrain for 10 inches at 100 rpm.
Drivetrain.driveFor(10, inches, 100, rpm);

The driveFor(dir, distance, units, velocity, units_v, waitForCompletion) method is used to drive the drivetrain for a specified distance at the default velocity.

参数

描述

目录

有效的 directionType

距离

传动系统移动的距离。

单位

A valid distanceUnit. The default is inches.

速度

The velocity the drivetrain will move with. The default velocity set by the setDriveVelocity() method will be used if not provided.

单位

A valid velocityUnit. The default is rpm.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已达到目标距离。

// Drive the drivetrain forward for 10 inches at 100 rpm.
Drivetrain.driveFor(forward, 10, inches, 100, rpm);

turn()#

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

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

The turn(dir) method is used to turn the robot in a specified direction at the default velocity as specified by the setTurnVelocity() method, until another drivetrain movement method is used, or the project is stopped.

参数

描述

目录

有效的 directionType

**返回:**无。

// Turn the drivetrain right.
Drivetrain.turn(right);

The turn(dir, velocity, units) method is used to turn the robot in a specified direction at a specified velocity, until another drivetrain movement method is used, or the project is stopped.

参数

描述

目录

有效的 directionType

速度

The velocity at which the drivetrain will turn. The default velocity set by The setTurnVelocity() method will be used if not provided.

单位

A valid velocityUnit. The default is rpm.

**返回:**无。

// Turn the drivetrain right at 100 rpm.
Drivetrain.turn(right, 100, rpm);

turnFor()#

This can be a waiting or non-waiting method depending on if the waitForCompletion parameter is used.

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

The turnFor(angle, units, waitForCompletion) turns the drivetrain for a specified angle or rotations at the default velocity as specified by the setTurnVelocity() method.

参数

描述

角度

传动系统转动的角度。

单位

A valid rotationUnit. The default is degrees.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已转到目标角度。

// Turn the drivetrain for 90 degrees.
Drivetrain.turnFor(90, degrees);

The turnFor(dir, angle, units, waitForCompletion) turns the drivetrain left or right for a specified angle or rotations at the default velocity as specified by the setTurnVelocity() method.

参数

描述

目录

有效的 directionType

角度

传动系统转动的角度。

单位

A valid rotationUnit. The default is degrees.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已转到目标角度。

// Turn the drivetrain right for 90 degrees.
Drivetrain.turnFor(right, 90, degrees);

The turnFor(angle, units, velocity, units_v, waitForCompletion) turns the drivetrain for a specified angle or rotations at a specified velocity.

参数

描述

角度

传动系统转动的角度。

单位

A valid rotationUnit. The default is degrees.

速度

The velocity at which the drivetrain will turn. The default velocity set by The setTurnVelocity() method will be used if not provided.

单位

A valid velocityUnit. The default is rpm.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已转到目标角度。

// Turn the drivetrain for 90 degrees at 100 rpm.
Drivetrain.turnFor(90, degrees, 100, rpm);

The turnFor(dir, angle, units, velocity, units_vwaitForCompletion) turns the drivetrain left or right for a specified angle or rotations at a specified velocity.

参数

描述

目录

有效的 directionType

角度

传动系统转动的角度。

单位

A valid rotationUnit. The default is degrees.

速度

The velocity at which the drivetrain will turn. The default velocity set by The setTurnVelocity() method will be used if not provided.

单位

A valid velocityUnit. The default is rpm.

等待完成

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.

**返回:**一个布尔值,表示传动系统是否已转到目标角度。

// Turn the drivetrain right for 90 degrees at 100 rpm.
Drivetrain.turnFor(right, 90, degrees, 100, rpm);

stop()#

这是一个非等待命令,允许下一个命令无延迟运行。

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

The stop() command is used to stop the drivetrain, setting the drivetrain to 0 velocity and configuring the current stopping mode. The default Brake Type is coast, unless previously changed using the setStopping() command.

**返回:**无。

// Spin Drivetrain for 2.5 seconds.
Drivetrain.spin(forward);

wait(2.5 seconds);

// Stop Drivetrain.
Drivetrain.stop();

The stop(mode) command is used to stop the drivetrain using a specific Brake Type.

参数

描述

模式

有效的 brakeType

**返回:**无。

// Spin Drivetrain for 2.5 seconds.
Drivetrain.spin(forward);

wait(2.5 seconds);

// Stop Drivetrain using the hold Brake Type.
Drivetrain.stop(hold);

isMoving()#

The isMoving() command returns if any drivetrain motor is on and rotating to a specific target.

Returns: true if any drivetrain motor is on and rotating to a target. false if it they are done rotating to a target.

isDone()#

The isDone() command returns if all drivetrain motors are done rotating to a specific target.

Returns: true if the all drivetrain motors are done rotating to a target. false if any drivetrain motor is on and rotating to a target.

setDriveVelocity()#

The setDriveVelocity(velocity, units) method is used to set the default velocity for the Drivetrain. This velocity setting affects all subsequent drive method unless a specific velocity is provided in those method.

参数

描述

速度

为传动系统设置的新速度为默认速度。

单位

A valid velocityUnit or percent. The default is rpm.

**返回:**无。

// Set the drivetrain to drive at a velocity of 200 rpm.
Drivetrain.setDriveVelocity(200, rpm);

setTurnVelocity()#

The setTurnVelocity(velocity, units) method is used to set the default velocity for turning maneuvers in the Drivetrain. This setting specifies the speed at which the drivetrain will execute turning method unless overridden by a specific velocity in those method.

参数

描述

速度

设置为转弯操作默认的新速度。

单位

A valid velocityUnit or percent. The default is rpm.

**返回:**无。

// Set the drivetrain to turn at a velocity of 200 RPM.
Drivetrain.setTurnVelocity(200, rpm);

setStopping()#

The setStopping(mode) method is used to set the stopping mode for all motors on the Drivetrain. This setting determines the behavior of the motors when they receive a stop method or when the velocity is set to zero.

参数

描述

模式

有效的 brakeType

**返回:**无。

// Set the stopping mode to BRAKE.
Drivetrain.setStopping(brake);

setGearRatio()#

The setGearRatio(mode) method is used to set the gear ratio for all motors on the Drivetrain.

参数

描述

模式

有效的 gearSetting

**返回:**无。

setTimeout()#

The Drivetrain.setTimeout(time, units) method is used to set the timeout value for all motors on the Drivetrain. This setting determines how long the drivetrain will attempt to execute driveFor or turnFor method before timing out if the motors have not completed their movements.

参数

描述

暂停

设置为动力传动系统操作默认的超时持续时间。

单位

A valid timeUnit type. The default is msec.

**返回:**无。

// Set the timeout for the drivetrain to 10 seconds.
Drivetrain.setTimeout(10, seconds);

velocity()#

The velocity(units) method returns the average velocity of the drivetrain.

参数

描述

单位

A valid velocityUnit or percent. The default is rpm.

**返回:**以指定单位表示传动系统速度的双精度数。

current()#

The current() method returns the average current of the drivetrain.

参数

描述

单位

The only valid units for current are amp or percent.

**返回:**以指定单位表示动力传动系统电流的双精度数。

voltage()#

The voltage(units) method returns the average velocity of the drivetrain.

参数

描述

单位

A valid voltageUnit. The default is volt.

**返回:**以指定单位表示动力传动系统电压的双精度数。

power()#

The power(units) method returns the average power of the drivetrain .

参数

描述

单位

The only valid unit for power is watt.

**返回:**以指定单位表示动力传动系统功率的双精度数。

torque()#

The torque(units) method returns the average torque of the drivetrain.

参数

描述

单位

A valid torqueUnit. The default is Nm.

**返回:**以指定单位表示传动系统扭矩的双精度数。

efficiency()#

The efficiency(units) method returns the average efficiency of the drivetrain.

参数

描述

单位

The only valid unit for efficiency is percent.

**返回:**以提供的单位表示传动系统效率的双精度值。

temperature()#

The temperature(units) method returns the average temperature of the drivetrain.

参数

描述

单位

The only valid unit for temperature is percent.

**返回:**以提供的单位表示动力传动系统温度的双精度值。