传动系统#

介绍#

驱动系统使机器人能够连续移动或移动设定的距离,按度数或朝向某个方向旋转,并对其旋转方向的变化做出反应。

如果传动系统配置有惯性传感器GPS传感器陀螺仪传感器,则传动系统可以通过跟踪传感器的航向和旋转来更精确地进行前进、后退和转弯运动。

驱动系统类别还包含多种配置方法,可用于设置行驶和转弯速度、定义停止行为、应用超时以避免执行停滞,以及手动更新机器人的航向或旋转值。这些功能在设计自主行为或实时调整时提供了极大的灵活性。

This page uses drivetrain as the example drivetrain name. Replace it with your own configured name as needed.

以下是可用方法列表:

动作——移动和转向机器人。

  • drive — Drives the robot continuously forward or in reverse using the current drive velocity.

  • driveFor — Drives the robot forward or in reverse for a set distance.

  • turn — Rotates the robot continuously left or right using the current turn velocity.

  • turnFor — Rotates the robot left or right for a specified angle.

  • turnToHeading — Rotates the robot to face a specific absolute heading.

  • turnToRotation — Rotates the robot to reach a specific cumulative rotation.

  • stop — Stops the drivetrain using the configured stopping mode.

  • calibrateDrivetrain — Calibrates the drivetrain’s configured Inertial Sensor, GPS Sensor, or Gyro Sensor.

  • arcade — Drives the drivetrain forward or reverse while turning at the same time.

变异器 — 设置默认移动和转向速度。

  • setDriveVelocity — Sets the default drive velocity used by drive methods.

  • setTurnVelocity — Sets the default turn velocity used by turn methods.

  • setStopping — Sets how the drivetrain behaves when it stops.

  • setTimeout — Sets how long drive and turn methods try to reach their target before timing out.

  • setHeading — Manually sets the robot’s heading value.

  • setRotation — Manually sets the robot’s cumulative rotation value.

  • setGearRatio — Sets the gear ratio for all motors on the drivetrain.

  • setTurnThreshold — Sets the turn threshold for a drivetrain.

  • setTurnConstant — Sets the turn constant for a drivetrain.

  • setTurnDirectionReverse — Sets a drivetrain to have its direction be reversed.

  • setTurnVelocityMin — Sets the minimum turning velocity used by a drivetrain.

获取器 — 返回机器人状态和位置。

  • isDone — Returns whether a drivetrain is not currently moving.

  • isMoving — Returns whether a drivetrain is currently moving.

  • isTurning — Returns whether a drivetrain is currently turning.

  • heading — Returns the drivetrain’s heading angle.

  • rotation — Returns how much the drivetrain has turned since the project started.

  • velocity — Returns the drivetrain’s current velocity.

  • current — Returns the drivetrain’s current draw.

  • power — Returns the drivetrain’s power usage.

  • torque — Returns the drivetrain’s torque.

  • efficiency — Returns the drivetrain’s efficiency.

  • temperature — Returns the drivetrain motors’ temperature.

  • voltage — Returns the voltage currently applied to the drivetrain.

构造函数——手动初始化和配置动力传动系统。

行动#

drive#

drive moves the drivetrain forward or in reverse using the current drive velocity. This method runs continuously until another Drivetrain method interrupts it or the project stops.

Default Usage:
Drivetrain.drive(direction);

Overload Usages:
Drivetrain.drive(direction, velocity, units);

参数

描述

direction

The direction in which the robot drives:

  • forward
  • reverse

velocity

传动系统运动的速度,以双精度浮点数表示。如果未指定速度或速度之前已设置为#setdrivevelocity,则默认速度为 50%。

units

The unit to represent the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Drive forward and back
  Drivetrain.drive(forward);
  wait(2, seconds);
  Drivetrain.drive(reverse, 25, velocityUnits::pct);
  wait(2, seconds);
  Drivetrain.stop();
}

driveFor#

driveFor moves the drivetrain forward or in reverse for a specified distance using the current drive velocity.

Default Usage:
Drivetrain.driveFor(direction, distance, units, wait);

Overload Usages:
Drivetrain.driveFor(direction, distance, units, velocity, units_v, wait);
Drivetrain.driveFor(distance, units, wait);
Drivetrain.driveFor(distance, units, velocity, units_v, wait);

参数

描述

direction

The direction in which the robot drives:

  • forward
  • reverse

distance

传动系统将移动的距离为双倍。

units

The units representing the distance:

  • mm — millimeters
  • inches — inches
  • cm — centimeters

wait

Optional.

  • true (default) — The project waits until driveFor is complete before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for driveFor to finish.

velocity

传动系统运动的速度,以双精度浮点数表示。如果未指定速度或速度之前已设置为#setdrivevelocity,则默认速度为 50%。

units_v

The unit to represent the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Drive 200 mm, then back 200 mm
  Drivetrain.driveFor(forward, 200, mm);
  Drivetrain.driveFor(reverse, 200, mm);
}

turn#

turn turns the drivetrain left or right indefinitely.

Default Usage:
Drivetrain.turn(direction);

Overload Usages:
Drivetrain.turn(direction, velocity, units);

参数

描述

direction

The direction in which to turn:

  • left
  • right

velocity

传动系统转速,以双精度浮点数表示。如果未指定转速或转速之前已设置为#setturnvelocity,则默认转速为 50%。

units

The unit that represents the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Turn right, then left, then stop
  Drivetrain.turn(right);
  wait(2, seconds);
  Drivetrain.turn(left);
  wait(2, seconds);
  Drivetrain.stop();
}

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);

参数

描述

direction

The direction in which to turn:

  • left
  • right

angle

传动系统旋转的角度(以双精度浮点数表示)。

units

The unit that represents the rotational value:

  • degrees
  • turns

velocity

传动系统转速,以双精度浮点数表示。如果未指定转速或转速之前已设置为#setturnvelocity,则默认转速为 50%。

units_v

The unit that represents the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

wait

Optional.

  • true (default) — The project waits until turnFor is complete before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for turnFor to finish.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Turn right then left
  Drivetrain.turnFor(right, 90, degrees);
  wait(1, seconds);
  Drivetrain.turnFor(left, 90, degrees);
}

turnToHeading#

turnToHeading turns a smart drivetrain to a specified heading.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Default Usage:
Drivetrain.turnToHeading(angle, units, wait);

Overload Usages:
Drivetrain.turnToHeading(angle, units, velocity, units_v, wait);

参数

描述

angle

将传动系统转向双头方向。

units

The unit that represents the rotational value:

  • degrees
  • turns

velocity

传动系统旋转的速度(以双精度浮点数表示)。如果未指定速度或速度之前已设置为#setturnvelocity,则默认速度为 50%。

units_v

The unit that represents the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

wait

Optional.

  • true (default) — The project waits until turnToHeading is complete before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for turnToHeading to finish.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Face the cardinal directions
  Drivetrain.turnToHeading(90, degrees);
  wait(1, seconds);
  Drivetrain.turnToHeading(180, degrees);
  wait(1, seconds);
  Drivetrain.turnToHeading(270, degrees);
  wait(1, seconds);
  Drivetrain.turnToHeading(0, degrees);
}

turnToRotation#

turnToRotation turns a smart drivetrain to a specified rotational value.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Default Usage:
Drivetrain.turnToRotation(angle, units, wait);

Overload Usages:
Drivetrain.turnToRotation(angle, units, velocity, units_v, wait);

参数

描述

angle

用于将传动系统转向的旋转值,以双精度浮点数表示。

units

The unit that represents the rotational value:

  • degrees
  • turns

velocity

传动系统旋转的速度(以双精度浮点数表示)。如果未指定速度或速度之前已设置为#setturnvelocity,则默认速度为 50%。

units_v

The unit that represents the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

wait

Optional.

  • true (default) — The project waits until turnToRotation is complete before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for turnToRotation to finish.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Turn left, then spin clockwise to face right
  Drivetrain.turnToRotation(-90, degrees);
  wait(1, seconds);
  Drivetrain.turnToRotation(450, degrees);
}

stop#

stop stops a drivetrain.

Default Usage:
Drivetrain.stop();

Overload Usages:
Drivetrain.stop(mode);

参数

描述

mode

The stopping behavior to use when the drivetrain stops:

  • brake — Stops immediately.
  • coast — Slows gradually to a stop.
  • hold — Stops and resists movement using motor feedback.
If the stopping mode is not specified or previously set, the default behavior is brake.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Drive forward, then coast to a stop
  Drivetrain.setDriveVelocity(100, percent);
  Drivetrain.drive(forward);
  wait(2, seconds);
  Drivetrain.stop(coast);
}

calibrateDrivetrain#

calibrateDrivetrain calibrates the drivetrain.

这是在“设备”窗口中配置驱动系统时,由 VEXcode 机器人配置程序生成的一个方法。它无法在 VEXcode V5 以外的版本中使用。

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.calibrateDrivetrain();

参数

描述

此方法没有参数。

arcade#

arcade moves the drivetrain forward or reverse while turning at the same time. This method runs continuously until another Drivetrain method interrupts it or the project stops.

Usage:
Drivetrain.arcade(drivePower, turnPower, units);

参数

描述

drivePower

前进或后退的速度值取两倍。正数表示前进,负数表示后退。

turnPower

向左或向右转弯的速度值,以双精度浮点数表示。正数表示向右转弯,负数表示向左转弯。

units

Optional. The unit that represents the power values:

  • percentUnits::pct — percent

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Drive forward and left for 2 seconds
  Drivetrain.arcade(25, -25);
  wait(2, seconds);
  Drivetrain.driveFor(forward, 12, inches);
}

变异体#

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);

参数

描述

velocity

传动系统作为双轴时的速度。

units

The unit that represents the velocity:

  • percent — percent
  • rpm — rotations per minute
  • dps — degrees per second

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Try default, slow, then fast
  Drivetrain.driveFor(forward, 150, mm);
  wait(1, seconds);
  Drivetrain.setDriveVelocity(20, percent);
  Drivetrain.driveFor(forward, 150, mm);
  wait(1, seconds);
  Drivetrain.setDriveVelocity(100, percent);
  Drivetrain.driveFor(forward, 150, mm);
}

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);

参数

描述

velocity

传动系统以双盘形式旋转时的速度。

units

The unit that represents the velocity:

  • percent — percent
  • rpm — rotations per minute
  • dps — degrees per second

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Try default, slow, then fast
  Drivetrain.turnFor(right, 360, degrees);
  wait(1, seconds);
  Drivetrain.setTurnVelocity(20, percent);
  Drivetrain.turnFor(right, 360, degrees);
  wait(1, seconds);
  Drivetrain.setTurnVelocity(100, percent);
  Drivetrain.turnFor(right, 360, degrees);
}

setStopping#

setStopping sets the stopping mode for a drivetrain.

Usage:
Drivetrain.setStopping(mode);

参数

描述

mode

How the drivetrain will stop:

  • brake — Stops immediately.
  • coast — Slows gradually to a stop.
  • hold — Stops and resists movement using motor feedback.

setTimeout#

setTimeout sets a time limit for how long a Drivetrain command will wait to reach its target. If the robot cannot complete the movement within the set time, it will stop automatically and continue with the next command.

注意: 传动系统的时限用于防止未到达目标位置的传动系统命令停止其他命令的执行。

Usage:
Drivetrain.setTimeout(time, units);

参数

描述

time

电机功能在停止并切换到下一个功能之前将运行的最大秒数(以整数表示)。

units

The unit that represents the time:

  • seconds
  • msec — milliseconds

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Start turning if drive took too long
  Drivetrain.setTimeout(1, seconds);
  Drivetrain.driveFor(forward, 25, inches);
  Drivetrain.turnFor(right, 90, degrees);
}

setHeading#

setHeading sets the heading of a smart drivetrain.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.setHeading(value, units);

参数

描述

value

新标题为双重标题。

units

The unit that represents the heading:

  • degrees
  • turns

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Face the new 0 degrees
  Drivetrain.setHeading(90, degrees);
  Drivetrain.turnToHeading(0, degrees);
}

setRotation#

setRotation sets the rotation for the smart drivetrain.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.setRotation(value, units);

参数

描述

value

新的旋转值,以双精度浮点数表示。

units

The unit that represents the rotation:

  • degrees
  • turns

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Spin counterclockwise for 2 turns, then face forward
  Drivetrain.setRotation(720, degrees);
  Drivetrain.turnToRotation(0, degrees);
}

setGearRatio#

setGearRatio sets the gear ratio for all motors on the drivetrain.

Usage:
Drivetrain.setGearRatio(mode);

参数

描述

mode

Gear Ratio options:

  • ratio1_1 — A gear unit that is defined as 1:1 gearing.
  • ratio2_1 — A gear unit that is defined as 2:1 gearing.
  • ratio3_1 — A gear unit that is defined as 3:1 gearing.

// Set 2:1 gear ratio
Drivetrain.setGearRatio(ratio2_1);

setTurnThreshold#

setTurnThreshold sets the turn threshold for a smart drivetrain. 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.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.setTurnThreshold(threshold);

参数

描述

threshold

The new turn threshold in degrees as a double. The default for a smart drivetrain is 1 degree.

// Increase turn threshold to 5 degrees
Drivetrain.setTurnThreshold(5);

setTurnConstant#

setTurnConstant sets the turn constant for a smart drivetrain. Smart drivetrains use 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.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.setTurnConstant(kp);

参数

描述

kp

新的转弯常数范围为 0.1–4.0。默认值为 1.0。

// Increase turn gain to 2.0
Drivetrain.setTurnConstant(2.0);

setTurnDirectionReverse#

setTurnDirectionReverse sets the smart drivetrain to be reversed.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.setTurnDirectionReverse(value);

参数

描述

value

A Boolean value to set the reversed flag to true or false.

setTurnVelocityMin#

setTurnVelocityMin sets the minimum turning velocity used by a drivetrain. This prevents the drivetrain from slowing below a minimum speed while turning, which helps avoid stalling or incomplete turns.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.setTurnVelocityMin(velocity);

参数

描述

velocity

最小转弯速度为双倍。

获取器#

isDone#

isDone returns a Boolean indicating whether driveFor, turnToHeading, turnToRotation, or turnFor is not running.

  • true — The drivetrain is not moving towards a target.

  • false — The drivetrain is moving towards a target.

Usage:
Drivetrain.isDone()

参数

描述

此方法没有参数。

isMoving#

isMoving returns a Boolean indicating whether driveFor, turnToHeading, turnToRotation, or turnFor is still running.

  • true — The drivetrain is moving towards a target.

  • false — The drivetrain is not moving towards a target.

Usage:
Drivetrain.isMoving()

参数

描述

此方法没有参数。

isTurning#

isTurning returns a Boolean indicating whether turnToHeading, turnToRotation, or turnFor is still running.

  • true — The drivetrain is currently rotating to a target.

  • false — The drivetrain is not currently rotating to a target.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.isTurning()

参数

描述

此方法没有参数。

heading#

heading returns the current heading of a smart drivetrain from 0–359.99 degrees as a double.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.heading(units)

参数

描述

units

Optional. The unit that represents the rotational value:

  • degrees (default)
  • turns

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Display heading after a long turn
  Drivetrain.turnFor(right, 450, degrees);
  Brain.Screen.print("Heading: %f", Drivetrain.heading(degrees));
}

rotation#

rotation returns the current rotational value of a smart drivetrain as a double.

注意: 仅当传动系统在“设备”窗口中配置了惯性传感器GPS 传感器陀螺仪传感器 时,此方法才可用。

Usage:
Drivetrain.rotation(units)

参数

描述

units

Optional. The unit that represents the rotational value:

  • degrees (default)
  • turns

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Display rotation after a long turn
  Drivetrain.turnFor(right, 450, degrees);
  Brain.Screen.print("Rotation: %f", Drivetrain.rotation(degrees));
}

velocity#

velocity returns the current velocity of a drivetrain as a double.

Usage:
Drivetrain.velocity(units)

参数

描述

units

The unit that represents the velocity:

  • percent
  • rpm — rotations per minute
  • dps — degrees per second

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Show velocity before and during motion
  Brain.Screen.print("Resting: %f", Drivetrain.velocity(percent));
  Drivetrain.drive(forward, 100, velocityUnits::pct);
  wait(1, seconds);
  Brain.Screen.newLine();
  Brain.Screen.print("Moving: %f", Drivetrain.velocity(percent));
  Drivetrain.stop();
}

current#

current returns the drivetrain’s current as a double.

Usage:
Drivetrain.current(units)

参数

描述

units

The unit that represents the current:

  • percent
  • amp (default)

power#

power returns the average power of the smart drivetrain as a double.

Usage:
Drivetrain.power(units)

参数

描述

units

The unit that represents the power:

  • watt

torque#

torque returns the average torque of the drivetrain as a double.

Usage:
Drivetrain.torque(units)

参数

描述

units

A valid torque Unit:

  • Nm (default) — newton meters
  • InLb — inch pounds

efficiency#

efficiency returns the average efficiency of the drivetrain as a double.

Usage:
Drivetrain.efficiency(units)

参数

描述

units

The unit that represents the efficiency:

  • percent

temperature#

temperature returns the average temperature of the drivetrain as a double.

Usage:
Drivetrain.temperature(units)

参数

描述

units

The unit that represents the temperature:

  • percent

voltage#

voltage returns the voltage currently applied to the drivetrain motors.

Usage:
Drivetrain.voltage(units)

参数

描述

units

The unit that represents the voltage:

  • volt

构造函数#

Constructors are used to manually create drivetrain and smartdrive objects, which are necessary for configuring a drivetrain outside of VEXcode.

drivetrain#

drivetrain creates a drivetrain without an Inertial Sensor, GPS Sensor, or Gyro Sensor.

Usage:
drivetrain(l, r, wheelTravel, trackWidth, wheelBase, unit, externalGearRatio);

范围

描述

l

左侧运动或运动组的名称。

r

右侧电机或电机组的名称。

wheelTravel

驱动轮周长取两倍。默认值为 320 毫米。

trackWidth

传动系统的轮距,以双精度浮点数表示。默认值为 320 毫米。

wheelBase

传动系统的轴距为双倍。默认值为130毫米。

unit

The units that represent wheelTravel, trackWidth and wheelBase:

  • mm (default) — millimeters
  • inches

externalGearRatio

当使用双速齿轮传动时,用于补偿传动距离的齿轮比。默认值为 1.0。

Note: Motors and/or motor groups must be created first before they can be used to create an object with the drivetrain constructor.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Create the motors
  motor leftMotor = motor(PORT1, false);
  motor rightMotor = motor(PORT2, true);

  /*
  Create a drivetrain with the following values:
  wheelTravel: 259.34
  trackWidth: 320
  wheelBase: 40
  units: MM
  externalGearRatio: 1
  */
  drivetrain Drivetrain = drivetrain(leftMotor, rightMotor, 259.34, 320, 40, mm, 1);
}

smartdrive#

smartdrive creates a drivetrain configured with an Inertial Sensor, GPS Sensor, or Gyro Sensor.

Usage:
smartdrive(lm, rm, guido, wheelTravel, trackWidth, wheelBase, unit, externalGearRatio);

范围

描述

lm

左侧运动或运动组的名称。

rm

右侧电机或电机组的名称。

guido

惯性传感器GPS传感器陀螺仪传感器的名称。

wheelTravel

驱动轮周长取两倍。默认值为 320 毫米。

trackWidth

传动系统的轮距,以双精度浮点数表示。默认值为 320 毫米。

wheelBase

传动系统的轴距为双倍。默认值为130毫米。

unit

The units that represent wheelTravel, trackWidth and wheelBase:

  • mm (default) — millimeters
  • inches

externalGearRatio

当使用双速齿轮传动时,用于补偿传动距离的齿轮比。默认值为 1.0。

Note: Motors and/or motor groups must be created first before they can be used to create an object with the smartdrive constructor.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Create the motors
  motor leftMotor = motor(PORT1, false);
  motor rightMotor = motor(PORT2, true);

  // Create an Inertial sensor in Port 3
  inertial myInertial = inertial(PORT3);

  /*
  Create a drivetrain with the following values:
  wheelTravel: 259.34
  trackWidth: 320
  wheelBase: 40
  units: MM
  externalGearRatio: 1
  */
  smartdrive Smartdrive = smartdrive(leftMotor, rightMotor, myInertial, 259.34, 320, 40, mm, 1);
}