Saturation Function for Sliding Mode Control

Hi,

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.

Thanks in advance.

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.

What is it that you really want to know?

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.

Thanks in advance.

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;
}

there are other sigmoid functions

Thanks a lot for the answer. We are going to try that. We'll tell you later how it goes.

some more sat functions, can be adjusted. The gompertz is interesting because you have 3 params to tweak with.

float sat(float value, float steepness=1)
{
  return atan(steepness * value) * 0.636619772;     // 0.63.. == 2/pi  as atan goes form -pi/2 .. pi/2 one needs to multiply with the reciproke;
}

float sat2(float value, float steepness=1)
{
  return 1.0/(1 + exp(-steepness * value));
}

// http://en.wikipedia.org/wiki/Gompertz_curve
float Gompertz(float x, float a=1, float b=1, float c=1)
{
  return a * exp(b * exp(c * x));
}

Hurtex:
Thanks a lot for the answer. We are going to try that. We'll tell you later how it goes.

Hi Hurtex, I want to learn how to program sliding mode on Arduino, just if you don't mind to share your code and some infos. Thanks.

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.

Do you do any SMC in arduino?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.