スマートドライブ#

導入#

smartdrive クラスは、モーター、車輪、センサーを使用してロボットの走行と旋回を制御します smartdrive 、慣性センサー または ジャイロセンサー を使用して、方位と回転を追跡できます。

smartdrive センサーを使用して、ロボットの正確な移動と旋回を支援します。各プロジェクトの開始時に、ドライブトレインはセンサーを自動的にキャリブレーションします。キャリブレーション中はロボットを約2秒間静止させてください。そうすることで、ロボットが正しく移動および旋回できるようになります。

smartdrive クラスは drivetrain クラスに基づいています。 drivetrain と同じドライブおよびターン機能を使用でき、 turnToHeading や turnToRotationのようなセンサーベースの機能も追加されています。

クラスコンストラクタ#

1 — 左側 (&l) と右側 (&r) の既存の motor_group オブジェクトと慣性センサーまたはジャイロセンサーを使用してスマートドライブを作成します。

smartdrive(
    motor_group     &l,
    motor_group     &r,
    inertial        &g,
    double          wheelTravel = 320,
    double          trackWidth  = 320,
    double          wheelBase   = 130,
    distanceUnits   unit = mm,
    double          externalGearRatio = 1.0 );

2 — 左側 (&l) と右側 (&r) の既存の motor オブジェクトと慣性センサーまたはジャイロセンサーを使用してスマートドライブを作成します。

smartdrive(
    motor           &l,
    motor           &r,
    inertial        &g,
    double          wheelTravel = 320,
    double          trackWidth  = 320,
    double          wheelBase   = 130,
    distanceUnits   unit = mm,
    double          externalGearRatio = 1.0 );

クラスデストラクタ#

smartdrive オブジェクトを破棄し、関連するリソースを解放します。

~smartdrive();

パラメータ#

センサーパラメータは、 inertial または gyro オブジェクトのいずれかです。

パラメータ

タイプ

説明

&l / &r

motor_group / motor

既存の motor または motor_group インスタンスへの参照。両方のパラメータは同じ型である必要があります。つまり、2 つの motor_group インスタンスまたは 2 つの motor インスタンスのいずれかです。8 &l パラメータは左モーターまたはモーターグループを参照し、 &r は右モーターまたはモーターグループを参照します。

&g

gyro&

既存の gyro または inertial インスタンスへの参照。

wheelTravel

double

駆動輪の円周。デフォルト値は 320です。

trackWidth

double

左右の車輪間の距離。デフォルト値は 320です。

wheelBase

double

前輪と後輪の間の距離。デフォルト値は 130です。

unit

distanceUnits

The unit for wheelTravel, trackWidth, and wheelBase: mm (millimeters, default) or inches.

externalGearRatio

double

ギアを使用する場合に、駆動距離を調整するために使用されるギア比。デフォルト値は 1.0です。

例#

/* 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 inertial instance
inertial myInertial = inertial(PORT3);

// Create the smartdrive instance
smartdrive myDrivetrain = smartdrive(
    leftMotor,  // left motor object
    rightMotor, // right motor object
    myInertial, // inertial object
    259.34,     // wheelTravel
    320,        // trackWidth
    40,         // wheelBase
    mm,         // unit
    1.0 );      // externalGearRatio

メンバーの機能#

smartdrive クラスには、以下のメンバ関数が含まれています。

操作 — 方位角または回転を使用してロボットを旋回させる。

設定 — 方位と回転の値を調整します。

  • setHeading — ロボットの現在の進行方向を新しい進行方向に変更します。

  • setRotation — ロボットの現在の回転を新しい回転に変更します。

値 — 方位と回転を確認してください。

  • heading — ロボットの現在の方位を0度から359度の範囲で返します。

  • rotation — ロボットの現在の回転を返します。

smartdrive 、drivetrain から継承したメンバ関数、例えば drive、 driveFor、 turn、 turnFor、 stop、 isDone、および isMovingを使用することもできます。

smartdrive メンバ関数を呼び出す前に、以下に示すように smartdrive インスタンスを作成する必要があります。

/* 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 inertial instance
inertial myInertial = inertial(PORT3);

// Create the smartdrive instance
smartdrive myDrivetrain = smartdrive(
    leftMotor,  // left motor object
    rightMotor, // right motor object
    myInertial, // inertial object
    259.34,     // wheelTravel
    320,        // trackWidth
    40,         // wheelBase
    mm,         // unit
    1.0 );      // externalGearRatio

turnToHeading#

方位とは、ロボットが向いている方向のことで、度数で表されます。0 turnToHeading は ロボットを-359度から359度までの特定の方位に向けます。ロボットは、目標の方位に到達するために最短の方向へ旋回します。

ロボットの初期進行方向は0度です。

プロジェクトは、ロボットの旋回が完了するまで待機し、その後次のコードが実行されます。

Available Functions

1 — Turns the drivetrain to the specified heading using the currently configured turn velocity.

bool turnToHeading(
    double        angle,
    rotationUnits units,
    bool          waitForCompletion = true );

2 — 指定された速度で駆動系を指定された方向へ向けます。

bool turnToHeading(
    double        angle,
    rotationUnits units,
    double        velocity,
    velocityUnits units_v,
    bool          waitForCompletion = true );

Parameters

パラメータ

タイプ

説明

angle

double

ロボットが向くべき方向(度数)。0 deg または degrees使用する場合は、-359から359までの範囲になります。

units

rotationUnits

回転単位: deg (度)、 rev (回転)、または raw (単位)。1回転は360度に相当します。

velocity

double

The velocity to turn with from 0% to 100% when using velocityUnits::pct, from 0 to 600 rpm when using rpm, or from 0 to 3600 degrees per second when using dps. If no velocity is provided, the robot turns at the current turn velocity.

units_v

velocityUnits

速度の単位: velocityUnits::pct (パーセント)、 rpm (1分あたりの回転数)、または dps (1秒あたりの角度)。

waitForCompletion

bool

true (デフォルト) は、ロボットの回転が完了するまで次のコード行の実行を待機します。 false 、次のコード行をすぐに実行します。

Return Values

ロボットが目標の進行方向に到達したかどうかをブール値で返します。

  • true — ロボットは目標の進行方向に到達しました。

  • false — ロボットが旋回を完了しなかったか、 false が waitForCompletionに設定されたため、旋回が完了する前に関数が戻りました。

Notes
  • turnToHeading が進行中に、別の駆動系移動機能 (turn や drive など) を実行すると、現在の移動が中断されます。

  • turnToHeading はターゲットベース ( angle パラメータを使用) なので、isDone や isMoving などの関数は turnToHeadingで動作します。

Examples
// Face the new 0 degrees
myDrivetrain.setHeading(90, degrees);
myDrivetrain.turnToHeading(0, degrees);

turnToRotation#

turnToRotation はロボットを特定の回転方向に回転させます。

回転とは、ロボットがどれだけ回転したかを示すもので、度または回転数で測定されます。プロジェクトの開始時には、回転値は0度に設定されます。回転は、setRotation 関数を使用して設定することもできます。

回転値は絶対値です。つまり、旋回方向はロボットの現在の回転角度によって決まります。右に旋回すると回転角度が大きくなり、左に旋回すると回転角度が小さくなります。

例えば、ロボットが0度の位置から始まり、720度回転させると、右に2回転します。次に360度回転させると、360度は720度より小さいため、左に1回転します。

プロジェクトは、ロボットの旋回が完了するまで待機し、その後次のコードが実行されます。

Available Functions

1 — Turns the drivetrain to the specified rotation using the currently configured turn velocity.

bool turnToRotation(
    double        angle,
    rotationUnits units,
    bool          waitForCompletion = true );

2 — ドライブトレインを、指定された回転方向と速度に回転させます。

bool turnToRotation(
    double        angle,
    rotationUnits units,
    double        velocity,
    velocityUnits units_v,
    bool          waitForCompletion = true );

Parameters

パラメータ

タイプ

説明

angle

double

ロボットが回転する回転値。

units

rotationUnits

回転単位: deg (度)、 rev (回転)、または raw (単位)。1回転は360度に相当します。

velocity

double

The velocity to turn with from 0% to 100% when using velocityUnits::pct, from 0 to 600 rpm when using rpm, or from 0 to 3600 degrees per second when using dps. If no velocity is provided, the robot turns at the current turn velocity.

units_v

velocityUnits

速度の単位: velocityUnits::pct (パーセント)、 rpm (1分あたりの回転数)、または dps (1秒あたりの角度)。

waitForCompletion

bool

true (デフォルト) は、ロボットの回転が完了するまで次のコード行の実行を待機します。 false 、次のコード行をすぐに実行します。

Return Values

ロボットが目標の回転位置に到達したかどうかをブール値で返します。

  • true — ロボットは目標の回転位置に到達しました。

  • false — ロボットが旋回を完了しなかったか、 false が waitForCompletionに設定されたため、旋回が完了する前に関数が戻りました。

Notes
  • turnToRotation が進行中に、別の駆動系動作機能 (turn や drive など) を実行すると、現在の動作が中断されます。

  • turnToRotation ターゲットベース ( angle パラメータを使用) なので、isDone や isMoving などの関数は turnToRotationで動作します。

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

calibrateDrivetrain#

calibrateDrivetrain は、スマートドライブで構成された慣性センサーまたはジャイロセンサーを較正します。

キャリブレーションは、センサーが動きを正確に測定するために役立ちます。キャリブレーション中は、ロボットを約2秒間静止させてください。キャリブレーション中にロボットが動くと、センサーが動きを正確に測定できない場合があります。

プロジェクトは、キャリブレーションが完了するまで次のコード行の実行を待ちます。

calibrateDrivetrain 、ドライブトレインに慣性センサーまたはジャイロセンサーが設定されている場合に VEXcode によって自動的に生成されます。これはプロジェクトソースの一部として提供され、VEX EXP C++ API の一部ではありません。

Available Functions
void calibrateDrivetrain();

Parameters

この関数は引数を受け付けません。

Return Values

この関数は値を返しません。

Notes
  • ロボットは各プロジェクトの開始時に自動的にキャリブレーションを行います。

  • キャリブレーション中は、ロボットを約2秒間静止させてください。

Function Implementation

以下は、VEXcodeによって自動生成された calibrateDrivetrain の実装です。

bool vexcode_initial_drivetrain_calibration_completed = false;
void calibrateDrivetrain() {
  wait(200, msec);
  Brain.Screen.print("Calibrating");
  Brain.Screen.newLine();
  Brain.Screen.print("Inertial");
  DrivetrainInertial.calibrate();
  while (DrivetrainInertial.isCalibrating()) {
    wait(25, msec);
  }
  vexcode_initial_drivetrain_calibration_completed = true;
  // Clears the screen and returns the cursor to row 1, column 1.
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
}

setHeading#

方位とは、ロボットが向いている方向のことで、度数で表されます。0 setHeading は ロボットの現在の方位を新しい方位値に変更します。

例えば、ロボットが右を向いた場合、方位を0度に設定すると、その右向きの位置が新たな0度になります。その後、ロボットはその新たな方位に基づいて他の位置に旋回することができます。

Available Functions
void  setHeading(
  double value,
  rotationUnits units);

Parameters

パラメータ

タイプ

説明

value

double

ロボットに設定する方位値。0 deg または degrees使用する場合は、-359から359までの範囲になります。

units

rotationUnits

見出しの単位は、 deg (度)、 rev (回転)、または raw (単位) です。1回転は360度に相当します。

Return Values

この関数は値を返しません。

Examples
// Face the new 0 degrees
myDrivetrain.setHeading(90, degrees);
myDrivetrain.turnToHeading(0, degrees);

setRotation#

回転とは、ロボットがどれだけ回転したかを示すもので、度数または回転数で表されます。プロジェクトの開始時には、回転値は0度に設定されます。setRotation を実行すると、ロボットの現在の回転値が新しい値に変更されます。

例えば、ロボットが右に2回転した場合、回転角度は720度になります。回転角度を0度に設定すると、720度から0度にリセットされます。その後、ロボットはその新しい値に基づいて回転することができます。

Available Functions
void  setRotation(
  double value,
  rotationUnits units);

Parameters

パラメータ

タイプ

説明

value

double

ロボットに設定する回転値。

units

rotationUnits

回転単位: deg (度)、 rev (回転)、または raw (単位)。1回転は360度に相当します。

Return Values

この関数は値を返しません。

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

heading#

方位とは、ロボットが向いている方向のことで、度数で表されます。0 heading ロボットの現在の方位を0度から359度の範囲で返します。

ロボットの初期進行方向は0度です。

Available Functions
double heading( rotationUnits units = rotationUnits::deg );

Parameters

パラメータ

タイプ

説明

units

rotationUnits

オプション。方位を返す単位: degrees deg (デフォルト)、 rev、または raw回転は360度に相当します。

Return Values

ロボットの現在の進行方向を、選択された単位で double 倍数として返します。

Examples
// Show heading before and after turning
Brain.Screen.print("Before: %f", myDrivetrain.heading(degrees));
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
Brain.Screen.newLine();
Brain.Screen.print("After: %f", myDrivetrain.heading(degrees));
myDrivetrain.stop();

rotation#

Rotation is how much the robot has turned, measured in degrees or revolutions. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the robot’s current rotation.

右に回すと回転角度が大きくなり、左に回すと回転角度が小さくなります。例えば、右に2回転すると720度回転します。

Available Functions
double rotation( rotationUnits units = rotationUnits::deg );

Parameters

パラメータ

タイプ

説明

units

rotationUnits

オプション。方位を返す単位: degrees deg (デフォルト)、 rev、または raw回転は360度に相当します。

Return Values

選択した単位で、ロボットの現在の回転を double 倍数として返します。

Examples
// Show rotation before and after turning
Brain.Screen.print("Before: %f", myDrivetrain.rotation(degrees));
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
Brain.Screen.newLine();
Brain.Screen.print("After: %f", myDrivetrain.rotation(degrees));
myDrivetrain.stop();