SOLVED Code: local outputAV1Smoother = newExponentialSmoothing(50) local outputAV2Smoother = newExponentialSmoothing(50) Code: local outputAV1 = outputAV1Smoother:get(differential.outputAV1) --left wheel local outputAV2 = outputAV2Smoother:get(differential.outputAV2) --right wheel Explanation here I'm creating an active locking/torque vectoring differential/transfercase that working in a proactive manner without DSE. For the use of non-DSE equipped vehicle(s), The 1st gen Pessima is currently being used as a testbed. The proactive part is already complete, I successively acquired the steering angle, lateral and horizontal g-forces. The problem is the reactive part: when too much speed difference between the shafts of a diff, a locking torque is applied. For example, when the inner wheel is 100 RPM higher than the outer wheel, increase the locking force. When the RPM difference is lower than 50, do not interfere. A differential has one input and two output. There are inputTorque, outputTorque1, outputTorque2 in N*m, and inputAV, outputAV1, outputAV2 in rad/s. Therefore to make the locking torque Code: 1000 * clamp(math.abs(outputAV2 - outputAV1) * 0.2 - 1,0,1) It can be interpreted as a mathematical functon Y = aX + b where a is 0.2 and b is -1 If directly used Code: differential.outputAV2 - differential.outputAV1 , then massive oscillation will occur. However, if use newExponentialSmoothing(50) to smooth the outputAV, then the "math.abs(outputAV2 - outputAV1) * 0.2 - 1" is no longer accurate as shown below Therefore, my "best guess" is set the function inaccurately, via trial and error "math.abs(outputAV2 - outputAV1) * 0.5 - 0.15", the a and b are 0.5 and -0.15 respectively. My question is how to make the outputAV not to oscillate during locking actuation and set the locking control with angular velocity accurately, and why does newExponentialSmoothing makes the values way off? and how to include a low-pass filter in the outputAV sensors? The WIP mod is in the attachment, the diffs are named "Torque Vectoring Rear Differential", "Clutched Front Differential" and "Clutched2 Front Differential", Clutched and Torque Vectoring are based on LSD, Clutched2 is based on Welded.
After looking through your code, one thing that stands out to me that probably is causing problems is that you are using the same "ExponentialSmoothing" object for smoothing the two output angular velocities. You should create separate "ExponentialSmoothing" objects for smoothing each output angular velocity independently. The reason is that the "ExponentialSmoothing:get" function uses the previous smoothed value to determine the new smoothed value. And basically with the way you are doing it now, when you smooth "outputAV2", the previous smoothed value is based on "outputAV1", which obviously can cause some problems
In addition to what was said above, a smoother will by design give you output values different than your input values, it will "invent" values inbetween your varying input values to make the transition smoother. Some types of smoothing can in theory also introduce values outside the original input range if not used correctly.