SPIKE-RT C API Reference [Japanese]
An RTOS-based software platform for LEGO® Education SPIKE™.
型定義 | 列挙型 | 関数
モータ

モータのAPI. [詳解]

型定義

typedef pbio_servo_t pup_motor_t
 

列挙型

enum  pup_direction_t { PUP_DIRECTION_CLOCKWISE = PBIO_DIRECTION_CLOCKWISE , PUP_DIRECTION_COUNTERCLOCKWISE = PBIO_DIRECTION_COUNTERCLOCKWISE }
 

関数

pup_motor_t * pup_motor_get_device (pbio_port_id_t port)
 ポートIDで指定されたモータへのPUPモータデバイスポインタを取得する. [詳解]
 
pbio_error_t pup_motor_setup (pup_motor_t *motor, pup_direction_t positive_direction, bool reset_count)
 モータを初期化する. [詳解]
 
pbio_error_t pup_motor_reset_count (pup_motor_t *motor)
 エンコーダをリセットする. [詳解]
 
int32_t pup_motor_get_count (pup_motor_t *motor)
 エンコーダの値を取得する. [詳解]
 
int32_t pup_motor_get_speed (pup_motor_t *motor)
 モータの回転速度を取得する. [詳解]
 
pbio_error_t pup_motor_set_speed (pup_motor_t *motor, int speed)
 モータの回転速度を設定する. [詳解]
 
int32_t pup_motor_get_power (pup_motor_t *motor)
 モータのパワー値を取得する. [詳解]
 
pbio_error_t pup_motor_set_power (pup_motor_t *motor, int power)
 モータのパワー値を設定する. [詳解]
 
pbio_error_t pup_motor_stop (pup_motor_t *motor)
 モータを止める. [詳解]
 
pbio_error_t pup_motor_brake (pup_motor_t *motor)
 ブレーキをかけてモータを止める. [詳解]
 
pbio_error_t pup_motor_hold (pup_motor_t *motor)
 モータを止めて角度を維持する. [詳解]
 
bool pup_motor_is_stalled (pup_motor_t *motor)
 モータがストールしているか調べる. \detail モータを動かす前にpup_motor_set_duty_limitを呼んで最大トルクを下げておくと感度を調整することができる. [詳解]
 
int32_t pup_motor_set_duty_limit (pup_motor_t *motor, int duty_limit)
 モータのデューティ値を下げる. \detail 元の状態に戻すにはこの関数の戻り値を使ってpup_motor_restore_duty_limitを呼ぶ.. [詳解]
 
void pup_motor_restore_duty_limit (pup_motor_t *motor, int old_value)
 モータのデューティ値を元に戻す.. [詳解]
 

詳解

モータのAPI.

関数詳解

◆ pup_motor_brake()

pbio_error_t pup_motor_brake ( pup_motor_t *  motor)

ブレーキをかけてモータを止める.

引数
motorPUPモータデバイスポインタ.
戻り値
PBIO_SUCCESSまたはエラー番号.

◆ pup_motor_get_count()

int32_t pup_motor_get_count ( pup_motor_t *  motor)

エンコーダの値を取得する.

引数
motorPUPモータデバイスポインタ.
戻り値
エンコーダの値 [°].

◆ pup_motor_get_device()

pup_motor_t * pup_motor_get_device ( pbio_port_id_t  port)

ポートIDで指定されたモータへのPUPモータデバイスポインタを取得する.

失敗した場合,エラーログを出力し,NULLを返す.

引数
portPUPポートID.
戻り値
PUPモータデバイスポインタ.

◆ pup_motor_get_power()

int32_t pup_motor_get_power ( pup_motor_t *  motor)

モータのパワー値を取得する.

引数
motorPUPモータデバイスポインタ.
戻り値
パワー値(-100 ~ +100).

◆ pup_motor_get_speed()

int32_t pup_motor_get_speed ( pup_motor_t *  motor)

モータの回転速度を取得する.

引数
motorPUPモータデバイスポインタ.
戻り値
回転速度 [°/秒].

◆ pup_motor_hold()

pbio_error_t pup_motor_hold ( pup_motor_t *  motor)

モータを止めて角度を維持する.

引数
motorPUPモータデバイスポインタ.
戻り値
PBIO_SUCCESSまたはエラー番号.

◆ pup_motor_is_stalled()

bool pup_motor_is_stalled ( pup_motor_t *  motor)

モータがストールしているか調べる. \detail モータを動かす前にpup_motor_set_duty_limitを呼んで最大トルクを下げておくと感度を調整することができる.

引数
motorPUPモータデバイスポインタ.
戻り値
true or false.

◆ pup_motor_reset_count()

pbio_error_t pup_motor_reset_count ( pup_motor_t *  motor)

エンコーダをリセットする.

引数
motorPUPモータデバイスポインタ.
戻り値
PBIO_SUCCESSまたはエラー番号.

◆ pup_motor_restore_duty_limit()

void pup_motor_restore_duty_limit ( pup_motor_t *  motor,
int  old_value 
)

モータのデューティ値を元に戻す..

引数
motorPUPモータデバイスポインタ.
old_valuepup_motor_set_duty_limitの戻り値.

◆ pup_motor_set_duty_limit()

int32_t pup_motor_set_duty_limit ( pup_motor_t *  motor,
int  duty_limit 
)

モータのデューティ値を下げる. \detail 元の状態に戻すにはこの関数の戻り値を使ってpup_motor_restore_duty_limitを呼ぶ..

引数
motorPUPモータデバイスポインタ.
duty_limit新しいデューティ値(0-100)
戻り値
元の状態に戻すための最大電圧.

◆ pup_motor_set_power()

pbio_error_t pup_motor_set_power ( pup_motor_t *  motor,
int  power 
)

モータのパワー値を設定する.

引数
motorPUPモータデバイスポインタ.
powerモータのパワー値(-100 ~ +100).
戻り値
PBIO_SUCCESSまたはエラー番号.

◆ pup_motor_set_speed()

pbio_error_t pup_motor_set_speed ( pup_motor_t *  motor,
int  speed 
)

モータの回転速度を設定する.

引数
motorPUPモータデバイスポインタ.
speedモータの回転速度 [°/秒].
戻り値
PBIO_SUCCESSまたはエラー番号.

◆ pup_motor_setup()

pbio_error_t pup_motor_setup ( pup_motor_t *  motor,
pup_direction_t  positive_direction,
bool  reset_count 
)

モータを初期化する.

PBIO_ERROR_AGAINが返ってき場合は時間をおいてもう一度この関数を呼ぶこと.その他のエラーで失敗した場合は エラーログに出力する.

引数
motorPUPモータデバイスポインタ.
positive_directionモータの正回転方向をPUP_DIRECTION_CLOCKWISEまたはPUP_DIRECTION_COUNTERCLOCKWISEで示す.
reset_counttrueかfalseでエンコーダの値をリセットするか示す.
戻り値
PBIO_SUCCESSまたはエラー番号.

◆ pup_motor_stop()

pbio_error_t pup_motor_stop ( pup_motor_t *  motor)

モータを止める.

引数
motorPUPモータデバイスポインタ.
戻り値
PBIO_SUCCESSまたはエラー番号.