We are trying to implement a Sliding Mode Control on Arduino. On Theory SMC uses the Sign function. But, for stability issues we simulated (on Simulink) it with a Saturator getting better results.
So the question is, how to implement a Saturation function on Arduino? We want to avoid the abrupt change from values given by the sign function.
I have no idea what any of those terms mean, but in order to use an algorithm on an Arduino you need to either understand the algorithm and design the code to implement it, or find somebody who has already done it and shared their work. So you could try Google I suppose, and if you can't find anybody else's solution you need to understand the algorithm and implement it for yourself.
Hurtex:
So the question is, how to implement a Saturation function on Arduino?
Well, uh, you write something like this:
...
u = k*sat(s);
...
int sat(float s) {
if (s > 1) return -1;
if (s < -1) return -1;
return s;
}
That's a saturation function. It's a simple one. The odds are high that, out of the infinite-dimensional space of possible functions, this isn't exactly the one you want.
For anyone who's actually contemplating sliding mode control on an Arduino, this task should be trivial. You shouldn't be asking this question.
The control algorithm for Sliding Mode Control we have already implemented in Arduino, what I'm asking is the following:
Sliding Mode Control uses the sign function theoretically. The function you posted works for that and it's what we are already using. In practice, it would be better to use a saturation function since it gives a more stable control with less chatering (imagine an infinate switching of low amplitude in your output which is caused by the sign function).
In Matlab it's as simple as placing your saturation block. While the sign function the change from -1 to 1 it's instantaneus, for saturation it's gradually. Has the saturation function been implemented in Arduino? I already tried searching for it with no results.
int sat(float s) {
if (s > 1) return -1; <=== should be 1
if (s < -1) return -1;
return s;
}
a smooth transition from -1 to 1 can be made with the atan function
float sat(float value)
{
// speed up some math; 20 is modifiable
if (value < -20) return -1;
if (value > 20) return 1;
// workhorse
float f = 10.0 * value; // 10 is a parameter to adjust the steepness
float rv = atan(f) * 0,636619772; // 0.63.. == 2/pi as atan goes form -pi/2 .. pi/2 one needs to multiply with the reciproke;
return rv;
}
Hello, I am trying to make a control in sliding mode but I can't find many examples of how to implement the sliding surface by code, could you do me the favor of giving an explanation of the SMC or how you did yours, I would appreciate a lot if you share information.