SPIKE-RT C API Reference [English]
An RTOS-based software platform for LEGO® Education SPIKE™.
Typedefs | Enumerations | Functions
Motors

APIs for motors. More...

Typedefs

typedef pbio_servo_t pup_motor_t
 

Enumerations

enum  pup_direction_t { PUP_DIRECTION_CLOCKWISE = PBIO_DIRECTION_CLOCKWISE , PUP_DIRECTION_COUNTERCLOCKWISE = PBIO_DIRECTION_COUNTERCLOCKWISE }
 

Functions

pup_motor_t * pup_motor_get_device (pbio_port_id_t port)
 Get the PUP motor device pointer of the motor specified by the port ID. More...
 
pbio_error_t pup_motor_setup (pup_motor_t *motor, pup_direction_t positive_direction, bool reset_count)
 Setup the PUP motor with the specified direction, possibly resetting the encoder. More...
 
pbio_error_t pup_motor_reset_count (pup_motor_t *motor)
 Reset the motor encoder. More...
 
int32_t pup_motor_get_count (pup_motor_t *motor)
 Get the encoder value of the motor. More...
 
int32_t pup_motor_get_speed (pup_motor_t *motor)
 Get the speed of rotation of the motor. More...
 
pbio_error_t pup_motor_set_speed (pup_motor_t *motor, int speed)
 Set the speed of rotation of the motor. More...
 
int32_t pup_motor_get_power (pup_motor_t *motor)
 Get the power of the motor. More...
 
pbio_error_t pup_motor_set_power (pup_motor_t *motor, int power)
 Set the power of the motor. More...
 
pbio_error_t pup_motor_stop (pup_motor_t *motor)
 Stop the motor in coast mode. More...
 
pbio_error_t pup_motor_brake (pup_motor_t *motor)
 Stop the motor in brake mode. More...
 
pbio_error_t pup_motor_hold (pup_motor_t *motor)
 Stop the motor and hold it. More...
 
bool pup_motor_is_stalled (pup_motor_t *motor)
 Check if the motor is stalled. More...
 
int32_t pup_motor_set_duty_limit (pup_motor_t *motor, int duty_limit)
 Lower the duty limit of the motor. \detail To restore the limit, call pup_motor_restore_duty_limit with the value returned as its argument. More...
 
void pup_motor_restore_duty_limit (pup_motor_t *motor, int old_value)
 Restore the duty limit of the motor. More...
 

Detailed Description

APIs for motors.

Function Documentation

◆ pup_motor_brake()

pbio_error_t pup_motor_brake ( pup_motor_t *  motor)

Stop the motor in brake mode.

Parameters
motorPUP motor device pointer.
Returns
PBIO_SUCCESS or error number.

◆ pup_motor_get_count()

int32_t pup_motor_get_count ( pup_motor_t *  motor)

Get the encoder value of the motor.

Parameters
motorPUP motor device pointer.
Returns
Encoder value in degree.

◆ pup_motor_get_device()

pup_motor_t * pup_motor_get_device ( pbio_port_id_t  port)

Get the PUP motor device pointer of the motor specified by the port ID.

If it fails, it outputs an error log and returns NULL.

Parameters
portPUP port ID of the device.
Returns
PUP motor device pointer.

◆ pup_motor_get_power()

int32_t pup_motor_get_power ( pup_motor_t *  motor)

Get the power of the motor.

Parameters
motorPUP motor device pointer.
Returns
PWM (between -100 and +100).

◆ pup_motor_get_speed()

int32_t pup_motor_get_speed ( pup_motor_t *  motor)

Get the speed of rotation of the motor.

Parameters
motorPUP motor device pointer.
Returns
Speed in degree/sec.

◆ pup_motor_hold()

pbio_error_t pup_motor_hold ( pup_motor_t *  motor)

Stop the motor and hold it.

Parameters
motorPUP motor device pointer.
Returns
PBIO_SUCCESS or error number.

◆ pup_motor_is_stalled()

bool pup_motor_is_stalled ( pup_motor_t *  motor)

Check if the motor is stalled.

Call pup_motor_set_duty_limit before actuating the motor to avoid applying the full motor torque.

Parameters
motorPUP motor device pointer.
Returns
true or false.

◆ pup_motor_reset_count()

pbio_error_t pup_motor_reset_count ( pup_motor_t *  motor)

Reset the motor encoder.

Parameters
motorPUP motor device pointer.
Returns
PBIO_SUCCESS or error number.

◆ pup_motor_restore_duty_limit()

void pup_motor_restore_duty_limit ( pup_motor_t *  motor,
int  old_value 
)

Restore the duty limit of the motor.

Parameters
motorPUP motor device pointer.
old_valueVoltage returned from pup_motor_set_duty_limit.

◆ pup_motor_set_duty_limit()

int32_t pup_motor_set_duty_limit ( pup_motor_t *  motor,
int  duty_limit 
)

Lower the duty limit of the motor. \detail To restore the limit, call pup_motor_restore_duty_limit with the value returned as its argument.

Parameters
motorPUP motor device pointer.
duty_limitnew limit (0-100),
Returns
max voltage to restore the limit back to the original conditions.

◆ pup_motor_set_power()

pbio_error_t pup_motor_set_power ( pup_motor_t *  motor,
int  power 
)

Set the power of the motor.

Parameters
motorPUP motor device pointer.
powerPower between -100 and +100.
Returns
PBIO_SUCCESS or error number.

◆ pup_motor_set_speed()

pbio_error_t pup_motor_set_speed ( pup_motor_t *  motor,
int  speed 
)

Set the speed of rotation of the motor.

Parameters
motorPUP motor device pointer.
speedSpeed of rotation in degree/sec.
Returns
PBIO_SUCCESS or error number.

◆ pup_motor_setup()

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

Setup the PUP motor with the specified direction, possibly resetting the encoder.

It could return PBIO_ERROR_AGAIN and (PBIO_ERROR_NO_DEV, too), if it is called "too soon", in which case you should call this function again sometime later. Errors other than PBIO_ERROR_AGAIN are logged.

Parameters
motorPUP motor device pointer.
positive_directionEither PUP_DIRECTION_CLOCKWISE or PUP_DIRECTION_COUNTERCLOCKWISE to indicate the desiredi positive direction..
reset_countIndicate if counter should be reset.
Returns
PBIO_SUCCESS or error number.

◆ pup_motor_stop()

pbio_error_t pup_motor_stop ( pup_motor_t *  motor)

Stop the motor in coast mode.

Parameters
motorPUP motor device pointer.
Returns
PBIO_SUCCESS or error number.