传动系统#
介绍#
The drivetrain class provides control over a drivetrain using separate left and right motors or motor groups.
派生类#
The drivetrain class serves as a base class for the following derived classes:
smartdrive— This class adds Inertial Sensor, GPS Sensor, or Gyro Sensor support to enable heading-based and rotation-based turns.
类构造函数#
1 — This constructor constructs a drivetrain using references to existing
motor_groupinstances for the left (&l) and right (&r) sides.drivetrain( motor_group &l, motor_group &r, double wheelTravel = 320, double trackWidth = 320, double wheelBase = 130, distanceUnits unit = mm, double externalGearRatio = 1.0 );
2 — This constructor constructs a drivetrain using references to existing
motorinstances for the left (&l) and right (&r) sides.drivetrain( motor &l, motor &r, double wheelTravel = 320, double trackWidth = 320, double wheelBase = 130, distanceUnits unit = mm, double externalGearRatio = 1.0 );
类析构函数#
Destroys the drivetrain object and releases associated resources.
virtual ~drivetrain();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
References to existing |
|
|
The wheel’s circumference. Default is |
|
|
The distance between the left and right wheels. Default is |
|
|
The width of the wheel base. Default is |
|
|
Units for the
|
|
|
The gear ration compensation factor. Default is |
例子#
// Create the left and right motor instances
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);
// Create the drivetrain instance
drivetrain myDrivetrain = drivetrain(
leftMotor, // left motor instance
rightMotor, // right motor instance
259.34, // wheelTravel
320, // trackWidth
40, // wheelBase
mm, // unit
1.0 ); // externalGearRatio
成员功能#
The drivetrain class includes the following member functions:
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.stop— Stops the drivetrain using the configured stopping mode.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.isDone— Returns whether a drivetrain is not currently moving.isMoving— Returns whether a drivetrain is currently moving.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.
Before calling any drivetrain member functions, a drivetrain instance must be created, as shown below:
/* This constructor is required when using VS Code.
Drivetrain configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the left and right motor instances
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);
// Create the drivetrain instance
drivetrain myDrivetrain = drivetrain(
leftMotor, // left motor instance
rightMotor, // right motor instance
259.34, // wheelTravel
320, // trackWidth
40, // wheelBase
mm, // unit
1.0 ); // externalGearRatio
驾驶#
使传动系统沿指定方向持续运动。
Available Functions1 — 使用当前 配置的驱动速度 的驱动器。
void drive( directionType dir );
Parameters2 — 以指定速度行驶。
void drive( directionType dir, double velocity, velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The direction in which the robot drives:
|
|
|
传动系统运动的速度,以双精度浮点数表示。如果未指定速度或之前设置为速度为 ,则默认速度为 50%。 |
|
|
The unit to represent the velocity:
|
此函数不返回值。
Notesdriveis non-waiting; the project will continue executing the next line of code immediately after the call.The drivetrain will continue moving until
stopis called or another drivetrain movement function (such asdriveFororturn) is executed.Functions such as
isDoneandisMovingare not applicable todrive, since it does not use target-based movement (doesn’t have adistanceparameter).
// Drive forward and back
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.drive(reverse, 25, rpm);
wait(2, seconds);
myDrivetrain.stop();
驱动#
使传动系统沿指定方向移动指定距离,单位为指定单位。
Available Functions1 — 使用当前配置的行驶速度 沿指定方向行驶一段距离。
bool driveFor( directionType dir, double distance, distanceUnits units, bool waitForCompletion = true );
2 — 根据当前配置的行驶速度(#setdrivevelocity )沿距离方向行驶。
bool driveFor( double distance, distanceUnits units, bool waitForCompletion = true );
3 — 以指定的速度沿距离方向行驶。
bool driveFor( double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion = true );
Parameters4 — 以指定的速度沿指定方向行驶指定距离。
bool driveFor( directionType dir, double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion = true );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The direction in which the robot drives:
|
|
|
传动系统将移动的距离。 |
|
|
The units representing the distance:
|
|
|
传动系统运动的速度,以双精度浮点数表示。如果未指定速度或之前设置为速度为 ,则默认速度为 50%。 |
|
|
The unit to represent the velocity:
|
|
|
|
Returns a Boolean indicating whether the drivetrain reached the target distance parameter value:
true— The drivetrain successfully reaches the targetdistanceparameter value.false— The drivetrain does not complete the movement or if thewaitForCompletionparameter is set tofalse.
Executing another drivetrain movement function (such as
driveorturnFor) whiledriveForis in progress will interrupt the current movement.Because
driveForis target-based (uses adistanceparameter), functions such asisDoneandisMovingwork withdriveFor.
// Drive 200 mm, then back 200 mm
myDrivetrain.driveFor(forward, 200, mm);
myDrivetrain.driveFor(reverse, 200, mm);
转动#
使传动系统沿指定方向持续旋转。
Available Functions1 — 使用当前配置的转弯速度 进行转弯。
void turn( turnType dir );
Parameters2 — 以指定速度转弯。
void turn( turnType dir, double velocity, velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The direction in which the robot turns:
|
|
|
传动系统转速,以双精度浮点数表示。如果未指定转速或转速之前设置则默认转速为 50%。 |
|
|
The unit to represent the velocity:
|
turnis non-waiting; the project will continue executing the next line of code immediately after the call.The drivetrain will continue turning until
stopis called or another drivetrain movement function (such asturnForordrive) is executed.Functions such as
isDoneandisMovingare not applicable toturn, since it does not use target-based movement (doesn’t have anangleparameter).
// Turn right, then left, then stop
myDrivetrain.turn(right);
wait(2, seconds);
myDrivetrain.turn(left);
wait(2, seconds);
myDrivetrain.stop();
转向#
使传动系统沿指定方向旋转指定角度,单位为指定单位。
Available Functions1 — 使用当前配置的转弯速度 转弯指定的角度。
bool turnFor( double angle, rotationUnits units, bool waitForCompletion = true );
2 — 使用当前配置的转弯速度 沿指定方向转弯一定角度。
bool turnFor( turnType dir, double angle, rotationUnits units, bool waitForCompletion = true );
3 — 以指定的速度转指定的角度。
bool turnFor( double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion = true );
Parameters4 — 以指定的速度沿指定方向转弯指定角度。
bool turnFor( turnType dir, double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion = true );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The direction in which the robot turns:
|
|
|
传动系统转动的角度。 |
|
|
The units representing the angle:
|
|
|
传动系统转速,以双精度浮点数表示。如果未指定转速或转速之前设置则默认转速为 50%。 |
|
|
The unit to represent the velocity:
|
|
|
|
Returns a Boolean indicating whether the drivetrain reached the target angle parameter value:
true— The drivetrain successfully reaches the targetangleparameter value.false— The drivetrain does not complete the movement or if thewaitForCompletionparameter is set tofalse.
Executing another drivetrain movement function (such as
turnordrive) whileturnForis in progress will interrupt the current movement.Because
turnForis target-based (uses anangleparameter), functions such asisDoneandisMovingwork withturnFor.
// Turn right then left
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
myDrivetrain.turnFor(left, 90, degrees);
停止#
停止传动系统。
Available Functions1 — 使用当前配置的停止模式 停止传动系统。
void stop();
Parameters2 — 使用指定的制动模式停止传动系统。
void stop( brakeType mode );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The brake type to use when stopping the drivetrain:
|
此函数不返回值。
Examples// Drive forward, then coast to a stop
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);
设置驱动速度#
设置传动系统的默认驱动速度。
Available Functionsvoid setDriveVelocity(
double velocity,
velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
传动系统的运行速度。 |
|
|
The unit to represent the velocity:
|
此函数不返回值。
NotesThe drive velocity applies to all subsequent drivetrain movement functions (such as
driveanddriveFor) unless a specific velocity is provided in the function call.
// Drive forward, then coast to a stop
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);
设置转弯速度#
设置传动系统的默认转弯速度。
Available Functionsvoid setTurnVelocity(
double velocity,
velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
传动系统的转速。 |
|
|
The units representing the velocity:
|
此函数不返回值。
NotesThe turn velocity applies to all subsequent drivetrain turning functions (such as
turnandturnFor) unless a specific velocity is provided in the function call.
// Try default, slow, then fast
myDrivetrain.turnFor(right, 360, degrees);
wait(1, seconds);
myDrivetrain.setTurnVelocity(20, percent);
myDrivetrain.turnFor(right, 360, degrees);
wait(1, seconds);
myDrivetrain.setTurnVelocity(100, percent);
myDrivetrain.turnFor(right, 360, degrees);
设置停止#
设置传动系统的默认停止模式。
Available Functionsvoid setStopping(
brakeType mode );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The brake type to use when stopping the drivetrain:
|
此函数不返回值。
NotesThe stopping mode applies to all subsequent
stopcalls unless a specific stopping mode is provided in the function call.
设置超时#
设定传动系统尝试达到目标距离或角度的时间限制。如果传动系统无法在设定时间内完成动作,它将自动停止并继续执行下一个功能。
Available Functionsvoid setTimeout(
int32_t time,
timeUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The maximum number of seconds a |
|
|
The unit that represents the time:
|
此函数不返回值。
NotesThe timeout only applies to target-based drivetrain movement functions (such as
driveForandturnFor).
// Start turning if driving takes too long
myDrivetrain.setTimeout(1, seconds);
myDrivetrain.driveFor(forward, 25, inches);
myDrivetrain.turnFor(right, 90, degrees);
已完成#
Returns a Boolean indicating whether no target-based drivetrain movement (such as driveFor or turnFor) is currently in progress.
bool isDone( void );
此函数不接受任何参数。
Return Values返回一个布尔值,指示传动系统是否处于静止状态:
-
true— The drivetrain is not moving. -
false— The drivetrain is moving.
正在移动#
Returns a Boolean indicating whether the drivetrain is currently executing a target-based movement (such as driveFor or turnFor).
virtual bool isMoving( void );
此函数不接受任何参数。
Return Values返回一个布尔值,指示传动系统是否正在运转:
-
true— The drivetrain is moving. -
false— The drivetrain is not moving.
速度#
返回传动系统的速度。
Available Functionsdouble velocity(
velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units that represent the velocity:
|
Returns a double indicating the velocity of the drivetrain in the units specified by the units parameter.
// Show velocity before and during motion
Brain.Screen.print("Resting: %f", myDrivetrain.velocity(percent));
myDrivetrain.drive(forward, 100, velocityUnits::pct);
wait(1, seconds);
Brain.Screen.newLine();
Brain.Screen.print("Moving: %f", myDrivetrain.velocity(percent));
myDrivetrain.stop();
当前的#
返回传动系统正在使用的电流大小。
Available Functions1 — 返回传动系统的电流(以安培为单位)。
double current( currentUnits units = currentUnits::amp );
Parameters2 — 返回传动系统的电流占最大值的百分比。
double current( percentUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units that represent the current:
|
|
|
The units that represent the current:
|
Returns a double indicating the amount of electrical current the drivetrain is using in the units specified by the units parameter.
力量#
返回动力传动系统的功率消耗。
Available Functionsdouble power(
powerUnits units = powerUnits::watt );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units that represent the power:
|
返回一个双精度浮点数,表示传动系统的功率消耗(单位:瓦特)。
扭矩#
返回传动系统产生的扭矩。
Available Functionsdouble torque(
torqueUnits units = torqueUnits::nm );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units representing the torque:
|
Returns a double indicating the torque produced by the drivetrain in the units specified by the units parameter.
效率#
返回传动系统的效率。
Available Functionsdouble efficiency(
percentUnits units = percentUnits::pct );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units that represent the efficiency:
|
返回一个双精度浮点数,表示传动系统的效率(以百分比表示)。
温度#
返回传动系统所用电机的平均温度。
Available Functionsdouble temperature(
percentUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units that represent the temperature:
|
返回一个双精度浮点数,表示传动系统所用电机的平均温度百分比。
NotesA returned value of
50%indicates that the average motor temperature is approximately45°C(113°F).The typical operating temperature range for drivetrain motors is approximately
20°C(68°F) to70°C(158°F).
电压#
返回传动系统的电压。
Available Functionsdouble voltage(
voltageUnits units = voltageUnits::volt );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The units that represent the voltage:
|
Returns a double indicating the voltage of the drivetrain in the units specified by the units parameter.