RBE1001Lib
Public Member Functions | Data Fields | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
Motor Class Reference

A PID Motor class using FreeRTOS threads, ESP32Encoder and ESP32PWM. More...

#include <Motor.h>

Inheritance diagram for Motor:
Inheritance graph
[legend]
Collaboration diagram for Motor:
Collaboration graph
[legend]

Public Member Functions

float getInterpolationUnitIncrement ()
 
 Motor (int pwmPin, int dirPin, int encAPin, int encBPin)
 A PID Motor class using FreeRTOS threads, ESP32Encoder and ESP32PWM. More...
 
virtual ~Motor ()
 
void attach ()
 Attach the motors hardware. More...
 
void setEffort (float effort)
 
void setEffortPercent (float percent)
 
float getEffort ()
 
float getEffortPercent ()
 
float getDegreesPerSecond ()
 
float getCurrentDegrees ()
 
void loop ()
 
void setSetpointWithTime (float newTargetInDegrees, long miliseconds, interpolateMode mode)
 
void setSpeed (float newDegreesPerSecond)
 
void setSpeed (float newDegreesPerSecond, long miliseconds)
 
void moveTo (float newTargetInDegrees, float speedDegPerSec)
 
void moveFor (float deltaTargetInDegrees, float speedDegPerSec)
 
void blockUntilMoveIsDone ()
 wait for the motor to arrive at a setpoint More...
 
float startMoveFor (float deltaTargetInDegrees, float speedDegPerSec)
 
void setSetpoint (float newTargetInDegrees)
 
void setSetpointWithLinearInterpolation (float newTargetInDegrees, long miliseconds)
 
void setSetpointWithSinusoidalInterpolation (float newTargetInDegrees, long miliseconds)
 
void setSetpointWithBezierInterpolation (float newTargetInDegrees, long miliseconds, float Control_0=0.5, float Control_1=1.0)
 
void setSetpointWithTrapezoidalInterpolation (float newTargetInDegrees, long miliseconds, float trapazoidalTime)
 
void setGains (float p, float i, float d)
 
void setGainsP (float p)
 
void setGainsI (float i)
 
void setGainsD (float d)
 
float getGainsP ()
 
float getGainsI ()
 
float getGainsD ()
 
bool isMotorDoneWithMove ()
 Check to see if the motor is done with a move. More...
 

Data Fields

int MotorPWMPin = -1
 
int directionFlag = -1
 
int MotorEncAPin = -1
 
int MotorEncBPin = -1
 
int64_t nowEncoder = 0
 

Static Public Attributes

static bool timersAllocated = false
 
static Motorlist [MAX_POSSIBLE_MOTORS]
 

Private Member Functions

void setEffortLocal (float effort)
 

Static Private Member Functions

static void allocateTimer (int PWMgenerationTimer)
 

Private Attributes

ESP32PWMpwm
 
ESP32Encoderencoder
 
bool isAttached = false
 
int interruptCountForVelocity = 0
 
int prevousCount = 0
 
float cachedSpeed = 0
 
float setpoint = 0
 
float kP = 0.02
 
float kI = 0.01
 
float kD = 0
 
float runntingITerm = 0
 
bool closedLoopControl = true
 
float targetEffort = 0
 
float currentEffort = 0
 
float duration = 0
 
float startTime = 0
 
float endSetpoint = 0
 
float startSetpoint = 0
 
float unitDuration = 1
 
interpolateMode mode = LINEAR_INTERPOLATION
 
float milisecondPosIncrementForVelocity
 
float BEZIER_P0 = 0.25
 BEZIER Control Point 0. More...
 
float BEZIER_P1 = 0.75
 BEZIER Control Point 1. More...
 
float TRAPEZOIDAL_time = 0
 the amount of time to ramp up and ramp down the speed More...
 

Detailed Description

A PID Motor class using FreeRTOS threads, ESP32Encoder and ESP32PWM.

This Motor class is intended to be used by RBE 1001 in the WPI Robotics Department.

Motor objects can be instantiated statically. The attach method must be called before using the motor.

The motor uses one timer for the ESP32PWM objects. That means the static method

Motor::allocateTimer (int PWMgenerationTimer)

must be called before any motor objects can be attached. This method will also start the PID thread.

Definition at line 43 of file Motor.h.

Constructor & Destructor Documentation

◆ Motor()

Motor::Motor ( int  pwmPin,
int  dirPin,
int  encAPin,
int  encBPin 
)

A PID Motor class using FreeRTOS threads, ESP32Encoder and ESP32PWM.

This Motor class is intended to be used by RBE 1001 in the WPI Robotics Department.

Motor objects can be instantiated statically. The attach method must be called before using the motor.

The motor uses one timer for the ESP32PWM objects. That means the static method

Motor::allocateTimer (int PWMgenerationTimer)

must be called before any motor objects can be attached. This method will also start the PID thread.

Definition at line 126 of file Motor.cpp.

References directionFlag, encoder, MotorEncAPin, MotorEncBPin, MotorPWMPin, and pwm.

◆ ~Motor()

Motor::~Motor ( )
virtual

Definition at line 136 of file Motor.cpp.

References ESP32PWM::detachPin(), encoder, MotorPWMPin, ESP32Encoder::pauseCount(), and pwm.

Here is the call graph for this function:

Member Function Documentation

◆ allocateTimer()

void Motor::allocateTimer ( int  PWMgenerationTimer)
staticprivate
Parameters
PWMgenerationTimerthe timer to be used to generate the 20khz PWM
PWMgenerationTimerthe timer to be used to generate the 20khx PWM
controllerTimera timer running at 1khz for PID, velocity measurment, and trajectory planning

Definition at line 115 of file Motor.cpp.

References ESP32PWM::allocateTimer(), complexHandlerTask, onMotorTimer(), and timersAllocated.

Referenced by attach().

Here is the call graph for this function:

◆ attach()

void Motor::attach ( )

◆ blockUntilMoveIsDone()

void Motor::blockUntilMoveIsDone ( )

wait for the motor to arrive at a setpoint

Note
this is a blocking function, it will block code for multiple seconds until the motor arrives at its given setpoint

Definition at line 249 of file Motor.cpp.

References attach(), isAttached, and isMotorDoneWithMove().

Referenced by getEffortPercent(), and moveFor().

Here is the call graph for this function:

◆ getCurrentDegrees()

float Motor::getCurrentDegrees ( )

getTicks

This function returns the current count of encoders

Returns
count

Definition at line 568 of file Motor.cpp.

References attach(), isAttached, nowEncoder, and TICKS_TO_DEGREES.

Referenced by getEffortPercent(), isMotorDoneWithMove(), loop(), moveTo(), WebPage::SendSetpoint(), setSpeed(), startMoveFor(), and updateDashboard().

Here is the call graph for this function:

◆ getDegreesPerSecond()

float Motor::getDegreesPerSecond ( )

getDegreesPerSecond

This function returns the current speed of the motor

Returns
the speed of the motor in degrees per second

Definition at line 551 of file Motor.cpp.

References attach(), cachedSpeed, isAttached, and TICKS_TO_DEGREES.

Referenced by getEffortPercent(), isMotorDoneWithMove(), loop(), and updateDashboard().

Here is the call graph for this function:

◆ getEffort()

float Motor::getEffort ( )

Definition at line 516 of file Motor.cpp.

References attach(), currentEffort, and isAttached.

Referenced by getEffortPercent(), and setEffortPercent().

Here is the call graph for this function:

◆ getEffortPercent()

float Motor::getEffortPercent ( )
inline

Definition at line 265 of file Motor.h.

References attach(), blockUntilMoveIsDone(), getCurrentDegrees(), getDegreesPerSecond(), getEffort(), loop(), moveFor(), moveTo(), setSetpointWithTime(), setSpeed(), and startMoveFor().

Referenced by loop(), and updateDashboard().

Here is the call graph for this function:

◆ getGainsD()

float Motor::getGainsD ( )
inline

Definition at line 467 of file Motor.h.

References attach(), isMotorDoneWithMove(), and kD.

Referenced by WebPage::SendPIDValues().

Here is the call graph for this function:

◆ getGainsI()

float Motor::getGainsI ( )
inline

Definition at line 461 of file Motor.h.

References attach(), and kI.

Referenced by WebPage::SendPIDValues().

Here is the call graph for this function:

◆ getGainsP()

float Motor::getGainsP ( )
inline

Definition at line 455 of file Motor.h.

References attach(), and kP.

Referenced by WebPage::SendPIDValues().

Here is the call graph for this function:

◆ getInterpolationUnitIncrement()

float Motor::getInterpolationUnitIncrement ( )

use the internal state and current time to comput where along the path from start to finish the interpolation is

getInterpolationUnitIncrement A unit vector from 0 to 1 representing the state of the interpolation.

Definition at line 32 of file Motor.cpp.

References attach(), BEZIER, BEZIER_P0, BEZIER_P1, duration, isAttached, mode, SINUSOIDAL_INTERPOLATION, startTime, TRAPEZOIDAL, TRAPEZOIDAL_time, and unitDuration.

Referenced by isMotorDoneWithMove(), and loop().

Here is the call graph for this function:

◆ isMotorDoneWithMove()

bool Motor::isMotorDoneWithMove ( )

Check to see if the motor is done with a move.

isMotorDoneWithMove

This checks that the interpolation is done, that the position is within 1 degree and that the velocity is close to zero

Definition at line 213 of file Motor.cpp.

References attach(), getCurrentDegrees(), getDegreesPerSecond(), getInterpolationUnitIncrement(), isAttached, setpoint, TAG, and TICKS_TO_DEGREES.

Referenced by blockUntilMoveIsDone(), and getGainsD().

Here is the call graph for this function:

◆ loop()

void Motor::loop ( )

Loop function this method is called by the timer to run the PID control of the motors and ensure strict timing

Definition at line 347 of file Motor.cpp.

References cachedSpeed, closedLoopControl, currentEffort, DELTA_EFFORT, encoder, endSetpoint, ESP32Encoder::getCount(), getInterpolationUnitIncrement(), I_TERM_SIZE, interruptCountForVelocity, kI, kP, milisecondPosIncrementForVelocity, mode, nowEncoder, prevousCount, runntingITerm, setEffortLocal(), setpoint, startSetpoint, targetEffort, unitDuration, and VELOCITY_MODE.

Referenced by getEffortPercent(), and onMotorTimer().

Here is the call graph for this function:

◆ moveFor()

void Motor::moveFor ( float  deltaTargetInDegrees,
float  speedDegPerSec 
)

MoveFor a relative amount in degrees with speed Set the setpoint for the motor in degrees and the speed you want to get there Bascially, a wrapper function for SetSetpointWithTime that takes speed as an argument

Parameters
deltaTargetInDegreesthe new relative setpoint for the closed loop controller
speedDegPerSecis the speed in degrees per second
Note
this is a blocking function, it will block code for multiple seconds until the motor arrives at its given setpoint

moveFor a relative amount in degrees with speed Set the setpoint for the motor in degrees and the speed you want to get there Bascially, a wrapper function for setSetpointWithTime that takes speed as an argument

Parameters
deltaTargetInDegreesthe new relative setpoint for the closed loop controller
speedDegPerSecis the speed in degrees per second
Note
this is a blocking function, it will block code for multiple seconds until the motor arrives at its given setpoint

Definition at line 269 of file Motor.cpp.

References attach(), blockUntilMoveIsDone(), isAttached, and startMoveFor().

Referenced by getEffortPercent().

Here is the call graph for this function:

◆ moveTo()

void Motor::moveTo ( float  newTargetInDegrees,
float  speedDegPerSec 
)

MoveTo in degrees with speed Set the setpoint for the motor in degrees and the speed you want to get there Bascially, a wrapper function for SetSetpointWithTime that takes speed as an argument

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
speedDegPerSecis the speed in degrees per second

moveTo in degrees with speed Set the setpoint for the motor in degrees and the speed you want to get there Bascially, a wrapper function for setSetpointWithTime that takes speed as an argument

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
speedDegPerSecis the speed in degrees per second

Definition at line 182 of file Motor.cpp.

References attach(), getCurrentDegrees(), isAttached, and setSetpointWithBezierInterpolation().

Referenced by getEffortPercent(), and loop().

Here is the call graph for this function:

◆ setEffort()

void Motor::setEffort ( float  effort)

Definition at line 495 of file Motor.cpp.

References attach(), closedLoopControl, isAttached, and targetEffort.

Referenced by setEffortPercent().

Here is the call graph for this function:

◆ setEffortLocal()

void Motor::setEffortLocal ( float  effort)
private

Definition at line 529 of file Motor.cpp.

References attach(), directionFlag, isAttached, pwm, and ESP32PWM::writeScaled().

Referenced by loop().

Here is the call graph for this function:

◆ setEffortPercent()

void Motor::setEffortPercent ( float  percent)
inline

Definition at line 244 of file Motor.h.

References attach(), getEffort(), and setEffort().

Here is the call graph for this function:

◆ setGains()

void Motor::setGains ( float  p,
float  i,
float  d 
)

PID gains for the PID controller

Definition at line 418 of file Motor.cpp.

References attach(), isAttached, kD, kI, kP, and runntingITerm.

Referenced by setSetpointWithTrapezoidalInterpolation().

Here is the call graph for this function:

◆ setGainsD()

void Motor::setGainsD ( float  d)

Definition at line 447 of file Motor.cpp.

References attach(), isAttached, kD, and runntingITerm.

Referenced by WebPage::initalize(), setSetpointWithTrapezoidalInterpolation(), and WebPage::UpdatePIDValues().

Here is the call graph for this function:

◆ setGainsI()

void Motor::setGainsI ( float  i)

Definition at line 439 of file Motor.cpp.

References attach(), isAttached, kI, and runntingITerm.

Referenced by WebPage::initalize(), setSetpointWithTrapezoidalInterpolation(), and WebPage::UpdatePIDValues().

Here is the call graph for this function:

◆ setGainsP()

void Motor::setGainsP ( float  p)

Definition at line 431 of file Motor.cpp.

References attach(), isAttached, kP, and runntingITerm.

Referenced by WebPage::initalize(), setSetpointWithTrapezoidalInterpolation(), and WebPage::UpdatePIDValues().

Here is the call graph for this function:

◆ setSetpoint()

void Motor::setSetpoint ( float  newTargetInDegrees)
inline

SetSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller

Definition at line 366 of file Motor.h.

References attach(), LINEAR_INTERPOLATION, and setSetpointWithTime().

Referenced by setSpeed(), and WebPage::UpdateSetpoint().

Here is the call graph for this function:

◆ setSetpointWithBezierInterpolation()

void Motor::setSetpointWithBezierInterpolation ( float  newTargetInDegrees,
long  miliseconds,
float  Control_0 = 0.5,
float  Control_1 = 1.0 
)
inline

SetSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
milisecondsthe number of miliseconds to get from current position to the new setpoint
Control_0On a scale of 0 to 1, where should the first control point in the equation go
Control_1On a scale of 0 to 1, where should the second control point in the equation go use Bezier interpolation

Definition at line 413 of file Motor.h.

References attach(), BEZIER, and setSetpointWithTime().

Referenced by moveTo(), and startMoveFor().

Here is the call graph for this function:

◆ setSetpointWithLinearInterpolation()

void Motor::setSetpointWithLinearInterpolation ( float  newTargetInDegrees,
long  miliseconds 
)
inline

SetSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
milisecondsthe number of miliseconds to get from current position to the new setpoint use linear interoplation

Definition at line 380 of file Motor.h.

References attach(), LINEAR_INTERPOLATION, and setSetpointWithTime().

Referenced by loop().

Here is the call graph for this function:

◆ setSetpointWithSinusoidalInterpolation()

void Motor::setSetpointWithSinusoidalInterpolation ( float  newTargetInDegrees,
long  miliseconds 
)
inline

SetSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
milisecondsthe number of miliseconds to get from current position to the new setpoint use sinusoidal interpolation

Definition at line 396 of file Motor.h.

References attach(), setSetpointWithTime(), and SINUSOIDAL_INTERPOLATION.

Referenced by loop(), and setSetpointWithTrapezoidalInterpolation().

Here is the call graph for this function:

◆ setSetpointWithTime()

void Motor::setSetpointWithTime ( float  newTargetInDegrees,
long  msTimeDuration,
interpolateMode  mode 
)

SetSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
milisecondsthe number of miliseconds to get from current position to the new setpoint param mode the interpolation mode

setSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
msTimeDurationthe number of miliseconds to get from current position to the new setpoint

Definition at line 150 of file Motor.cpp.

References attach(), closedLoopControl, duration, encoder, endSetpoint, ESP32Encoder::getCount(), isAttached, mode, setpoint, startSetpoint, startTime, TAG, and TICKS_TO_DEGREES.

Referenced by getEffortPercent(), setSetpoint(), setSetpointWithBezierInterpolation(), setSetpointWithLinearInterpolation(), setSetpointWithSinusoidalInterpolation(), setSetpointWithTrapezoidalInterpolation(), and setSpeed().

Here is the call graph for this function:

◆ setSetpointWithTrapezoidalInterpolation()

void Motor::setSetpointWithTrapezoidalInterpolation ( float  newTargetInDegrees,
long  miliseconds,
float  trapazoidalTime 
)
inline

SetSetpoint in degrees with time Set the setpoint for the motor in degrees

Parameters
newTargetInDegreesthe new setpoint for the closed loop controller
milisecondsthe number of miliseconds to get from current position to the new setpoint
trapazoidalTimemiliseconds for the ramping to take at the beginning and end.

use sinusoidal interpolation

Definition at line 433 of file Motor.h.

References attach(), setGains(), setGainsD(), setGainsI(), setGainsP(), setSetpointWithSinusoidalInterpolation(), setSetpointWithTime(), and TRAPEZOIDAL.

Here is the call graph for this function:

◆ setSpeed() [1/2]

void Motor::setSpeed ( float  newDegreesPerSecond)

SetSpeed in degrees with time Set the setpoint for the motor in degrees This implements "Red Queen" mode running interpolation in the PID controller.

"Now, here, you see, it takes all the running you can do, to keep in the same place.

If you want to get somewhere else, you must run at least twice as fast as that!"

— The Red Queen, Alice In Wonderland, Lewis Carroll

The way this velocity mode works is that the position target is moved forward every iteration of the PID loop. The position runs away continuously, in order to keep the velocity stable. A position increment is calculated, and added to the Position every 1ms of the loop()

Parameters
newDegreesPerSecondthe new speed in degrees per second

setSpeed in degrees with time Set the setpoint for the motor in degrees This implements "Red Queen" mode running interpolation in the PID controller.

"Now, here, you see, it takes all the running you can do, to keep in the same place.

If you want to get somewhere else, you must run at least twice as fast as that!"

— The Red Queen, Alice In Wonderland, Lewis Carroll

The way this velocity mode works is that the position target is moved forward every iteration of the PID loop. The position runs away continuously, in order to keep the velocity stable. A position increment is calculated, and added to the Position every 1ms of the loop()

Parameters
newDegreesPerSecondthe new speed in degrees per second

Definition at line 295 of file Motor.cpp.

References attach(), closedLoopControl, getCurrentDegrees(), isAttached, milisecondPosIncrementForVelocity, mode, setSetpoint(), TICKS_TO_DEGREES, and VELOCITY_MODE.

Referenced by getEffortPercent(), loop(), runStateMachine(), and setSpeed().

Here is the call graph for this function:

◆ setSpeed() [2/2]

void Motor::setSpeed ( float  newDegreesPerSecond,
long  miliseconds 
)

SetSpeed in degrees with time Set the setpoint for the motor in degrees

Parameters
newDegreesPerSecondthe new speed in degrees per second
milisecondsthe number of miliseconds to run for

setSpeed in degrees with time Set the setpoint for the motor in degrees

Parameters
newDegreesPerSecondthe new speed in degrees per second
milisecondsthe number of miliseconds to run for
Note
a value of 0 miliseconds will set the motor into open-ended run mode

Definition at line 326 of file Motor.cpp.

References attach(), getCurrentDegrees(), isAttached, LINEAR_INTERPOLATION, setSetpointWithTime(), and setSpeed().

Here is the call graph for this function:

◆ startMoveFor()

float Motor::startMoveFor ( float  deltaTargetInDegrees,
float  speedDegPerSec 
)

StartMoveFor a relative amount in degrees with speed Set the setpoint for the motor in degrees and the speed you want to get there Bascially, a wrapper function for SetSetpointWithTime that takes speed as an argument

Parameters
deltaTargetInDegreesthe new relative setpoint for the closed loop controller
speedDegPerSecis the speed in degrees per second

Definition at line 192 of file Motor.cpp.

References attach(), getCurrentDegrees(), isAttached, and setSetpointWithBezierInterpolation().

Referenced by getEffortPercent(), and moveFor().

Here is the call graph for this function:

Field Documentation

◆ BEZIER_P0

float Motor::BEZIER_P0 = 0.25
private

BEZIER Control Point 0.

https://stackoverflow.com/a/43071667

Definition at line 152 of file Motor.h.

Referenced by getInterpolationUnitIncrement().

◆ BEZIER_P1

float Motor::BEZIER_P1 = 0.75
private

BEZIER Control Point 1.

https://stackoverflow.com/a/43071667

Definition at line 158 of file Motor.h.

Referenced by getInterpolationUnitIncrement().

◆ cachedSpeed

float Motor::cachedSpeed = 0
private

this variable is the most recently calculated speed

Definition at line 70 of file Motor.h.

Referenced by getDegreesPerSecond(), and loop().

◆ closedLoopControl

bool Motor::closedLoopControl = true
private

this is a flag to switch between using the PID controller, or allowing the user to set effort 'directly'

Definition at line 108 of file Motor.h.

Referenced by loop(), setEffort(), setSetpointWithTime(), and setSpeed().

◆ currentEffort

float Motor::currentEffort = 0
private

variable for caching the current effort being sent to the PWM/direction pins

Definition at line 116 of file Motor.h.

Referenced by getEffort(), and loop().

◆ directionFlag

int Motor::directionFlag = -1

GPIO pin number of the motor direction output flag

Definition at line 173 of file Motor.h.

Referenced by attach(), Motor(), and setEffortLocal().

◆ duration

float Motor::duration = 0
private

PID controller Interpolation duration in miliseconds

Definition at line 120 of file Motor.h.

Referenced by getInterpolationUnitIncrement(), and setSetpointWithTime().

◆ encoder

ESP32Encoder* Motor::encoder
private

the object that keeps track of the motors position

Definition at line 53 of file Motor.h.

Referenced by attach(), loop(), Motor(), setSetpointWithTime(), and ~Motor().

◆ endSetpoint

float Motor::endSetpoint = 0
private

PID controller Interpolation setpoint for the interpolation to arrive at

Definition at line 128 of file Motor.h.

Referenced by loop(), and setSetpointWithTime().

◆ interruptCountForVelocity

int Motor::interruptCountForVelocity = 0
private

an internal counter that counts iterations of the PID loop this is used to calculate 50ms timing for calculation of the velocity

Definition at line 62 of file Motor.h.

Referenced by loop().

◆ isAttached

bool Motor::isAttached = false
private

◆ kD

float Motor::kD = 0
private

PID controller derivitive constant

Definition at line 86 of file Motor.h.

Referenced by getGainsD(), setGains(), and setGainsD().

◆ kI

float Motor::kI = 0.01
private

PID controller integral constant

Definition at line 82 of file Motor.h.

Referenced by getGainsI(), loop(), setGains(), and setGainsI().

◆ kP

float Motor::kP = 0.02
private

PID controller proportional constant

Definition at line 78 of file Motor.h.

Referenced by getGainsP(), loop(), setGains(), and setGainsP().

◆ list

Motor * Motor::list
static
Initial value:
= {
NULL,
}

This is a list of all of the Motor objects that have been attached. As a motor is attahed, it adds itself to this list of Motor pointers. This list is read by the PID thread and each object in the list has loop() called. once every milisecond.

Definition at line 200 of file Motor.h.

Referenced by WebPage::initalize(), WebPage::SendPIDValues(), WebPage::SendSetpoint(), WebPage::UpdatePIDValues(), and WebPage::UpdateSetpoint().

◆ milisecondPosIncrementForVelocity

float Motor::milisecondPosIncrementForVelocity
private

when using Red Queen mode for velocity interpolation, this is the amount of setpoint to add to the current setpoint every milisecond to maintain a smooth velocity trajectory.

Definition at line 146 of file Motor.h.

Referenced by loop(), and setSpeed().

◆ mode

interpolateMode Motor::mode = LINEAR_INTERPOLATION
private

Current interpolation mode, linear, sinusoidal or velocity

Definition at line 140 of file Motor.h.

Referenced by getInterpolationUnitIncrement(), loop(), setSetpointWithTime(), and setSpeed().

◆ MotorEncAPin

int Motor::MotorEncAPin = -1

GPIO pin number of the motor encoder A

Definition at line 177 of file Motor.h.

Referenced by attach(), and Motor().

◆ MotorEncBPin

int Motor::MotorEncBPin = -1

GPIO pin number of the motor encoder B

Definition at line 181 of file Motor.h.

Referenced by attach(), and Motor().

◆ MotorPWMPin

int Motor::MotorPWMPin = -1

GPIO pin number of the motor PWM pin

Definition at line 169 of file Motor.h.

Referenced by attach(), Motor(), and ~Motor().

◆ nowEncoder

int64_t Motor::nowEncoder = 0

Variable to store the latest encoder read from the encoder hardware as read by the PID thread. This variable is set inside the PID thread, and read outside.

Definition at line 190 of file Motor.h.

Referenced by getCurrentDegrees(), and loop().

◆ prevousCount

int Motor::prevousCount = 0
private

Definition at line 66 of file Motor.h.

Referenced by loop().

◆ pwm

ESP32PWM* Motor::pwm
private

the object that produces PWM for motor speed

Definition at line 49 of file Motor.h.

Referenced by attach(), Motor(), setEffortLocal(), and ~Motor().

◆ runntingITerm

float Motor::runntingITerm = 0
private

a variable to store the running avarage for the integral term

Definition at line 90 of file Motor.h.

Referenced by loop(), setGains(), setGainsD(), setGainsI(), and setGainsP().

◆ setpoint

float Motor::setpoint = 0
private

PID controller setpoint in encoder ticks

Definition at line 74 of file Motor.h.

Referenced by isMotorDoneWithMove(), loop(), and setSetpointWithTime().

◆ startSetpoint

float Motor::startSetpoint = 0
private

PID controller Interpolation setpoint at the start of interpolation

Definition at line 132 of file Motor.h.

Referenced by loop(), and setSetpointWithTime().

◆ startTime

float Motor::startTime = 0
private

PID controller Interpolation time in miliseconds that the interplation began

Definition at line 124 of file Motor.h.

Referenced by getInterpolationUnitIncrement(), and setSetpointWithTime().

◆ targetEffort

float Motor::targetEffort = 0
private

variable for storing target effort to allow for smoother accelerations

Definition at line 112 of file Motor.h.

Referenced by loop(), and setEffort().

◆ timersAllocated

bool Motor::timersAllocated = false
static

the is a flag to check if the timer has been allocated and the thread started.

Definition at line 194 of file Motor.h.

Referenced by allocateTimer(), and attach().

◆ TRAPEZOIDAL_time

float Motor::TRAPEZOIDAL_time = 0
private

the amount of time to ramp up and ramp down the speed

Definition at line 163 of file Motor.h.

Referenced by getInterpolationUnitIncrement().

◆ unitDuration

float Motor::unitDuration = 1
private

Duration of the interpolation mode, 1 equals done, 0 starting

Definition at line 136 of file Motor.h.

Referenced by getInterpolationUnitIncrement(), and loop().


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