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

erp5_officejs_drone_simulator: command contraints

Introduce `_callSetTargetCommand` function to regroup contraints on
command calls. Commands like `takeOff` and `land` should have such
constraints and therefore use `_internal_setTargetCoordinates` directly.
parent f159d4f2
...@@ -141,23 +141,32 @@ var DroneManager = /** @class */ (function () { ...@@ -141,23 +141,32 @@ var DroneManager = /** @class */ (function () {
this._internal_crash(error); this._internal_crash(error);
} }
}; };
DroneManager.prototype._callSetTargetCommand =
function (latitude, longitude, altitude, speed, radius) {
if (!this.isReadyToFly()) {
return;
}
if (this._API._gameManager._game_duration - this._last_command_timestamp
< 1000 / this._API.getMaxCommandFrequency()) {
this._internal_crash(new Error('Minimum interval between commands is ' +
1000 / this._API.getMaxCommandFrequency() + ' milliseconds'));
}
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed,
radius);
this._last_command_timestamp = this._API._gameManager._game_duration;
};
/** /**
* Set a target point to move * Set a target point to move
*/ */
DroneManager.prototype.setTargetCoordinates = DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude, speed) { function (latitude, longitude, altitude, speed) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed); this._callSetTargetCommand(latitude, longitude, altitude, speed);
}; };
DroneManager.prototype._internal_setTargetCoordinates = DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) { function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay || !this.isReadyToFly()) { if (!this._canPlay) {
return; return;
} }
if (this._API._gameManager._game_duration - this._last_command_timestamp
< 1000 / this._API.getMaxCommandFrequency()) {
this._internal_crash(new Error('Minimum interval between commands is ' +
1000 / this._API.getMaxCommandFrequency() + ' milliseconds'));
}
//each drone API process coordinates on its needs //each drone API process coordinates on its needs
//e.g. fixedwing drone converts real geo-coordinates to virtual x-y //e.g. fixedwing drone converts real geo-coordinates to virtual x-y
this._targetCoordinates = this._targetCoordinates =
...@@ -168,7 +177,6 @@ var DroneManager = /** @class */ (function () { ...@@ -168,7 +177,6 @@ var DroneManager = /** @class */ (function () {
speed, speed,
radius radius
); );
this._last_command_timestamp = this._API._gameManager._game_duration;
}; };
DroneManager.prototype.getDroneDict = function () { DroneManager.prototype.getDroneDict = function () {
return this._API._drone_dict_list; return this._API._drone_dict_list;
...@@ -319,13 +327,7 @@ var DroneManager = /** @class */ (function () { ...@@ -319,13 +327,7 @@ var DroneManager = /** @class */ (function () {
*/ */
DroneManager.prototype.loiter = DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius, speed) { function (latitude, longitude, altitude, radius, speed) {
this._internal_setTargetCoordinates( this._callSetTargetCommand(latitude, longitude, altitude, speed, radius);
latitude,
longitude,
altitude,
speed,
radius
);
}; };
DroneManager.prototype.getFlightParameters = function () { DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) { if (this._API.getFlightParameters) {
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1015.15557.49327.13158</string> </value> <value> <string>1015.15587.24859.64699</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1710511088.86</float> <float>1710512866.57</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -130,23 +130,32 @@ var DroneManager = /** @class */ (function () { ...@@ -130,23 +130,32 @@ var DroneManager = /** @class */ (function () {
this._internal_crash(error); this._internal_crash(error);
} }
}; };
DroneManager.prototype._callSetTargetCommand =
function (latitude, longitude, altitude, speed, radius) {
if (!this.isReadyToFly()) {
return;
}
if (this._API._gameManager._game_duration - this._last_command_timestamp
< 1000 / this._API.getMaxCommandFrequency()) {
this._internal_crash(new Error('Minimum interval between commands is ' +
1000 / this._API.getMaxCommandFrequency() + ' milliseconds'));
}
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed,
radius);
this._last_command_timestamp = this._API._gameManager._game_duration;
};
/** /**
* Set a target point to move * Set a target point to move
*/ */
DroneManager.prototype.setTargetCoordinates = DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude, speed) { function (latitude, longitude, altitude, speed) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed); this._callSetTargetCommand(latitude, longitude, altitude, speed);
}; };
DroneManager.prototype._internal_setTargetCoordinates = DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) { function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay || !this.isReadyToFly()) { if (!this._canPlay) {
return; return;
} }
if (this._API._gameManager._game_duration - this._last_command_timestamp
< 1000 / this._API.getMaxCommandFrequency()) {
this._internal_crash(new Error('Minimum interval between commands is ' +
1000 / this._API.getMaxCommandFrequency() + ' milliseconds'));
}
//convert real geo-coordinates to virtual x-y coordinates //convert real geo-coordinates to virtual x-y coordinates
this._targetCoordinates = this._targetCoordinates =
this._API.processCoordinates(latitude, longitude, altitude); this._API.processCoordinates(latitude, longitude, altitude);
...@@ -156,7 +165,6 @@ var DroneManager = /** @class */ (function () { ...@@ -156,7 +165,6 @@ var DroneManager = /** @class */ (function () {
speed, speed,
radius radius
); );
this._last_command_timestamp = this._API._gameManager._game_duration;
}; };
DroneManager.prototype.internal_update = function (delta_time) { DroneManager.prototype.internal_update = function (delta_time) {
var context = this; var context = this;
...@@ -284,13 +292,7 @@ var DroneManager = /** @class */ (function () { ...@@ -284,13 +292,7 @@ var DroneManager = /** @class */ (function () {
*/ */
DroneManager.prototype.loiter = DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius, speed) { function (latitude, longitude, altitude, radius, speed) {
this._internal_setTargetCoordinates( this._callSetTargetCommand(latitude, longitude, altitude, speed, radius);
latitude,
longitude,
altitude,
speed,
radius
);
}; };
DroneManager.prototype.getFlightParameters = function () { DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) { if (this._API.getFlightParameters) {
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1015.15533.18317.53657</string> </value> <value> <string>1015.15585.15092.32085</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1710509638.96</float> <float>1710512741.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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