makerbase-mks / MKS-SERVO42B

MKS SERVO42B is 3d printer closed loop stepper motor NEMA17 MKS SERVO42 developed by Makerbase that prevents losing steps. CPU is STM32F103C8T6 ARM 32-bit Cortex™-M3 CPU Core,72 MHz. Magnetic encoder is Allegro's A1333LLETR-T Contactless 0° to 360° angle sensor IC ,12bit .This Project open source hardware and code,support platformio build and upload firmware...
https://www.aliexpress.com/item/33032696338.html?spm=a2g0o.store_home.productList_8356958.pic_1
GNU General Public License v3.0
170 stars 70 forks source link

Add PID autocalibration routine. #22

Open lonelymyp opened 3 years ago

lonelymyp commented 3 years ago

An example of printing with an uncalibrated PID. Heavy hot end + high speed = Waves on the surface after corners wave

Procedure name in the original code: void PID_Autotune(void); Implementation example: https://github.com/Misfittech/nano_stepper/blob/b731396f2ec985e0e7baea13b0282bdc214aa09b/firmware/stepper_nano_zero/stepper_controller.cpp#L1644

Since there is no way to connect via uart, pid calibration becomes a problem, you need to reflash the controller to change the parameter manually. The original code had a PID autocalibration routine. It would be great to bring this procedure back and bring it to the menu on the display.

menuItem_t MenuMain[] = {   
        {"Calibrate", menuCalibrate, NULL},
        {"Test Cal", menuTestCal, NULL},
        {"Autotune PID", menuCalibrate, NULL},  //add new item
        {"Motor mA", motorCurrent, currentOptions},
        {"Hold mA", motorHoldCurrent, currentOptions},
        {"Microstep", microsteps, microstepOptions},
        {"EnablePin", enablePin, enablePinOptions},
        {"Dir Pin", dirPin, dirPinOptions},
        { "", NULL, NULL}
};

Of course, this will need to be repaired:

options_t controlLoopOptions[] = {
        {"Simple"},
        {"Pos PID"},
        {"Vel PID"},
        {""}
};

And for this you need to transfer the missing code for pidFeedback https://github.com/Misfittech/nano_stepper/blob/b731396f2ec985e0e7baea13b0282bdc214aa09b/firmware/stepper_nano_zero/stepper_controller.cpp#L1078