传动系统#
初始化传动系统类#
使用以下构造函数创建动力传动系统:
drivetrain
构造函数创建一个 drivetrain 对象。
范围 |
描述 |
---|---|
|
|
|
|
|
驱动轮的周长。默认值为 300 毫米。 |
|
传动系统的轮距。默认值为 320 毫米。 |
|
传动系统的轴距。默认值为 320 毫米。 |
|
对于 wheelTravel、trackWidth 和 wheelBase 指定的单位,有效的 distanceUnit。默认值为“mm”。 |
|
如果使用齿轮传动,则电机的 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);
当引用传动系统类方法时,此“Drivetrain”对象将在整个 API 文档的所有后续示例中使用。
要在您的动力传动系统中加入 惯性传感器 或 陀螺仪传感器 以增强转弯功能,您可以在使用 smartdrive 类构造函数创建对象时将其包含在内。
类方法#
驾驶()#
这是一种非等待方法,允许下一个方法无延迟运行。
该方法通过以下方式调用:
drive(dir)
方法用于以 setDriveVelocity()
方法指定的默认速度永远沿指定方向驱动传动系统,直到使用另一种传动系统运动方法或项目停止。
参数 |
描述 |
---|---|
目录 |
有效的 DirectionType。 |
**返回:**无。
// Drive the drivetrain forward.
Drivetrain.drive(forward);
drive(dir, speed, units)
方法用于以指定的速度永远驱动传动系统沿指定方向运动,直到使用另一种传动系统运动方法或项目停止。
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
速度 |
传动系统移动的速度。 |
单位 |
有效的 velocityUnit。 |
**返回:**无。
// Drive the drivetrain forward at 100 rpm.
Drivetrain.drive(forward, 100, rpm);
驱动()#
这可以是等待或非等待方法,取决于是否使用了waitForCompletion
参数。
该方法通过以下方式调用:
driveFor(distance, units, waitForCompletion)
方法用于以默认速度驱动传动系统行驶指定距离。
参数 |
描述 |
---|---|
距离 |
传动系统移动的距离。 |
单位 |
有效的 DistanceUnit。默认值为“英寸”。 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已达到目标距离。
// Drive the drivetrain for 10 inches.
Drivetrain.driveFor(10, inches);
driveFor(dir, distance, units, waitForCompletion)
方法用于以默认速度沿指定方向驱动传动系统行驶指定距离。
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
距离 |
传动系统移动的距离。 |
单位 |
有效的 distanceUnit。默认值为“英寸”。 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已达到目标距离。
// Drive the drivetrain forward for 10 inches.
Drivetrain.driveFor(forward, 10, inches);
driveFor(distance, units, speed, units_v, waitForCompletion)
方法用于以默认速度驱动传动系统行驶指定距离。
参数 |
描述 |
---|---|
距离 |
传动系统移动的距离。 |
单位 |
有效的 distanceUnit。默认值为“英寸”。 |
速度 |
传动系统的移动速度。如果未提供,则使用 |
单位 |
有效的 velocityUnit。默认值为 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已达到目标距离。
// Drive the drivetrain for 10 inches at 100 rpm.
Drivetrain.driveFor(10, inches, 100, rpm);
driveFor(dir, distance, units, speed, units_v, waitForCompletion)
方法用于以默认速度驱动传动系统行驶指定距离。
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
距离 |
传动系统移动的距离。 |
单位 |
有效的 distanceUnit。默认值为“英寸”。 |
速度 |
传动系统的移动速度。如果未提供,则使用 |
单位 |
有效的 velocityUnit。默认值为 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已达到目标距离。
// Drive the drivetrain forward for 10 inches at 100 rpm.
Drivetrain.driveFor(forward, 10, inches, 100, rpm);
转动()#
这是一种非等待方法,允许下一个方法无延迟运行。
该方法通过以下方式调用:
turn(dir)
方法用于以 setTurnVelocity()
方法指定的默认速度将机器人转向指定方向,直到使用另一种传动系统运动方法或项目停止。
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
**返回:**无。
// Turn the drivetrain right.
Drivetrain.turn(right);
turn(dir, speed, units)
方法用于以指定的速度将机器人转向指定的方向,直到使用另一种传动系统运动方法,或者项目停止。
参数 |
描述 |
---|---|
目录 |
有效的 directionType。 |
速度 |
传动系统的转动速度。如果未提供,则使用 |
单位 |
有效的 velocityUnit。默认值为 |
**返回:**无。
// Turn the drivetrain right at 100 rpm.
Drivetrain.turn(right, 100, rpm);
turnFor()#
这可以是等待或非等待方法,取决于是否使用了waitForCompletion
参数。
该方法通过以下方式调用:
The turnFor(angle, units, waitForCompletion)
turns the drivetrain for a specified angle or rotations at the default velocity as specified by the setTurnVelocity()
method.
参数 |
描述 |
---|---|
角度 |
传动系统转动的角度。 |
单位 |
有效的 rotationUnit。默认值为“度”。 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已转到目标角度。
// 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。 |
角度 |
传动系统转动的角度。 |
单位 |
有效的 rotationUnit。默认值为“度”。 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已转到目标角度。
// 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.
参数 |
描述 |
---|---|
角度 |
传动系统转动的角度。 |
单位 |
有效的 rotationUnit。默认值为“度”。 |
速度 |
传动系统的转动速度。如果未提供,则使用 |
单位 |
有效的 velocityUnit。默认值为 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已转到目标角度。
// 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。 |
角度 |
传动系统转动的角度。 |
单位 |
有效的 rotationUnit。默认值为“度”。 |
速度 |
传动系统的转动速度。如果未提供,则使用 |
单位 |
有效的 velocityUnit。默认值为 |
等待完成 |
确定命令是否阻止后续命令( |
**返回:**一个布尔值,表示传动系统是否已转到目标角度。
// Turn the drivetrain right for 90 degrees at 100 rpm.
Drivetrain.turnFor(right, 90, degrees, 100, rpm);
停止()#
这是一个非等待命令,允许下一个命令无延迟运行。
该方法通过以下方式调用:
stop()
命令用于停止传动系统,将传动系统速度设置为 0,并配置当前停止模式。默认制动类型为“滑行”,除非之前使用 setStopping()
命令进行了更改。
**返回:**无。
// Spin Drivetrain for 2.5 seconds.
Drivetrain.spin(forward);
wait(2.5 seconds);
// Stop Drivetrain.
Drivetrain.stop();
stop(mode)
命令用于使用特定的制动类型停止传动系统。
参数 |
描述 |
---|---|
模式 |
有效的 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()
命令将返回。
**返回:**如果任何传动系统电机已打开并旋转至目标,则返回“true”。如果已旋转至目标,则返回“false”。
完成()#
如果所有传动系统电机都已旋转至特定目标,则 isDone()
命令将返回。
**返回:**如果所有传动系统电机都已完成旋转至目标,则返回“true”。如果任何传动系统电机已开启并旋转至目标,则返回“false”。
设置驱动速度()#
setDriveVelocity(velocity, units)
方法用于设置传动系统的默认速度。此速度设置会影响所有后续的驱动方法,除非这些方法中提供了具体的速度。
参数 |
描述 |
---|---|
速度 |
为传动系统设置的新速度为默认速度。 |
单位 |
有效的 velocityUnit 或 |
**返回:**无。
// Set the drivetrain to drive at a velocity of 200 rpm.
Drivetrain.setDriveVelocity(200, rpm);
设置转弯速度()#
setTurnVelocity(velocity, units)
方法用于设置传动系统中转弯操作的默认速度。此设置指定传动系统执行转弯方法的速度,除非该方法中设置了特定速度。
参数 |
描述 |
---|---|
速度 |
设置为转弯操作默认的新速度。 |
单位 |
有效的 velocityUnit 或 |
**返回:**无。
// Set the drivetrain to turn at a velocity of 200 RPM.
Drivetrain.setTurnVelocity(200, rpm);
设置停止()#
setStopping(mode)
方法用于设置传动系统上所有电机的停止模式。此设置决定了电机在收到停止方法或速度设置为零时的行为。
参数 |
描述 |
---|---|
模式 |
有效的 brakeType。 |
**返回:**无。
// Set the stopping mode to BRAKE.
Drivetrain.setStopping(brake);
设置齿轮比()#
setGearRatio(mode)
方法用于设置传动系统上所有电机的齿轮比。
参数 |
描述 |
---|---|
模式 |
有效的 gearSetting。 |
**返回:**无。
设置超时()#
Drivetrain.setTimeout(time, units) 方法用于设置传动系统上所有电机的超时值。此设置决定了如果电机尚未完成运动,传动系统将在超时前尝试执行 driveFor 或 turnFor 方法的时间。
参数 |
描述 |
---|---|
暂停 |
设置为动力传动系统操作默认的超时持续时间。 |
单位 |
有效的 timeUnit 类型。默认值为 |
**返回:**无。
// Set the timeout for the drivetrain to 10 seconds.
Drivetrain.setTimeout(10, seconds);
速度()#
velocity(units)
方法返回传动系统的平均速度。
参数 |
描述 |
---|---|
单位 |
有效的 velocityUnit 或 |
**返回:**以指定单位表示传动系统速度的双精度数。
当前的()#
current()
方法返回传动系统的平均电流。
参数 |
描述 |
---|---|
单位 |
电流的唯一有效单位是“安培”或“百分比”。 |
**返回:**以指定单位表示动力传动系统电流的双精度数。
电压()#
volt(units)
方法返回传动系统的平均速度。
参数 |
描述 |
---|---|
单位 |
有效的 voltUnit。默认值为 |
**返回:**以指定单位表示动力传动系统电压的双精度数。
力量()#
power(units)
方法返回传动系统的平均功率。
参数 |
描述 |
---|---|
单位 |
功率的唯一有效单位是“瓦特”。 |
**返回:**以指定单位表示动力传动系统功率的双精度数。
扭矩()#
torque(units)
方法返回传动系统的平均扭矩。
参数 |
描述 |
---|---|
单位 |
有效的 torqueUnit。默认值为 |
**返回:**以指定单位表示传动系统扭矩的双精度数。
效率()#
efficiency(units)
方法返回传动系统的平均效率。
参数 |
描述 |
---|---|
单位 |
效率的唯一有效单位是“百分比”。 |
**返回:**以提供的单位表示传动系统效率的双精度值。
温度()#
temp(units)
方法返回传动系统的平均温度。
参数 |
描述 |
---|---|
单位 |
温度的唯一有效单位是“百分比”。 |
**返回:**以提供的单位表示动力传动系统温度的双精度值。