0

I'm developing a drone simulation in OpenModelica. In an equation block I am calculating velocity and position vectors, but I want to cap the velocity to a certain value. This is a simplified example of my drone block.

block drone

 parameter Real mass =  0.985;
 constant Real g = 9.8;
 constant Real maxSpeed = 15.0;

 Input Real Fx,Fy,Fz;

 Real x,y,z;
 Real vX,vY,vZ;

equation
 der(vX) = Fx / mass;
 der(vY) = Fy / mass;
 der(vZ) = Fz / (mass*g);

 der(x) = vX;
 der(y) = vY;
 der(z) = vZ;

end drone;

EDIT: The velocity vector in the example have to be capped only if the speed of the drone exceed the maxSpeed value

BigMautone
  • 17
  • 6

1 Answers1

2

As you have physically correct relations between force F, acceleration der(v), speed v and positions x, I wouldn't change anything there.

You could think about something like:

der(vZ) = if vZ >-1 then Fz / (mass*g) else 0;

which should result in something like: Velocity-limit

But I think it would be better to add some kind of friction model, which could be something like:

 der(vZ) = (Fz-vZ*3) / (mass*g);

with 3 being a coefficient for linear friction (chosen to get a nice plot). Note that the above is very rudimentary and should be refined quite a bit - the intention is just to give an idea.
The result: Friction

Markus A.
  • 6,300
  • 10
  • 26
  • Thanks for your answer. One more thing, some days ago i tried the first method but the simulation get stuck. The line of code goes like this: der(vZ) = if(vZ > 15) then 15 else Fz / ecc...; There it is some sort of error in this or something else? – BigMautone Apr 26 '22 at 14:17
  • When using switching conditions like this, it is pretty common to end up with chattering. This usually results in an extremely bad simulation performance (essentially no progress) but the model does not fail. Some more info here: https://mbe.modelica.university/behavior/discrete/decay/#chattering – Markus A. Apr 26 '22 at 15:14
  • If i want to avoid chattering, how can i try to cap velocity? Using a friction model would be good, but if the environment size is too big, velocity will always exceet the predefined value of maxSpeed. P.S. The velocity have to be capped only if the speed of the drone exceed the maxSpeed. I'll edit the question – BigMautone Apr 26 '22 at 15:36
  • You need to reformulate the equations in a way, that they don't switch so frequently. If reformulating is difficult, it is often possible to use hysteresis (see e.g. Modelica.Blocks.Logical.Hysteresis) and/or filtering the used signals. – Markus A. Apr 27 '22 at 06:28