SingleMotor クラス

class legoeducation.SingleMotor()

単一のモーターに対して、方向、速度、位置、加減速を詳細に制御・監視します。

1. done()

done(motor=None)

実行中のモーターコマンドがまだ稼働中かどうかを確認します。

引数名 要求される型 数値の範囲 / 選択肢 備考
motor int / None 0 または None 0指定時はモーター0、None指定時はすべてのモーターを対象に検査。1や2などの範囲外を指定した場合はValueErrorが発生します。

2. motor_set_speed()

motor_set_speed(speed, *, motor=0, blocking=True)

モーターの基準回転速度を設定します。

引数名 要求される型 数値の範囲 / 選択肢 備考
speed int / float (四捨五入) -100100 (%) 負の値で反時計回りに回転。
motor int 任意の整数(デフォルト 0 SingleMotorでは渡された整数に関わらず、内部で常にモーター0として処理されます。
blocking bool True または False -

3. motor_run()

motor_run(*, direction=MOTOR_MOVE_DIRECTION_CLOCKWISE, motor=0, speed=UNCHANGED, blocking=True)

モーターを指定方向へ連続回転させます。

引数名 要求される型 数値の範囲 / 選択肢 備考
direction int (厳格) 03 (MotorMoveDirection定数) 0:時計, 1:反時計, 2:最短旋回, 3:最長旋回
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
speed int/float / None -100100、または None None時は既存設定速度を維持。
blocking bool True または False コマンド完了まで待機するかどうか。

4. motor_run_for_time()

motor_run_for_time(time_ms, *, direction=MOTOR_MOVE_DIRECTION_CLOCKWISE, motor=0, speed=UNCHANGED, blocking=True)

指定ミリ秒間、モーターを回転させて自動停止します。

引数名 要求される型 数値の範囲 / 選択肢 備考
time_ms int / float (四捨五入) UINT32幅: 04294967295 負数はValueError。
direction int (厳格) 03 (MotorMoveDirection定数) 0:時計, 1:反時計, 2:最短旋回, 3:最長旋回
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
speed int/float / None -100100、または None None時は既存設定速度を維持。
blocking bool True または False -

5. motor_run_for_degrees()

motor_run_for_degrees(degrees, *, direction=MOTOR_MOVE_DIRECTION_CLOCKWISE, motor=0, speed=UNCHANGED, blocking=True)

指定した角度(度数)だけモーターを回転させて自動停止します。

引数名 要求される型 数値の範囲 / 選択肢 備考
degrees int / float (四捨五入) INT32幅: -21474836482147483647 回転目標角度。
direction int (厳格) 03 (MotorMoveDirection定数) 0:時計, 1:反時計, 2:最短旋回, 3:最長旋回
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
speed int/float / None -100100、または None None時は既存設定速度を維持。
blocking bool True または False -

6. motor_reset_relative_position()

motor_reset_relative_position(*, motor=0, position=0, blocking=True)

現在のモーターの相対位置カウンターを任意の値にリセット設定します。

引数名 要求される型 数値の範囲 / 選択肢 備考
position int / float (四捨五入) INT32幅: 全整数範囲(0〜360推奨) リセット後の角度値。
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
blocking bool True または False -

7. motor_run_to_relative_position()

motor_run_to_relative_position(position, *, motor=0, speed=UNCHANGED, blocking=True)

相対基準点に基づき、指定のターゲット位置まで回転します。

引数名 要求される型 数値の範囲 / 選択肢 備考
position int / float (四捨五入) INT32幅: -21474836482147483647 相対ターゲット位置。
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
speed int/float / None -100100、または None None時は既存設定速度を維持。
blocking bool True または False -

8. motor_run_to_absolute_position()

motor_run_to_absolute_position(position, *, direction=MOTOR_MOVE_DIRECTION_SHORTEST, motor=0, speed=UNCHANGED, blocking=True)

モーターに刻まれた固定の絶対位置(0〜359度)を目標に回転します。

引数名 要求される型 数値の範囲 / 選択肢 備考
position int / float (四捨五入) INT32幅: 制限なし(内部で自動的に % 360 演算されます) 絶対ターゲット位置。
direction int (厳格) 03 (MotorMoveDirection定数) デフォルトは最短ルート(2)。
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
speed int/float / None -100100、または None None時は既存設定速度を維持。
blocking bool True または False -

9. motor_set_duty_cycle()

motor_set_duty_cycle(duty_cycle, *, motor=0, blocking=True)

速度レギュレーションをバイパスし、生のデューティ比を指定して直接駆動します。

引数名 要求される型 数値の範囲 / 選択肢 備考
duty_cycle int / float (四捨五入) -100100 パワー比率制御。
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
blocking bool True または False コマンド完了まで待機するかどうか。

10. motor_stop()

motor_stop(*, motor=0, blocking=True)

モーターを停止します。

※motor引数には任意の整数を指定可能ですが、一律でモーター0として処理されます。

11. motor_set_end_state()

motor_set_end_state(end_state, *, motor=0, blocking=True)

モーター停止後の状態(コースト、ブレーキ、ホールドなど)を指定します。

引数名 要求される型 数値の範囲 / 選択肢 備考
end_state int (厳格) -15 (MotorEndState定数) 0:フリー(コースト), 1:ブレーキ, 2:位置保持(ホールド)
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
blocking bool True または False -

12. motor_set_acceleration()

motor_set_acceleration(acceleration, deceleration, *, motor=0, blocking=True)

駆動時の加速・減速の滑らかさをパーセンテージで設定します。

引数名 要求される型 数値の範囲 / 選択肢 備考
acceleration int / float (四捨五入) 0100 (%) 加速レート。
deceleration int / float (四捨五入) 0100 (%) 減速レート。
motor int 任意の整数(デフォルト 0 渡された整数に関わらず、内部で常にモーター0として処理されます。
blocking bool True または False -

GitHub サンプルプログラム

import legoeducation as le

singlemotor = le.SingleMotor()
singlemotor.connect(card_color=le.LEGO_COLOR_AZURE, card_serial="1234")

# 360度(1回転)をスピード30%で回転
singlemotor.motor_run_for_degrees(360, speed=30)
singlemotor.disconnect()