傳動系統#
介紹#
drivetrain 類控制機器人的行駛與轉向方式。驅動系統由馬達和輪子組成,它們協同工作以驅動機器人移動。
drivetrain 不使用慣性感測器、陀螺儀感測器或GPS感測器進行基於航向或旋轉的轉向。它可以前進或後退,也可以左轉或右轉,但無法轉向特定的航向或旋轉角度。對於基於航向和旋轉的轉向,請使用smartdrive類別。
衍生類別#
drivetrain 類別作為以下衍生類別的基底類別:
smartdrive- 此類添加了慣性感測器、GPS 感測器或陀螺儀感測器支持,以實現基於航向和基於旋轉的轉彎。
類別建構函數#
1 - 使用現有的
motor_group物件為左側 (&l) 和右側 (&r) 建立傳動系統。drivetrain( motor_group &l, motor_group &r, double wheelTravel = 320, double trackWidth = 320, double wheelBase = 130, distanceUnits unit = mm, double externalGearRatio = 1.0 );
2 - 使用現有的
motor物件為左側 (&l) 和右側 (&r) 建立傳動系統。drivetrain( motor &l, motor &r, double wheelTravel = 320, double trackWidth = 320, double wheelBase = 130, distanceUnits unit = mm, double externalGearRatio = 1.0 );
類別析構函數#
銷毀 drivetrain 物件並釋放相關資源。
virtual ~drivetrain();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
左側和右側馬達或馬達組。兩個參數必須使用相同的類型:要么是兩個 |
|
|
傳動車輪的周長。預設值為 |
|
|
左右車輪之間的距離。預設值為 |
|
|
前輪和後輪之間的距離。預設值為 |
|
|
The unit for |
|
|
如果使用齒輪,則用於調整驅動距離的齒輪比。預設值為 |
例子#
// Create the left and right motor objects
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);
// Create the drivetrain object
drivetrain myDrivetrain = drivetrain(
leftMotor, // left motor object
rightMotor, // right motor object
259.34, // wheelTravel
320, // trackWidth
40, // wheelBase
mm, // unit
1.0 ); // externalGearRatio
成員功能#
drivetrain 類別包含以下成員函數:
操作 - 移動和轉向機器人。
drive- 使機器人無限向前或向後移動。driveFor- 使機器人向前或向後移動指定的距離。turn- 讓機器人永遠向左或向右轉。turnFor- 使機器人向左或向右旋轉指定的角度數。stop- 停止機器人的移動。
設定 - 調整傳動系統設定。
setDriveVelocity- 告訴機器人要以多快的速度行駛。setTurnVelocity- 告訴機器人轉彎的速度。setStopping- 說明機器人如何停止移動:透過煞車、滑行或保持。setTimeout- 設定機器人嘗試完成一次移動的秒數。
數值 - 檢查移動狀態。
isDone- 返回機器人是否已完成移動,以布林值表示。isMoving- 傳回機器人是否正在移動,以布林值表示。velocity- 返回機器人行駛的速度。current- 傳回傳動系統正在使用的電流大小。power- 返回傳動系統使用能量的速度。torque- 返回傳動系統正在使用的扭矩大小。efficiency- 返回傳動系統使用動力的效率。temperature- 傳回傳動系統的溫度。voltage- 傳回提供給傳動系統的電壓。
在呼叫 drivetrain 函數之前,必須先建立一個 drivetrain ,如下所示:
/* 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 objects
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);
// Create the drivetrain object
drivetrain myDrivetrain = drivetrain(
leftMotor, // left motor object
rightMotor, // right motor object
259.34, // wheelTravel
320, // trackWidth
40, // wheelBase
mm, // unit
1.0 ); // externalGearRatio
行動#
駕駛#
drive 使機器人無限前進或後退。機器人將持續移動,直到收到其他指令,例如轉向或停止。對於轉速 (RPM) 或每秒輸出次數 (DPS),其限制值會根據傳動系統的齒輪比而變化。
1 - 使用目前配置的驅動速度驅動。
void drive( directionType dir );
Parameters2 - 以指定速度行駛。
void drive( directionType dir, double velocity, velocityUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
機器人移動方向: |
|
|
當使用 |
|
|
速度單位: |
此函數不傳回值。
Notes Examples// Drive forward and back
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.drive(reverse, 25, rpm);
wait(2, seconds);
myDrivetrain.stop();
驅動#
driveFor 指令使機器人前進或後退指定距離。預設情況下,程式會等待機器人完成移動後才執行下一行程式碼。對於轉速 (RPM) 或每秒行程 (DPS),限制值會根據傳動系統的齒輪比而變化。
1 - 使用目前配置的行駛速度 沿著指定方向行駛一段距離。
bool driveFor( directionType dir, double distance, distanceUnits units, bool waitForCompletion = true );
2 - Drives in a direction dependent on the distance using the currently configured drive velocity.
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 );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
機器人移動方向: |
|
|
機器人行駛的距離。 |
|
|
距離單位: |
|
|
當使用 |
|
|
速度單位: |
|
|
|
返回機器人是否達到目標距離,以布林值表示。
true- 機器人已達到目標距離。false- 機器人沒有完成移動,或函數在移動完成之前返回,因為waitForCompletion設定為false。
// Drive 200 mm, then back 200 mm
myDrivetrain.driveFor(forward, 200, mm);
myDrivetrain.driveFor(reverse, 200, mm);
轉動#
turn 表示機器人無限向左或向右轉向。機器人會一直轉向,直到收到其他指令,例如行駛或停止。對於轉速 (RPM) 或每秒輸出功率 (DPS),其限制值會根據傳動系統的齒輪比而變化。
1 - 使用目前配置的轉彎速度 進行轉彎。
void turn( turnType dir );
Parameters2 - 以指定速度轉彎。
void turn( turnType dir, double velocity, velocityUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
機器人轉向的方向: |
|
|
使用 |
|
|
速度單位: |
// Turn right, then left, then stop
myDrivetrain.turn(right);
wait(2, seconds);
myDrivetrain.turn(left);
wait(2, seconds);
myDrivetrain.stop();
轉向#
turnFor 使機器人向左或向右旋轉指定角度。旋轉角度相對於機器人的當前位置。預設情況下,程式會等待機器人完成旋轉後才執行下一行程式碼。對於 RPM 或 DPS,限制值會根據傳動系統的齒輪比而變化。
1 - 使用目前配置的轉彎速度 轉彎指定的角度。
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 );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
機器人轉向的方向: |
|
|
機器人的轉彎角度。 |
|
|
旋轉單位: |
|
|
使用 |
|
|
速度單位: |
|
|
|
返回機器人是否達到目標角度,以布林值表示。
true- 機器人達到目標角度。false- 機器人沒有完成回合,或函數在回合完成前返回,因為waitForCompletion設定為false。
// Turn right then left
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
myDrivetrain.turnFor(left, 90, degrees);
停止#
stop 停止機器人的運動。如果提供了停止模式,則控制機器人在此函數呼叫中如何停止。
1 - 使用目前配置的停止模式 停止傳動系統。
void stop();
Parameters2 - 使用指定的煞車模式停止傳動系統。
void stop( brakeType mode );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
How the robot will stop:
|
此函數不傳回值。
Examples// Drive forward, then coast to a stop
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);
突變體#
設定驅動速度#
setDriveVelocity 告訴機器人行駛速度。百分比越高,機器人行駛速度越快;百分比越低,機器人行駛速度越慢。對於轉速(RPM),其限制值取決於傳動系統的齒輪比。
每個專案開始時,機器人預設以 50% 的速度行駛。
注意:速度越高,機器人行駛速度越快,但精度可能越低;速度越低,機器人行駛速度越慢,但精度可能越高。
Available Functionsvoid setDriveVelocity(
double velocity,
velocityUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
使用 |
|
|
速度單位: |
此函數不傳回值。
Notes Examples// Drive forward, then coast to a stop
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);
設定轉彎速度#
setTurnVelocity 告訴機器人轉彎的速度。百分比越高,機器人轉彎越快;百分比越低,機器人轉彎越慢。
每個專案開始時,機器人預設以 50% 的速度旋轉。
注意:速度越高,機器人轉彎越快,但精度可能越低;速度越低,機器人轉彎越慢,但精度可能越高。
Available Functionsvoid setTurnVelocity(
double velocity,
velocityUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
使用 |
|
|
速度單位: |
此函數不傳回值。
Notes Examples// 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);
設定停止#
setStopping 設定機器人停止移動的方式:透過煞車、滑行或保持。
void setStopping(
brakeType mode );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
How the robot will stop:
|
此函數不傳回值。
Notes除非在函數呼叫中提供特定的停止模式,否則停止模式適用於所有後續的
stop呼叫。
設定超時#
setTimeout 設定機器人嘗試完成一個動作的秒數。如果機器人無法在規定時間內完成,它將停止嘗試並執行下一行程式碼。這可以防止機器人卡在某個動作上。
void setTimeout(
int32_t time,
timeUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
機器人嘗試完成一次動作的時間。該值應為正整數。 |
|
|
時間單位: |
此函數不傳回值。
Notes Examples// Start turning if driving takes too long
myDrivetrain.setTimeout(1, seconds);
myDrivetrain.driveFor(forward, 25, inches);
myDrivetrain.turnFor(right, 90, degrees);
獲取器#
已完成#
isDone 返回機器人是否已完成移動,結果為布林值。這可用於根據機器人的移動狀態控制其他行為的執行時間。
bool isDone( void );
此函數不接受任何參數。
Return Valuestrue- 機器人已停止移動。false- 機器人仍在移動。
正在移動#
isMoving 返回機器人是否正在移動,以布林值表示。這可用於根據機器人的移動狀態控制其他行為的執行時間。
virtual bool isMoving( void );
此函數不接受任何參數。
Return Valuestrue- 機器人正在移動。false- 機器人沒有移動。
速度#
velocity 返回機器人行駛的速度。
正值表示機器人向前行駛,負值表示機器人向後行駛。
Available Functionsdouble velocity(
velocityUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
速度單位: |
傳回所選單位的傳動系統速度,數值為 double (雙精度浮點數)。
// 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();
目前的#
current 返回動力傳動系統正在使用的電流大小。電流是指流經動力傳動系統的電量。根據單位不同,電流值可以以安培 (A) 或百分比的形式傳回。
電流值越高,代表驅動系統消耗的電流越大。這種情況可能發生在機器人推擠物體或卡住後試圖移動時。
這可以用來檢查傳動系統在運動過程中是否運作吃力。如果電流持續偏高,傳動系統可能會發熱或動力利用效率降低。
Available Functions1 - 傳回傳動系統的電流(以安培為單位)。
double current( currentUnits units = currentUnits::amp );
Parameters2 - 返回傳動系統的電流佔最大值的百分比。
double current( percentUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
返回電流的單位: |
|
|
返回電流的單位: |
返回所選單位的傳動系統電流,數值為 double。
力量#
power 返回傳動系統正在使用的功率,單位為瓦特。功率值表示傳動系統消耗能量的速度。
功率值越高,代表驅動系統消耗能量的速度越快。這種情況可能發生在機器人推擠物體或卡住後試圖移動時。
這可以用來比較不同的運動軌跡,或是檢查傳動系統是否運作吃力。如果功率持續偏高,傳動系統可能會過熱或能量利用效率降低。
Available Functionsdouble power(
powerUnits units = powerUnits::watt );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
功率單位: |
以瓦特為單位返回傳動系統功率( double。
扭力#
扭力表示傳動系統在車輪旋轉時能夠施加多大的推力或拉力。
torque 返回傳動系統使用的扭矩大小,以牛頓米 (Nm) 或英寸磅 (InLb) 為單位測量。
扭力值越高,表示傳動系統需要更大的推力或拉力。這種情況可能發生在機器人推擠物體或卡住後試圖移動時。
這可以用來檢查傳動系統是否運作不暢,或是比較不同動作所需的推力大小。
Available Functionsdouble torque(
torqueUnits units = torqueUnits::nm );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
返回扭力的單位: |
返回所選單位的傳動系統扭矩,數值為 double。
效率#
efficiency 返回動力傳動系統使用動力的效率,以百分比表示,範圍從 0% 到 100%。
效率值反映了傳動系統有多少動力被用於運動。效率值越高,代表傳動系統用於運動的動力越多。當傳動系統高負載運轉但運動量不大時,例如機器人被卡住或抵擋物體時,效率值會降低。
這可以用來比較運動情況,或者檢查傳動系統是否浪費動力而不是將其用於運動。
Available Functionsdouble efficiency(
percentUnits units = percentUnits::pct );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
傳回效率的單位: |
傳回所選單位的傳動系統效率,數值為 double。
溫度#
temperature 傳回傳動系統的平均溫度,以百分比表示,範圍從 0% 到 100%。
溫度顯示傳動系統馬達的溫度。溫度越高,代表馬達在工作過程中溫度越高。為了保持最佳性能,馬達溫度應保持在 55°C 以下。
如果馬達過熱,它們會降低最大電流以保護自身。當溫度達到 70°C 時,馬達將停止運轉,直到冷卻。
這可以用來檢查傳動系統在重複運動、長時間運作或推動物體時是否過熱。
Available Functionsdouble temperature(
percentUnits units );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
返回溫度的單位: |
傳回所選單位的平均傳動系統溫度,數值為 double。
返回值
50%表示平均馬達溫度約為45°C(113°F)。傳動系統的典型工作溫度範圍約為
20°C(68°F) 至70°C(158°F)。
電壓#
voltage 返回輸送至傳動系統的電壓。
電壓是指輸送至傳動系統馬達的電壓力。結合電流和功率值,我們可以了解傳動系統如何利用電能。
Available Functionsdouble voltage(
voltageUnits units = voltageUnits::volt );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
回傳電壓的單位: |
傳回所選單位的傳動系統電壓,數值為 double。