传动系统#
介绍#
传动系统控制机器人的运动,使其能够精确地前进、转弯和停止。
当配置陀螺仪传感器或脑惯性传感器时,它还可以用作智能传动系统。
For the examples below, the configured drivetrain will be named Drivetrain
and will be used in all subsequent examples throughout this API documentation when referring to drivetrain
and smartdrive
class methods.
以下是所有方法的列表:
动作——移动和转动机器人。
drive – 无限期地沿指定方向移动传动系统。
driveFor – 将传动系统沿指定方向移动一段设定的距离。
turn – 无限期地向左或向右转动传动系统。
turnFor – 将传动系统向左或向右转动一段设定的距离。
turnToHeading – 将智能传动系统转向指定方向。
turnToRotation – 将智能传动系统转到指定的旋转值。
stop – 停止传动系统。
calibrateDrivetrain – 校准传动系统。
变异器——设置默认移动和转动速度。
setDriveVelocity – 设置传动系统的默认移动速度。
setTurnVelocity – 设置动力传动系统的默认转弯速度。
setStopping – 设置传动系统的停止模式。
setTimeout – 为动力传动系统功能设置时间限制。
setHeading – 设置智能传动系统的航向。
setRotation – 设置智能传动系统的旋转。
setGearRatio – 设置传动系统上所有电机的齿轮比。
setTurnThreshold – 设置智能传动系统的转弯阈值。
setTurnConstant – 设置智能传动系统的转弯常数。
setTurnDirectionReverse – 设置正航向的预期转弯方向。
Getters – 返回机器人状态和位置。
isDone – 返回传动系统当前是否未移动。
isMoving – 返回传动系统当前是否正在移动。
heading – 返回智能传动系统的当前航向。
rotation – 返回智能传动系统的当前旋转值。
velocity – 返回传动系统的当前速度。
current – 返回动力传动系统的当前电流。
power – 返回智能传动系统的平均功率。
torque – 返回传动系统的平均扭矩。
效率 – 返回传动系统的平均效率。
温度 – 返回传动系统的平均温度。
构造函数——手动初始化和配置传动系统。
drivetrain – 创建基本传动系统。
smartdrive – 创建配置有陀螺仪传感器或脑惯性传感器的传动系统。
行动#
drive#
drive
moves the drivetrain in a specified direction indefinitely.
Default Usage:
Drivetrain.drive(direction);
Overload Usages:
Drivetrain.drive(direction, velocity, units);
参数 |
描述 |
---|---|
方向 |
The direction in which to drive:
|
速度 |
传动系统移动的速度,以浮点数或整数表示。如果未指定速度,则默认速度为 50%。 |
单位 |
The unit that represents the velocity:
|
// Example coming soon
driveFor#
driveFor
moves the drivetrain in a specified direction for a set distance.
Default Usage:
Drivetrain.driveFor(direction, distance, units, wait);
Overload Usages:
Drivetrain.driveFor(direction, distance, units, wait);
Drivetrain.driveFor(direction, distance, units, velocity, units_v, wait);
Drivetrain.driveFor(distance, units, wait);
Drivetrain.driveFor(distance, units, velocity, units_v, wait);
参数 |
描述 |
---|---|
方向 |
The direction in which to drive:
|
距离 |
传动系统以双倍速度移动的距离。 |
单位 |
The unit that represents the distance:
|
等待 |
Optional.
|
速度 |
传动系统以双精度移动的速度。如果未指定速度,则默认速度为 50%。 |
单位 |
The unit that represents the velocity:
|
// Example coming soon
turn#
turn
turns the drivetrain left or right indefinitely.
Default Usage:
Drivetrain.turn(direction);
Overload Usages:
Drivetrain.turn(direction, velocity, units);
参数 |
描述 |
---|---|
方向 |
The direction in which to turn:
right |
速度 |
传动系统以双倍速度旋转的速度。如果未指定速度,则默认速度为 50%。 |
单位 |
The unit that represents the velocity:
|
// Example coming soon
turnFor#
turnFor
turns the drivetrain left or right for a set distance.
Default Usage:
Drivetrain.turnFor(direction, angle, units, wait);
Overload Usages:
Drivetrain.turnFor(direction, angle, units, velocity, units_v, wait);
Drivetrain.turnFor(angle, units, wait);
Drivetrain.turnFor(angle, units, velocity, units_v, wait);
参数 |
描述 |
---|---|
方向 |
The direction in which to turn:
|
角度 |
传动系统旋转的度数为双倍。 |
单位 |
The unit that represents the rotational value:
|
速度 |
传动系统以双倍速度旋转的速度。如果未指定速度,则默认速度为 50%。 |
单位 |
The unit that represents the velocity:
|
等待 |
Optional.
|
// Example coming soon
turnToHeading#
turnToHeading
turns a smart drivetrain to a specified heading.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Default Usage:
Drivetrain.turnToHeading(angle, units, wait);
Overload Usages:
Drivetrain.turnToHeading(angle, units, velocity, units_v, wait);
参数 |
描述 |
---|---|
角度 |
以浮点数或整数形式表示传动系统转向的方向。 |
单位 |
The unit that represents the rotational value:
|
速度 |
电机或电机组的旋转速度,以浮点数或整数表示。如果未指定速度,则默认速度为 50%。 |
单位 |
The unit that represents the velocity:
|
等待 |
Optional.
|
// Example coming soon
turnToRotation#
turnToRotation
turns a smart drivetrain to a specified rotational value.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Default Usage:
Drivetrain.turnToRotation(angle, units, wait);
Overload Usages:
Drivetrain.turnToRotation(angle, units, velocity, units_v, wait);
参数 |
描述 |
---|---|
角度 |
以浮点数或整数形式表示传动系统转向的方向。 |
单位 |
The unit that represents the rotational value:
|
速度 |
电机或电机组的旋转速度,以浮点数或整数表示。如果未指定速度,则默认速度为 50%。 |
单位 |
The unit that represents the velocity:
|
等待 |
Optional.
|
// Example coming soon
stop#
stop
stops a drivetrain.
Default Usage:
Drivetrain.stop();
Overload Usages:
Drivetrain.stop(mode);
参数 |
描述 |
---|---|
模式 |
How the drivetrain will stop:
|
// Example coming soon
calibrateDrivetrain#
calibrateDrivetrain
calibrates the drivetrain.
Usage:
Drivetrain.calibrateDrivetrain();
// Example coming soon
修改器#
setDriveVelocity#
setDriveVelocity
sets the default moving velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions if a specific velocity is not provided.
Usage:
Drivetrain.setDriveVelocity(velocity, units);
参数 |
描述 |
---|---|
速度 |
传动系统以双倍速度移动。 |
单位 |
The unit that represents the velocity:
|
// Example coming soon
setTurnVelocity#
setTurnVelocity
sets the default turning velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions if a specific velocity is not provided.
Usage:
Drivetrain.setTurnVelocity(velocity, units);
参数 |
描述 |
---|---|
速度 |
传动系统以双倍速度旋转的速度。 |
单位 |
The unit that represents the velocity:
|
setStopping#
setStopping
sets the stopping mode for a drivetrain.
Usage:
Drivetrain.setStopping(mode);
参数 |
描述 |
---|---|
模式 |
How the drivetrain will stop:
|
// Example coming soon
setTimeout#
setTimeout
sets a time limit for how long a drivetrain function will wait to reach its target. If the drivetrain cannot complete the movement within the set time, it will stop automatically and continue with the next function.
**注意:**传动系统的时间限制用于防止未达到目标位置的传动系统功能停止项目其余部分的执行。
Usage:
Drivetrain.setTimeout(time, units);
参数 |
描述 |
---|---|
时间 |
电机功能在停止并移动到下一个功能之前运行的最大秒数(整数)。 |
单位 |
The unit that represents the time:
|
// Example coming soon
setHeading#
setHeading
sets the heading of a smart drivetrain.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.setHeading(value, units);
参数 |
描述 |
---|---|
价值 |
新的标题为双重标题。 |
单位 |
The unit that represents the heading:
|
// Example coming soon
setRotation#
setRotation
sets the rotation for the smart drivetrain.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.setRotation(value, units);
参数 |
描述 |
---|---|
价值 |
新的旋转值(双精度值)。 |
单位 |
The unit that represents the heading:
|
// Example coming soon
setGearRatio#
setGearRatio
sets the gear ratio for all motors on the Drivetrain.
Usage:
Drivetrain.setGearRatio(mode);
参数 |
描述 |
---|---|
模式 |
Gear Ratio options:
|
// Example coming soon
setTurnThreshold#
setTurnThreshold
method sets the turn threshold for the Smartdrive. The threshold value is used to determine that turns are complete. If this is too large, then turns will not be accurate. If too small, then turns may not complete.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.setTurnThreshold(t);
参数 |
描述 |
---|---|
吨 |
The new turn threshold in |
// Example coming soon
setTurnConstant#
setTurnConstant
method sets the turn constant for the Smartdrive. The Smart Drivetrain uses a simple P controller when doing turns. This constant, generally known as kp, is the gain used in the equation that turns angular error into motor velocity.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.setTurnConstant(kp);
参数 |
描述 |
---|---|
千帕 |
新的转弯常数,范围为 0.1 - 4.0。默认值为 1.0。 |
// Example coming soon
setTurnDirectionReverse#
setTurnDirectionReverse
method sets the expected turn direction for positive heading.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.setTurnDirectionReverse(value);
参数 |
描述 |
---|---|
价值 |
A boolean value to set the reversed flag to |
// Example coming soon
吸气剂#
isDone#
isDone
returns a Boolean indicating whether a drivetrain is not currently moving.
true
– The drivetrain is not moving.false
– The drivetrain is moving.
Usage:
Drivetrain.isDone()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
isMoving#
isMoving
returns a Boolean indicating whether a drivetrain is currently moving.
true
– The drivetrain is moving.false
– The drivetrain is not moving.
Usage:
Drivetrain.isMoving()
参数 |
描述 |
---|---|
该方法没有参数。 |
// Example coming soon
heading#
heading
returns the current heading of a smart drivetrain as a double.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.heading(units)
参数 |
描述 |
---|---|
单位 |
Optional. The unit that represents the rotational value:
|
// Example coming soon
rotation#
rotation
returns the current rotational value of a smart drivetrain as a double.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.rotation(units)
参数 |
描述 |
---|---|
单位 |
Optional. The unit that represents the rotational value:
|
// Example coming soon
velocity#
velocity
returns the current velocity of a drivetrain as a double.
Usage:
Drivetrain.velocity(units)
参数 |
描述 |
---|---|
单位 |
The unit that represents the velocity:
|
// Example coming soon
current#
current
returns the current current of a drivetrain as a double.
Usage:
Drivetrain.current(units)
参数 |
描述 |
---|---|
单位 |
Optional. The unit that represents the current:
|
// Example coming soon
power#
power(units)
returns the average power of the Smart Drivetrain as a double.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.power(units)
参数 |
描述 |
---|---|
单位 |
The only valid unit for power is |
// Example coming soon
torque#
torque
returns the average torque of the Drivetrain as a double.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.torque(units)
参数 |
描述 |
---|---|
单位 |
A valid torque Unit:
|
// Example coming soon
efficiency#
efficiency
returns the average efficiency of the Drivetrain as a double.
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
Usage:
Drivetrain.efficiency(units)
参数 |
描述 |
---|---|
单位 |
The only valid unit for efficiency is |
// Example coming soon
temperature#
The temperature()
method returns the average temperature of the Drivetrain as a double.
Usage:
Drivetrain.temperature(units)
注意:此方法仅适用于配置了陀螺仪传感器或脑惯性传感器的传动系统。
参数 |
描述 |
---|---|
单位 |
The only valid unit for temperature is |
// Example coming soon
构造函数#
Drivetrain#
使用以下构造函数创建动力传动系统:
The drivetrain
constructor creates a drivetrain object.
Usage:
drivetrain(lm, rm, wheelTravel, trackWidth, wheelBase, unit, externalGearRatio);
范围 |
描述 |
---|---|
|
|
|
|
|
驱动轮的周长。默认值为 300 毫米。 |
|
传动系统的轮距。默认值为 320 毫米。 |
|
传动系统的轴距。默认值为 320 毫米。 |
|
A valid distanceUnit for the units that wheelTravel, trackWidth and wheelBase are specified in. The default is |
|
如果使用齿轮传动,则使用齿轮比来补偿驱动距离。 |
必须先创建 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, 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, 1);
This Drivetrain
object will be used in all subsequent examples throughout this API documentation when referring to drivetrain class methods.
要在您的传动系统中加入 惯性传感器 或 陀螺仪传感器 以增强转弯功能,您可以在使用 smartdrive 类构造函数创建对象时将其包含在内。
Smartdrive#
使用以下构造函数创建智能传动系统:
The smartdrive
constructor creates a smartdrive object. This object can do everything a drivetrain can do but has additional methods that include use of an Inertial Sensor or Gyro in order to make more accurate turns.
Usage:
smartdrive(lm, rm, guido, wheelTravel, trackWidth, wheelBase, unit, externalGearRatio);
范围 |
描述 |
---|---|
|
|
|
|
|
|
|
驱动轮的周长。默认值为 300 毫米。 |
|
智能传动系统的轮距。默认值为 320 毫米。 |
|
智能传动系统的轴距。默认值为 320 毫米。 |
|
A valid distanceUnit for the units that wheelTravel, trackWidth and wheelBase are specified in. The default is |
|
如果使用齿轮传动,则使用齿轮比来补偿驱动距离。 |
必须先创建 Motors 和/或 Motor Groups,然后才能使用 smartdrive 类构造函数创建对象。
// Create the Motors.
motor left_motor = motor(PORT1,false);
motor right_motor = motor(PORT2, true);
// Create the Inertial Sensor
inertial Inertial = inertial(PORT3);
// Construct a 2-Motor Smart Drivetrain "Smartdrive" with the
// smartdrive class.
smartdrive Smartdrive = smartdrive(left_motor, right_motor, Inertial, 259.34, 320, 40, mm, 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);
// Create the Inertial Sensor
inertial Inertial = inertial(PORT5);
// Construct a 4-Motor smartdrive "Smartdrive" with the
// smartdrive class.
smartdrive Smartdrive = smartdrive(leftMotors, rightMotors, Inertial, 259.34, 320, 40, mm, 1);
This Smartdrive
object will be used in all subsequent examples throughout this API documentation when referring to smartdrive class methods.