Commit a3c0dce6 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 14a5e22c
......@@ -141,23 +141,32 @@ var DroneManager = /** @class */ (function () {
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
*/
DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude, speed) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed);
this._callSetTargetCommand(latitude, longitude, altitude, speed);
};
DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay || !this.isReadyToFly()) {
if (!this._canPlay) {
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
//e.g. fixedwing drone converts real geo-coordinates to virtual x-y
this._targetCoordinates =
......@@ -168,7 +177,6 @@ var DroneManager = /** @class */ (function () {
speed,
radius
);
this._last_command_timestamp = this._API._gameManager._game_duration;
};
DroneManager.prototype.getDroneDict = function () {
return this._API._drone_dict_list;
......@@ -319,13 +327,7 @@ var DroneManager = /** @class */ (function () {
*/
DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius, speed) {
this._internal_setTargetCoordinates(
latitude,
longitude,
altitude,
speed,
radius
);
this._callSetTargetCommand(latitude, longitude, altitude, speed, radius);
};
DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) {
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.15557.49327.13158</string> </value>
<value> <string>1015.15587.24859.64699</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1710511088.86</float>
<float>1710512866.57</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -130,23 +130,32 @@ var DroneManager = /** @class */ (function () {
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
*/
DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude, speed) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed);
this._callSetTargetCommand(latitude, longitude, altitude, speed);
};
DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay || !this.isReadyToFly()) {
if (!this._canPlay) {
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
this._targetCoordinates =
this._API.processCoordinates(latitude, longitude, altitude);
......@@ -156,7 +165,6 @@ var DroneManager = /** @class */ (function () {
speed,
radius
);
this._last_command_timestamp = this._API._gameManager._game_duration;
};
DroneManager.prototype.internal_update = function (delta_time) {
var context = this;
......@@ -284,13 +292,7 @@ var DroneManager = /** @class */ (function () {
*/
DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius, speed) {
this._internal_setTargetCoordinates(
latitude,
longitude,
altitude,
speed,
radius
);
this._callSetTargetCommand(latitude, longitude, altitude, speed, radius);
};
DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) {
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.15533.18317.53657</string> </value>
<value> <string>1015.15585.15092.32085</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1710509638.96</float>
<float>1710512741.55</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