MatrixMiniR4 1.1.5
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MiniR4DC< ID > Class Template Reference

Class for controlling a DC motor with encoder functionality. More...

#include <MiniR4DC.h>

Public Member Functions

 MiniR4DC ()
 
bool begin (void)
 Initializes the DC motor settings.
 
bool setReverse (bool dir)
 Sets the direction of the DC motor.
 
bool setPower (int16_t power)
 Sets the power level of the DC motor.
 
bool setSpeed (int16_t speed)
 Sets the speed of the DC motor.
 
bool rotateFor (int16_t speed, uint16_t degree)
 Rotates the DC motor for a specific degree at a given speed.
 
bool setFixSpeedPID (float kp, float ki, float kd)
 Sets the PID parameters for fixed speed control. (For SetSpeed())
 
bool setRotatePID (float kp, float ki, float kd)
 Sets the PID parameters for rotation control. (For rotateFor())
 
int32_t getCounter (void)
 Gets the current encoder counter value. (Not Degree)
 
int32_t getDegrees (void)
 Gets the current rotation in degrees based on the encoder count.
 
bool resetCounter (void)
 Resets the encoder counter to zero.
 
bool setBrake (bool brake)
 Sets the brake mode for the DC motor.
 
bool ChkRotateEnd (bool &isEnd)
 Checks if the rotation has ended.
 

Detailed Description

template<uint8_t ID>
class MiniR4DC< ID >

Class for controlling a DC motor with encoder functionality.

This template class provides methods for initializing, controlling speed, power, and direction of a DC motor, as well as for managing its encoder.

Template Parameters
IDThe identifier for the motor.

Definition at line 20 of file MiniR4DC.h.

Constructor & Destructor Documentation

◆ MiniR4DC()

template<uint8_t ID>
MiniR4DC< ID >::MiniR4DC ( )
inline

Definition at line 23 of file MiniR4DC.h.

Member Function Documentation

◆ begin()

template<uint8_t ID>
bool MiniR4DC< ID >::begin ( void )
inline

Initializes the DC motor settings.

This function sets the speed range, resets the encoder counter, powers off the motor, and sets the direction to forward.

Note: Once you call MiniR4.begin(), M1-M4 motor will automaticlly begin.

Returns
True if initialization was successful, false otherwise.

Definition at line 35 of file MiniR4DC.h.

◆ ChkRotateEnd()

template<uint8_t ID>
bool MiniR4DC< ID >::ChkRotateEnd ( bool & isEnd)
inline

Checks if the rotation has ended.

Parameters
isEndReference to a boolean that will be set to true if rotation has ended, false otherwise.
Returns
True if the state was successfully retrieved, false otherwise.

Definition at line 197 of file MiniR4DC.h.

◆ getCounter()

template<uint8_t ID>
int32_t MiniR4DC< ID >::getCounter ( void )
inline

Gets the current encoder counter value. (Not Degree)

Returns
The current encoder counter value.

Definition at line 142 of file MiniR4DC.h.

◆ getDegrees()

template<uint8_t ID>
int32_t MiniR4DC< ID >::getDegrees ( void )
inline

Gets the current rotation in degrees based on the encoder count.

Returns
The calculated degrees of rotation.

Definition at line 154 of file MiniR4DC.h.

◆ resetCounter()

template<uint8_t ID>
bool MiniR4DC< ID >::resetCounter ( void )
inline

Resets the encoder counter to zero.

Returns
True if the counter was successfully reset, false otherwise.

Definition at line 166 of file MiniR4DC.h.

◆ rotateFor()

template<uint8_t ID>
bool MiniR4DC< ID >::rotateFor ( int16_t speed,
uint16_t degree )
inline

Rotates the DC motor for a specific degree at a given speed.

It's like LEGO EV3/SPIKE Motor rotate for degress block. Note: Non-Blocking function, you can use ChkRotateEnd() to check motor finish rotate or not. Note: If motor not complete rotate and revice other command like setSpeed(), the rotate will be skip.

Parameters
speedThe speed at which to rotate the motor.
degreeThe degree of rotation.
Returns
True if the rotation command was successful, false otherwise.

Definition at line 103 of file MiniR4DC.h.

◆ setBrake()

template<uint8_t ID>
bool MiniR4DC< ID >::setBrake ( bool brake)
inline

Sets the brake mode for the DC motor.

Like LEGO EV3/SPIKE, True is Brake, False is Coast.

Parameters
brakeTrue to engage the brake, false to stop the motor.
Returns
True if the brake was successfully engaged, false otherwise.

Definition at line 180 of file MiniR4DC.h.

◆ setFixSpeedPID()

template<uint8_t ID>
bool MiniR4DC< ID >::setFixSpeedPID ( float kp,
float ki,
float kd )
inline

Sets the PID parameters for fixed speed control. (For SetSpeed())

Parameters
kpProportional gain.
kiIntegral gain.
kdDerivative gain.
Returns
True if the PID parameters were successfully set, false otherwise.

Definition at line 117 of file MiniR4DC.h.

◆ setPower()

template<uint8_t ID>
bool MiniR4DC< ID >::setPower ( int16_t power)
inline

Sets the power level of the DC motor.

It's like LEGO EV3/SPIKE Power block (Unregulated Motor) It will output the Motor PWM from 0% to 100%

Parameters
powerThe power level to set (-100 to 100).
Returns
True if the power was successfully set, false otherwise.

Definition at line 71 of file MiniR4DC.h.

◆ setReverse()

template<uint8_t ID>
bool MiniR4DC< ID >::setReverse ( bool dir)
inline

Sets the direction of the DC motor.

Parameters
dirTrue to set direction to reverse, false for forward.
Returns
True if the direction was successfully set, false otherwise.

Definition at line 53 of file MiniR4DC.h.

◆ setRotatePID()

template<uint8_t ID>
bool MiniR4DC< ID >::setRotatePID ( float kp,
float ki,
float kd )
inline

Sets the PID parameters for rotation control. (For rotateFor())

Parameters
kpProportional gain.
kiIntegral gain.
kdDerivative gain.
Returns
True if the PID parameters were successfully set, false otherwise.

Definition at line 131 of file MiniR4DC.h.

◆ setSpeed()

template<uint8_t ID>
bool MiniR4DC< ID >::setSpeed ( int16_t speed)
inline

Sets the speed of the DC motor.

It's like LEGO EV3/SPIKE Speed block (EV3 Green Motor) The Lower MCU (STM32) will control the motor PWM to try keep the speed you set.

Parameters
speedThe speed to set (-100 to 100).
Returns
True if the speed was successfully set, false otherwise.

Definition at line 86 of file MiniR4DC.h.


The documentation for this class was generated from the following file: