9 static const char *
TAG =
"Motor Class";
26 return ((x - in_min) * (out_max - out_min) / (in_max - in_min)) + out_min;
36 float interpElapsed = (float)(millis() -
startTime);
37 if (interpElapsed < duration && duration > 0)
45 unitDuration = 1 - sinPortion;
56 unitDuration = pow((1 - t), 3) * P0 + 3 * t * pow((1 - t), 2) * P1 + 3 * pow(t, 2) * (1 - t) * P2 + pow(t, 3) * P3;
62 float unitLienear = lengthOfLinearMode /
duration;
64 float unitStartRampDown = unitLienear + unitRamp;
71 float sinPortion = 1 + cos(-PI * increment);
80 float increment = (
unitDuration - unitStartRampDown) / (unitRamp * 2) + 0.5;
81 float sinPortion = 0.5 - ((cos(-PI * increment) / 2) + 0.5);
82 unitDuration = (sinPortion * 2) * unitRamp + unitStartRampDown;
91 ESP_LOGI(
TAG,
"Starting the PID loop thread");
92 TickType_t xLastWakeTime;
93 const TickType_t xFrequency = 1;
94 xLastWakeTime = xTaskGetTickCount();
97 vTaskDelayUntil(&xLastWakeTime, xFrequency);
101 if (Motor::list[i] != NULL)
104 Motor::list[i]->
loop();
109 ESP_LOGE(
TAG,
"ERROR Pid thread died!");
120 xTaskCreatePinnedToCore(
onMotorTimer,
"PID loop Thread", 8192, NULL, 1,
159 if (newSetpoint ==
setpoint && msTimeDuration ==
duration && this->mode == mode)
166 if (msTimeDuration < 1)
170 ESP_LOGI(
TAG,
"Starting Interpolated move %.4f deg, %ld ms %d mode",
171 newTargetInDegrees, msTimeDuration, mode);
189 fabs(deltaMove / speedDegPerSec) * 1000.0, 0.2, 1);
199 fabs(deltaTargetInDegrees / speedDegPerSec) * 1000.0, 0.2, 1);
224 float distanceToGo = fabs(
227 if (distanceToGo > 0.75)
229 ESP_LOGD(
TAG,
"Move Remaining: %.4f", distanceToGo);
302 if (fabs(newDegreesPerSecond) < 0.1)
338 float distance = currentPos + (-newDegreesPerSecond * (((float)miliseconds) / 1000.0));
364 float newSetpoint = startSetpoint + (setpointDiff *
unitDuration);
477 if (Motor::list[i] == NULL)
481 Motor::list[i] =
this;
void setEffortLocal(float effort)
static void allocateTimer(int timerNumber)
void setSetpoint(float newTargetInDegrees)
float startMoveFor(float deltaTargetInDegrees, float speedDegPerSec)
Motor(int pwmPin, int dirPin, int encAPin, int encBPin)
A PID Motor class using FreeRTOS threads, ESP32Encoder and ESP32PWM.
void setSetpointWithTime(float newTargetInDegrees, long miliseconds, interpolateMode mode)
void attachPin(uint8_t pin)
void setSpeed(float newDegreesPerSecond)
void attach()
Attach the motors hardware.
void setGains(float p, float i, float d)
void setEffort(float effort)
int interruptCountForVelocity
#define MAX_POSSIBLE_MOTORS
float getCurrentDegrees()
float BEZIER_P0
BEZIER Control Point 0.
static TaskHandle_t complexHandlerTask
float milisecondPosIncrementForVelocity
void moveTo(float newTargetInDegrees, float speedDegPerSec)
float TRAPEZOIDAL_time
the amount of time to ramp up and ramp down the speed
A PID Motor class using FreeRTOS threads, ESP32Encoder and ESP32PWM.
static Motor * list[MAX_POSSIBLE_MOTORS]
float BEZIER_P1
BEZIER Control Point 1.
bool isMotorDoneWithMove()
Check to see if the motor is done with a move.
static bool timersAllocated
static void allocateTimer(int PWMgenerationTimer)
void setSetpointWithBezierInterpolation(float newTargetInDegrees, long miliseconds, float Control_0=0.5, float Control_1=1.0)
static enum puType useInternalWeakPullResistors
float getDegreesPerSecond()
void moveFor(float deltaTargetInDegrees, float speedDegPerSec)
void onMotorTimer(void *param)
void attachFullQuad(int aPintNumber, int bPinNumber)
void blockUntilMoveIsDone()
wait for the motor to arrive at a setpoint
float myFmapBounded(float x, float in_min, float in_max, float out_min, float out_max)
float getInterpolationUnitIncrement()
void writeScaled(float duty)