SPIKE-RT C API Reference [English]
An RTOS-based software platform for LEGO® Education SPIKE™.
motor.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2/*
3 * API for motors
4 *
5 * Copyright (c) 2022 Embedded and Real-Time Systems Laboratory,
6 * Graduate School of Information Science, Nagoya Univ., JAPAN
7 */
8
32#ifndef _PUP_MOTOR_H_
33#define _PUP_MOTOR_H_
34
35#include <pbio/port.h>
36#include <pbio/servo.h>
37
38typedef pbio_servo_t pup_motor_t;
39typedef enum {
40 PUP_DIRECTION_CLOCKWISE = PBIO_DIRECTION_CLOCKWISE,
41 PUP_DIRECTION_COUNTERCLOCKWISE = PBIO_DIRECTION_COUNTERCLOCKWISE,
42} pup_direction_t;
43
57pup_motor_t *pup_motor_get_device(pbio_port_id_t port);
58
80pbio_error_t pup_motor_setup(pup_motor_t *motor, pup_direction_t positive_direction, bool reset_count);
81
93pbio_error_t pup_motor_reset_count(pup_motor_t *motor);
94
106int32_t pup_motor_get_count(pup_motor_t *motor);
107
119int32_t pup_motor_get_speed(pup_motor_t *motor);
120
134pbio_error_t pup_motor_set_speed(pup_motor_t *motor, int speed);
135
147int32_t pup_motor_get_power(pup_motor_t *motor);
148
162pbio_error_t pup_motor_set_power(pup_motor_t *motor, int power);
163
175pbio_error_t pup_motor_stop(pup_motor_t *motor);
176
188pbio_error_t pup_motor_brake(pup_motor_t *motor);
189
201pbio_error_t pup_motor_hold(pup_motor_t *motor);
202
216bool pup_motor_is_stalled(pup_motor_t *motor);
217
233int32_t pup_motor_set_duty_limit(pup_motor_t *motor, int duty_limit);
234
246void pup_motor_restore_duty_limit(pup_motor_t *motor, int old_value);
247
248#endif // _PUP_MOTOR_H_
249
pbio_error_t pup_motor_reset_count(pup_motor_t *motor)
Reset the motor encoder.
Definition: motor.c:66
void pup_motor_restore_duty_limit(pup_motor_t *motor, int old_value)
Restore the duty limit of the motor.
Definition: motor.c:156
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.
Definition: motor.c:34
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.
Definition: motor.c:57
int32_t pup_motor_get_power(pup_motor_t *motor)
Get the power of the motor.
Definition: motor.c:116
pbio_error_t pup_motor_hold(pup_motor_t *motor)
Stop the motor and hold it.
Definition: motor.c:108
int32_t pup_motor_get_count(pup_motor_t *motor)
Get the encoder value of the motor.
Definition: motor.c:74
bool pup_motor_is_stalled(pup_motor_t *motor)
Check if the motor is stalled.
Definition: motor.c:142
pbio_error_t pup_motor_stop(pup_motor_t *motor)
Stop the motor in coast mode.
Definition: motor.c:92
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 wi...
Definition: motor.c:148
pbio_error_t pup_motor_brake(pup_motor_t *motor)
Stop the motor in brake mode.
Definition: motor.c:100
int32_t pup_motor_get_speed(pup_motor_t *motor)
Get the speed of rotation of the motor.
Definition: motor.c:83
pbio_error_t pup_motor_set_power(pup_motor_t *motor, int power)
Set the power of the motor.
Definition: motor.c:126
pbio_error_t pup_motor_set_speed(pup_motor_t *motor, int speed)
Set the speed of rotation of the motor.
Definition: motor.c:134