0

I'm developing a simulation of a swarm of drones in OpenModelica. The problem is that a lot of scenary can happen in the simulation, and two of the most common are

  1. battery at 0%
  2. collision with other objects.

In both cases, i want the drone to fall, until it reaches the floor, which in my simulation is equal to z = 0, and it won't change its position.

I don't know how to do it because my code calculate velocity with derivative functions, here is an example of how my code works:

block drone 
if(battery[i] <= 0 or droneDead)
       Trustx := (tmpFx/K.m);
       Trusty := (tmpFy/K.m);
       Trustz := (tmpFz/K.m);
else
        Trustx := if(z > 5) then -(K.m * K.g) else 0;
        Trusty := if(z > 5) then -(K.m * K.g) else 0;
        Trustz := if(z > 5) then -(K.m * K.g) else 0;
end if;
equation
        der(Vx) = Trustx;   
        der(Vy) = Trusty;
        der(Vz) = Trustz;   

        der(x) = Vx;
        der(y) = Vy;
        der(z) = Vz; 
end drone;

If this example is not explaing the question or is not good to read, i will edit it soon or i will link the .mo file

BigMautone
  • 17
  • 6
  • Comment - If you want to run this code on each drone, you will need to implement a for loop. Question - It looks like Trustx, y & z represent acceleration on each axis. If the unit is falling, shouldn't Trustx and Trusty be zero and Trustz be 1 g (assuming this is K.g)? – Jonathon S. May 03 '22 at 23:47
  • Comment answer - yes,it's a loop but i forgot to enter it in the example. Question answer - I actually did it, but i want the drone to stop when it hits the ground – BigMautone May 04 '22 at 15:42
  • Would it help to use `reinit()`? Like in https://mbe.modelica.university/behavior/discrete/bouncing/ but with something like: `when z<5 then reinit(Vz, 0); end when;` – Markus A. May 05 '22 at 06:39

0 Answers0