Skip to content

Commit

Permalink
Removed min step condition as it was interferring with the I-gain fro…
Browse files Browse the repository at this point in the history
…m the controller
  • Loading branch information
ChrGri committed Sep 18, 2023
1 parent b4c5276 commit d702bfb
Show file tree
Hide file tree
Showing 11 changed files with 11,196 additions and 57,382 deletions.
8 changes: 4 additions & 4 deletions Arduino/Esp32/Main/Main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ LoadCell_ADS1256* loadcell = NULL;

#include "StepperWithLimits.h"
StepperWithLimits* stepper = NULL;
static const int32_t MIN_STEPS = 5;
//static const int32_t MIN_STEPS = 5;

#include "StepperMovementStrategy.h"

Expand Down Expand Up @@ -544,9 +544,9 @@ void pedalUpdateTask( void * pvParameters )

// get current stepper position right before sheduling a new move
//int32_t stepperPosCurrent = stepper->getCurrentPositionSteps();
int32_t stepperPosCurrent = stepper->getTargetPositionSteps();
int32_t movement = abs(stepperPosCurrent - Position_Next);
if (movement > MIN_STEPS)
//int32_t stepperPosCurrent = stepper->getTargetPositionSteps();
//int32_t movement = abs(stepperPosCurrent - Position_Next);
//if (movement > MIN_STEPS)
{
stepper->moveTo(Position_Next, false);
}
Expand Down
19 changes: 15 additions & 4 deletions Arduino/Esp32/Main/StepperMovementStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ int32_t MoveByPidStrategy(float loadCellReadingKg, float stepperPosFraction, Ste
//turn the PID on
myPID.SetTunings(Kp, Ki, Kd);
myPID.SetMode(myPID.Control::automatic);
//myPID.SetAntiWindupMode(myPID.iAwMode::iAwCondition);
myPID.SetAntiWindupMode(myPID.iAwMode::iAwClamp);
//myPID.SetAntiWindupMode(myPID.iAwMode::iAwOff);


pidWasInitialized = true;
myPID.SetSampleTimeUs(PUT_TARGET_CYCLE_TIME_IN_US);
myPID.SetOutputLimits(-1.0,0.0);
Expand All @@ -86,20 +91,26 @@ int32_t MoveByPidStrategy(float loadCellReadingKg, float stepperPosFraction, Ste

// clip to min & max force to prevent Ki to overflow
float loadCellReadingKg_clip = constrain(loadCellReadingKg, calc_st->Force_Min, calc_st->Force_Max);

float loadCellTargetKg_clip = constrain(loadCellTargetKg, calc_st->Force_Min, calc_st->Force_Max);


// normalize input & setpoint
//Setpoint = (loadCellReadingKg_clip - calc_st.Force_Min) / calc_st.Force_Range;
//Input = (loadCellTargetKg - calc_st.Force_Min) / calc_st.Force_Range;

Setpoint = (loadCellTargetKg - calc_st->Force_Min) / calc_st->Force_Range;
Setpoint = (loadCellTargetKg_clip - calc_st->Force_Min) / calc_st->Force_Range;
Input = (loadCellReadingKg_clip - calc_st->Force_Min) / calc_st->Force_Range;

// compute PID output
myPID.Compute();

// unnormalize output
int32_t posStepperNew = -1.0 * Output * (calc_st->stepperPosMax - calc_st->stepperPosMin);//stepper->getTravelSteps();
posStepperNew += calc_st->stepperPosMin;
//int32_t posStepperNew = -1.0 * Output * (float)(calc_st->stepperPosMax - calc_st->stepperPosMin);//stepper->getTravelSteps();
//posStepperNew += calc_st->stepperPosMin;

float posStepperNew_fl32 = -1.0 * Output * (float)(calc_st->stepperPosMax - calc_st->stepperPosMin);//stepper->getTravelSteps();
posStepperNew_fl32 += calc_st->stepperPosMin;
int32_t posStepperNew = floor(posStepperNew_fl32);

//#define PLOT_PID_VALUES
#ifdef PLOT_PID_VALUES
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Arduino/Esp32/arduinoCliBuildScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# for Arduino-cli help, see https://arduino.github.io/arduino-cli/0.33/commands/arduino-cli_compile/


arduino-cli compile --fqbn esp32:esp32:fm-devkit --output-dir Arduino/Esp32/bin Arduino/Esp32/Main/.
arduino-cli compile --fqbn esp32:esp32:fm-devkit --output-dir bin Main/.
Binary file modified Arduino/Esp32/bin/Main.ino.bin
Binary file not shown.
Binary file modified Arduino/Esp32/bin/Main.ino.elf
Binary file not shown.
22,357 changes: 11,176 additions & 11,181 deletions Arduino/Esp32/bin/Main.ino.map

Large diffs are not rendered by default.

46,192 changes: 0 additions & 46,192 deletions Arduino/Esp32/bin_s2_mini/Main.ino.map

This file was deleted.

0 comments on commit d702bfb

Please sign in to comment.