From 749fe8c6d55b3b5ab502ac8b77613613341c1508 Mon Sep 17 00:00:00 2001 From: Dmitriy Antipov Date: Tue, 18 Jul 2023 21:18:48 +0300 Subject: [PATCH] Add reset block (#6) * Update pid.ts * description Description warning. I noticed a bug that when you use a controller instance with a certain number before and reuse it again the next time and do a reset before setting the values \u200b\u200band or the regulation limits, then the controller for some reason leads the control action to one side. For example, I put the ev3 robot on a line, two color sensors. Judging by the values from the sensors, it should go straight (the control action should be near zero), but the controller shows that it wants to take the robot to the side. The problem is not always, but often. Example... automation.pid1.reset(); automation.pid1.setGains(KP_LINE_FOLLOW, 0, KD_LINE_FOLLOW); automation.pid1.setControlSaturation(-100, 100); If the reset is done after, then the problem does not occur at all. automation.pid1.setGains(KP_LINE_FOLLOW, 0, KD_LINE_FOLLOW); automation.pid1.setControlSaturation(-100, 100); automation.pid1.reset(); --- pid.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pid.ts b/pid.ts index 8a7e117..a30c26b 100644 --- a/pid.ts +++ b/pid.ts @@ -84,13 +84,19 @@ namespace automation { this.reset(); } + /** + * Reset pid instance. Do a reset after setting the coefficients and limit range. + * @param pid necessary pid for reset + */ + //% blockId=pidReset block="reset %pid" + //% group=PID reset() { this.I = 0; this.D = 0; } /** - * Sets the PID gains + * Sets the PID gains. * @param kp proportional gain * @param ki integral gain * @param kd derivative gain @@ -117,7 +123,7 @@ namespace automation { } /** - * Sets the control saturation values + * Sets the control saturation values. * @param low lowest control value, eg: -100 * @param high highest control value, eg: 100 */ @@ -128,7 +134,7 @@ namespace automation { } /** - * Sets the derivative filter gain + * Sets the derivative filter gain. * @param N the filter gain, eg:10 */ //% blockId=pidSetDerivativeFilter block="set %pid|derivative filter %N" @@ -139,7 +145,7 @@ namespace automation { } /** - * Updates the desired setpoint + * Updates the desired setpoint. * @param ysp */ //% blockId=pidSetPoint block="set %pid|point to %ysp" @@ -148,7 +154,7 @@ namespace automation { } /** - * Computes the output based on the system state + * Computes the output based on the system state. */ //% blockId=pidCompute block="%pid|compute for timestep %timestep|(ms) at state %y" //% group=PID