Loading...
Pages: [1]   Go Down
Author Topic: Saturation Function for Sliding Mode Control  (Read 765 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6391
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

USA
Offline Offline
Full Member
***
Karma: 3
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So the question is, how to implement a Saturation function on Arduino?

Well, uh, you write something like this:
Code:
...
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
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

Code:
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
- see - http://en.wikipedia.org/wiki/Sigmoid_function - and
- http://en.wikipedia.org/w/index.php?title=File:Gjl-t(x).svg&page=1 -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

some more sat functions, can be adjusted. The gompertz is interesting because you have 3 params to tweak with.
Code:
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));
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: [1]   Go Up
Print
 
Jump to: