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
- battery at 0%
- 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