7#ifndef SPIKE_CPP_API_MOTOR_H_
8#define SPIKE_CPP_API_MOTOR_H_
15#include <libcpp/spike/Port.h>
25 enum class EDirection {
26 CLOCKWISE = PUP_DIRECTION_CLOCKWISE,
27 COUNTERCLOCKWISE = PUP_DIRECTION_COUNTERCLOCKWISE,
37 Motor(EPort port,EDirection direction = EDirection::CLOCKWISE,
bool reset_count =
true) : mHasError(false) {
43 pbio_error_t ret =
pup_motor_setup(mMotor,
static_cast<pup_direction_t
>(direction), reset_count);
44 if ( ret != PBIO_SUCCESS ) {
void stop() const
Definition Motor.h:103
void restoreDutyLimit(int old_value) const
Definition Motor.h:145
void brake() const
Definition Motor.h:111
void setPower(int power) const
Definition Motor.h:95
Motor(EPort port, EDirection direction=EDirection::CLOCKWISE, bool reset_count=true)
Definition Motor.h:37
bool isStalled() const
Definition Motor.h:128
int32_t getCount() const
Definition Motor.h:61
bool hasError()
Definition Motor.h:152
int32_t setDutyLimit(int duty_limit) const
Definition Motor.h:137
void resetCount() const
Definition Motor.h:53
void setSpeed(int speed) const
Definition Motor.h:78
int32_t getPower() const
Definition Motor.h:86
void hold() const
Definition Motor.h:119
int32_t getSpeed() const
Definition Motor.h:69
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