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

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

#include <MiniR4DriveDC.h>

Public Member Functions

 MiniR4DriveDC ()
 
uint8_t begin (uint8_t leftMotorID, uint8_t rightMotorID, bool isLeftReverse, bool isRightReverse)
 Initializes the DC motor settings.
 
bool setMoveSyncPID (float kp, float ki, float kd)
 Sets the PID parameters for DriveDC MoveSync.
 
bool setMoveGyroPID (float kp, float ki, float kd)
 Sets the PID parameters for DriveDC MoveGyro.
 
bool setTurnGyroPID (float kp, float ki, float kd)
 Sets the PID parameters for DriveDC TurnGyro.
 
uint8_t Move (int16_t power_left, int16_t power_right)
 Sets the Motor Type for DriveDC. (Unuse)
 
uint8_t MoveDegs (int16_t power_left, int16_t power_right, uint16_t degree, bool brake, bool async=false)
 Sets the power level of the DC motor for a specific degree.
 
uint8_t MoveTime (int16_t power_left, int16_t power_right, float Time_S, bool brake, bool async=false)
 Sets the power level of the DC motor for a specific time period.
 
uint8_t MoveSync (int16_t power_left, int16_t power_right)
 Sets the power level of the DC motor with synchronization.
 
uint8_t MoveSyncDegs (int16_t power_left, int16_t power_right, uint16_t degree, bool brake, bool async=false)
 Sets the power level of the DC motor with synchronization for specific degrees.
 
uint8_t MoveSyncTime (int16_t power_left, int16_t power_right, float Time_S, bool brake, bool async=false)
 Sets the power level of the DC motor with synchronization for specific time.
 
uint8_t MoveGyro (int16_t power, int16_t Target)
 Sets the power level with gyro guidance.
 
uint8_t MoveGyroDegs (int16_t power_X, int16_t Target_D, uint16_t degree, bool brake, bool async=false)
 Sets the power level with gyro guidance for specific degrees.
 
uint8_t MoveGyroTime (int16_t power, int16_t Target, float Time_S, bool brake, bool async=false)
 Sets the power level with gyro guidance for specific time.
 
uint8_t TurnGyro (int16_t power, int16_t Target_D, uint8_t mode, bool brake, bool async=false)
 Turns the robot to a specific gyro heading.
 
int32_t getCounter (void)
 Gets the estimated rotation counter of the drivebase. (not degrees)
 
int32_t getDegrees (void)
 Gets the estimated degrees of the drivebase.
 
uint8_t resetCounter (void)
 Resets the drivebase encoder counter/degrees to zero.
 
uint8_t brake (bool brakeType)
 Sets the brake mode for the DC motor.
 
bool isPrevTaskDone (void)
 Checks if the previous task has completed.
 

Detailed Description

template<uint8_t ID>
class MiniR4DriveDC< ID >

Class for controlling a DC motor with encoder functionality.

This template class provides methods for initializing, driving DC motor by Move, MoveSync, MoveGyro, TurnGyro function

Template Parameters
IDThe identifier for the motor.

Definition at line 29 of file MiniR4DriveDC.h.

Constructor & Destructor Documentation

◆ MiniR4DriveDC()

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

Definition at line 30 of file MiniR4DriveDC.h.

Member Function Documentation

◆ begin()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::begin ( uint8_t leftMotorID,
uint8_t rightMotorID,
bool isLeftReverse,
bool isRightReverse )
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.DriveDC.begin, DriveDC class motor will automatically begin.

Parameters
leftMotorID: the number of Left motor
rightMotorID: the number of Right motor
isLeftReverse: the direction of Left motor encoder
isRightReverse: the direction of Right motor encoder
Returns
0x00 if initialization was successful, error code otherwise.

Definition at line 49 of file MiniR4DriveDC.h.

◆ brake()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::brake ( bool brakeType)
inline

Sets the brake mode for the DC motor.

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

Parameters
brakeTypeTrue to engage the brake, false to coast the motor.
Returns
0x00 if the brake was successfully set, error code otherwise.

Definition at line 637 of file MiniR4DriveDC.h.

◆ getCounter()

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

Gets the estimated rotation counter of the drivebase. (not degrees)

Returns
The current encoder counter value.

Definition at line 583 of file MiniR4DriveDC.h.

◆ getDegrees()

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

Gets the estimated degrees of the drivebase.

Returns
The calculated degrees of rotation.

Definition at line 600 of file MiniR4DriveDC.h.

◆ isPrevTaskDone()

template<uint8_t ID>
bool MiniR4DriveDC< ID >::isPrevTaskDone ( void )
inline

Checks if the previous task has completed.

Returns
True if the previous task is done, false if still running.

Definition at line 654 of file MiniR4DriveDC.h.

◆ Move()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::Move ( int16_t power_left,
int16_t power_right )
inline

Sets the Motor Type for DriveDC. (Unuse)

Parameters
typeXC=> 1:Blue Motor / 2:LEGO Motor
Returns
True if the motor type was successfully set, false otherwise.

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
power_leftThe power level to set for left motor (-100 to 100).
power_rightThe power level to set for right motor (-100 to 100).
Returns
0x00 if the power was successfully set, error code otherwise.

Definition at line 164 of file MiniR4DriveDC.h.

◆ MoveDegs()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveDegs ( int16_t power_left,
int16_t power_right,
uint16_t degree,
bool brake,
bool async = false )
inline

Sets the power level of the DC motor for a specific degree.

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

Parameters
power_leftThe power level to set for left motor (-100 to 100).
power_rightThe power level to set for right motor (-100 to 100).
degreeTarget Degree for Stop
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 198 of file MiniR4DriveDC.h.

◆ MoveGyro()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveGyro ( int16_t power,
int16_t Target )
inline

Sets the power level with gyro guidance.

Robot moves with gyro sensor feedback to maintain straight line or target heading

Parameters
powerThe power level to set (-100 to 100).
TargetTarget Degree of the IMU Yaw (-360 ~ +360)
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 419 of file MiniR4DriveDC.h.

◆ MoveGyroDegs()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveGyroDegs ( int16_t power_X,
int16_t Target_D,
uint16_t degree,
bool brake,
bool async = false )
inline

Sets the power level with gyro guidance for specific degrees.

Robot moves with gyro sensor feedback to maintain heading while moving specific encoder degrees

Parameters
power_XThe power level to set (-100 to 100).
Target_DTarget Degree of the IMU Yaw (-360 ~ +360)
degreeTarget Degree of the motor encoder for stop
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 452 of file MiniR4DriveDC.h.

◆ MoveGyroTime()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveGyroTime ( int16_t power,
int16_t Target,
float Time_S,
bool brake,
bool async = false )
inline

Sets the power level with gyro guidance for specific time.

Robot moves with gyro sensor feedback to maintain heading for specific time duration

Parameters
powerThe power level to set (-100 to 100).
TargetTarget Degree of the IMU Yaw (-360 ~ +360)
Time_SThe Period(secs) of the motor running
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 500 of file MiniR4DriveDC.h.

◆ MoveSync()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveSync ( int16_t power_left,
int16_t power_right )
inline

Sets the power level of the DC motor with synchronization.

It's like LEGO EV3/SPIKE Power block (Regulated Motor) Motors will run synchronized with encoder feedback

Parameters
power_leftThe power level to set for left motor (-100 to 100).
power_rightThe power level to set for right motor (-100 to 100).
Returns
0x00 if the power was successfully set, error code otherwise.

Definition at line 290 of file MiniR4DriveDC.h.

◆ MoveSyncDegs()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveSyncDegs ( int16_t power_left,
int16_t power_right,
uint16_t degree,
bool brake,
bool async = false )
inline

Sets the power level of the DC motor with synchronization for specific degrees.

It's like LEGO EV3/SPIKE Power block (Regulated Motor) Motors will run synchronized with encoder feedback

Parameters
power_leftThe power level to set for left motor (-100 to 100).
power_rightThe power level to set for right motor (-100 to 100).
degreeTarget Degree
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 324 of file MiniR4DriveDC.h.

◆ MoveSyncTime()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveSyncTime ( int16_t power_left,
int16_t power_right,
float Time_S,
bool brake,
bool async = false )
inline

Sets the power level of the DC motor with synchronization for specific time.

It's like LEGO EV3/SPIKE Power block (Regulated Motor) Motors will run synchronized with encoder feedback

Parameters
power_leftThe power level to set for left motor (-100 to 100).
power_rightThe power level to set for right motor (-100 to 100).
Time_SPeriod of the Motor Running (secs)
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 373 of file MiniR4DriveDC.h.

◆ MoveTime()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::MoveTime ( int16_t power_left,
int16_t power_right,
float Time_S,
bool brake,
bool async = false )
inline

Sets the power level of the DC motor for a specific time period.

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

Parameters
power_leftThe power level to set for left motor (-100 to 100).
power_rightThe power level to set for right motor (-100 to 100).
Time_SPeriod of the Motor Running (secs)
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 245 of file MiniR4DriveDC.h.

◆ resetCounter()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::resetCounter ( void )
inline

Resets the drivebase encoder counter/degrees to zero.

Returns
0x00 if the counter was successfully reset, error code otherwise.

Definition at line 617 of file MiniR4DriveDC.h.

◆ setMoveGyroPID()

template<uint8_t ID>
bool MiniR4DriveDC< ID >::setMoveGyroPID ( float kp,
float ki,
float kd )
inline

Sets the PID parameters for DriveDC MoveGyro.

Parameters
kpProportional gain.(TT:6.01, LE:0.52)
kiIntegral gain.(TT:0.00, LE:0.00)
kdDerivative gain.(TT:2.15, LE:0.15)
Returns
True if the PID parameters were successfully set, false otherwise.

Definition at line 107 of file MiniR4DriveDC.h.

◆ setMoveSyncPID()

template<uint8_t ID>
bool MiniR4DriveDC< ID >::setMoveSyncPID ( float kp,
float ki,
float kd )
inline

Sets the PID parameters for DriveDC MoveSync.

Parameters
kpProportional gain.(TT:0.02, LE:0.002)
kiIntegral gain.(TT:0.00, LE:0.00)
kdDerivative gain.(TT:0.04, LE:0.004)
Returns
True if the PID parameters were successfully set, false otherwise.

Definition at line 88 of file MiniR4DriveDC.h.

◆ setTurnGyroPID()

template<uint8_t ID>
bool MiniR4DriveDC< ID >::setTurnGyroPID ( float kp,
float ki,
float kd )
inline

Sets the PID parameters for DriveDC TurnGyro.

Parameters
kpProportional gain.(TT:22.75, LE-F:22.75, LE-S:5.25)
kiIntegral gain.(TT:0.08, LE:0.02)
kdDerivative gain.(TT:0.25, LE:1.54)
Returns
True if the PID parameters were successfully set, false otherwise.

Definition at line 126 of file MiniR4DriveDC.h.

◆ TurnGyro()

template<uint8_t ID>
uint8_t MiniR4DriveDC< ID >::TurnGyro ( int16_t power,
int16_t Target_D,
uint8_t mode,
bool brake,
bool async = false )
inline

Turns the robot to a specific gyro heading.

Robot turns in place using gyro sensor feedback to reach target heading

Parameters
powerThe power level to set (-100 to 100).
Target_DTarget Degree of the IMU Yaw (-360 ~ +360)
mode0:single motor / 1:two motor
brakeTrue(Brake) / false(coast)
asyncTrue(non-block) / false(block) - default: false
Returns
0x00 if the param was successfully set, error code otherwise.

Definition at line 548 of file MiniR4DriveDC.h.


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