Commit 32aad29a authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

erp5_officejs_drone_simulator: implement proper parachute landing

parent ce80c289
......@@ -6,6 +6,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
"use strict";
var DEFAULT_SPEED = 16,
PARACHUTE_SPEED = 8,
EARTH_GRAVITY = 9.81,
LOITER_LIMIT = 30,
MAX_ACCELERATION = 6,
......@@ -98,8 +99,12 @@ var FixedWingDroneAPI = /** @class */ (function () {
** Function called on every drone update, right before onUpdate AI script
*/
FixedWingDroneAPI.prototype.internal_update = function (context, delta_time) {
this._updateSpeed(context, delta_time);
this._updatePosition(context, delta_time);
if (context.position.z > 0) {
this._updateSpeed(context, delta_time);
this._updatePosition(context, delta_time);
} else {
context.setDirection(0, 0, 0);
}
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
......@@ -486,8 +491,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
function (altitude_diff, max_climb_rate, speed, max_pitch) {
var maxVerticalSpeed =
Math.min(altitude_diff, Math.min(max_climb_rate, speed));
return (this._toDeg(Math.asin(maxVerticalSpeed / speed)) > max_pitch) ?
speed * Math.sin(this._toRad(max_pitch))
return (this._toDeg(Math.asin(maxVerticalSpeed / speed)) > max_pitch)
? speed * Math.sin(this._toRad(max_pitch))
: maxVerticalSpeed;
};
FixedWingDroneAPI.prototype._toRad = function (angle) {
......@@ -511,11 +516,16 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(
this._flight_parameters.drone.minSpeed = 0;
drone._speed = 0;
drone._acceleration = EARTH_GRAVITY;
this._flight_parameters.drone.maxSinkRate = PARACHUTE_SPEED;
this._flight_parameters.drone.minPitchAngle = -90;
drone._internal_setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
0,
drone.get3DSpeed()
-PARACHUTE_SPEED,
PARACHUTE_SPEED
);
this._is_ready_to_fly = false;
this._is_landing = true;
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.60733.7318.44953</string> </value>
<value> <string>1015.19974.55909.31829</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709564488.61</float>
<float>1710776360.59</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -360,7 +360,9 @@ var DroneManager = /** @class */ (function () {
return this._API.takeOff();
};
DroneManager.prototype.land = function () {
return this._API.land(this);
if (!this.isLanding()) {
return this._API.land(this);
}
};
DroneManager.prototype.exit = function () {
return this._internal_crash();
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.15587.24859.64699</string> </value>
<value> <string>1015.21423.13957.6792</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1710512866.57</float>
<float>1710863670.4</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -7,6 +7,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
// var TAKEOFF_RADIUS = 60,
var DEFAULT_SPEED = 16,
PARACHUTE_SPEED = 8,
EARTH_GRAVITY = 9.81,
LOITER_LIMIT = 30,
MAX_ACCELERATION = 6,
......@@ -373,8 +374,6 @@ var FixedWingDroneAPI = /** @class */ (function () {
var processed_coordinates =
this._mapManager.convertToLocalCoordinates(lat, lon, z);
processed_coordinates.z -= this._map_dict.start_AMSL;
//this._last_altitude_point_reached = -1;
//this.takeoff_path = [];
return processed_coordinates;
};
FixedWingDroneAPI.prototype.getCurrentPosition = function (x, y, z) {
......@@ -470,11 +469,16 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(
this._flight_parameters.drone.minSpeed = 0;
drone._speed = 0;
drone._acceleration = EARTH_GRAVITY;
this._flight_parameters.drone.maxSinkRate = PARACHUTE_SPEED;
this._flight_parameters.drone.minPitchAngle = -90;
drone._internal_setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
0,
drone.get3DSpeed()
PARACHUTE_SPEED
);
this._is_ready_to_fly = false;
this._is_landing = true;
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.60733.7318.44953</string> </value>
<value> <string>1015.19909.43325.57463</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1709562449.93</float>
<float>1710776370.92</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -316,7 +316,9 @@ var DroneManager = /** @class */ (function () {
return this._API.takeOff();
};
DroneManager.prototype.land = function () {
return this._API.land(this);
if (!this.isLanding()) {
return this._API.land(this);
}
};
DroneManager.prototype.exit = function () {
return this._internal_crash();
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.15585.15092.32085</string> </value>
<value> <string>1015.21142.6327.53794</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1710512741.55</float>
<float>1710863206.6</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -122,7 +122,8 @@
' }\n' +
' return;\n' +
' }\n' +
' me.exit(0);\n' +
' if (!me.isLanding()) { me.land() };\n' +
' if (me.getCurrentPosition().altitude <= 0) { me.exit(0) };\n' +
'};',
DRAW = true,
LOG = true,
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.60725.60577.24917</string> </value>
<value> <string>1015.15836.20157.60791</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709289017.41</float>
<float>1710527785.95</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment