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

erp5_officejs_drone_simulator: use multicopter API

parent ef735f9b
......@@ -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) {
......@@ -465,16 +464,20 @@ var FixedWingDroneAPI = /** @class */ (function () {
+ Math.pow(direction.z * drone.get3DSpeed(), 2)
);
};
FixedWingDroneAPI.prototype.takeOff = function () {
FixedWingDroneAPI.prototype.takeOff = function (drone) {
return console.log("Fixed-wing drones can only be taken off manually.");
};
FixedWingDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone._speed = 0;
drone._acceleration = EARTH_GRAVITY;
this._flight_parameters.drone.maxSinkRate = PARACHUTE_SPEED;
this._flight_parameters.drone.minPitchAngle = -90;
drone.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.14195.32960.20019</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1709562449.93</float>
<float>1710429600.19</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) {
......@@ -311,7 +313,7 @@ var DroneManager = /** @class */ (function () {
return this._API.getClimbRate(this);
};
DroneManager.prototype.takeOff = function () {
return this._API.takeOff();
return this._API.takeOff(this);
};
DroneManager.prototype.land = function () {
return this._API.land(this);
......@@ -544,6 +546,7 @@ var GameManager = /** @class */ (function () {
}
this.APIs_dict = {
FixedWingDroneAPI: FixedWingDroneAPI,
MulticopterDroneAPI: MulticopterDroneAPI,
DroneLogAPI: DroneLogAPI
};
if (this._game_parameters_json.debug_test_mode) {
......@@ -763,8 +766,7 @@ var GameManager = /** @class */ (function () {
};
GameManager.prototype._timeOut = function () {
var seconds = Math.floor(this._game_duration / 1000);
return this._totalTime - seconds <= 0;
return this._totalTime - this._game_duration <= 0;
};
GameManager.prototype._allDronesFinished = function () {
......@@ -904,7 +906,7 @@ var GameManager = /** @class */ (function () {
_this.finish_deferred = RSVP.defer();
console.log("Simulation started.");
this._game_duration = Date.now();
this._totalTime = GAMEPARAMETERS.gameTime + this._game_duration;
this._totalTime = GAMEPARAMETERS.gameTime * 1000 + this._game_duration;
return new RSVP.Queue()
.push(function () {
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.65027.38618.31573</string> </value>
<value> <string>1015.15360.8933.15121</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1709560536.57</float>
<float>1710499343.13</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,11 +12,11 @@
max_lon = 14.2766,
map_height = 100,
start_AMSL = 595,
DEFAULT_SPEED = 16,
DEFAULT_SPEED = 5,
MAX_ACCELERATION = 6,
MAX_DECELERATION = 1,
MIN_SPEED = 12,
MAX_SPEED = 26,
MIN_SPEED = 0,
MAX_SPEED = 6,
MAX_ROLL = 35,
MIN_PITCH = -20,
MAX_PITCH = 25,
......@@ -26,7 +26,7 @@
INITIAL_POSITION = {
"latitude": 45.6412,
"longitude": 14.2658,
"altitude": 15
"altitude": 0
},
NUMBER_OF_DRONES = 2,
// Non-inputs parameters
......@@ -35,42 +35,34 @@
' EPSILON = 9,\n' +
' CHECKPOINT_LIST = [\n' +
' {\n' +
' altitude: 585.1806861589965,\n' +
' latitude: 45.64492790560583,\n' +
' longitude: 14.25334942966329\n' +
' },\n' +
' {\n' +
' altitude: 589.8802607573035,\n' +
' latitude: 45.64316335436476,\n' +
' longitude: 14.26332880184475\n' +
' },\n' +
' {\n' +
' altitude: 608.6648153348965,\n' +
' latitude: 45.64911917196595,\n' +
' longitude: 14.26214792790128\n' +
' },\n' +
' {\n' +
' altitude: 606.1448368129072,\n' +
' latitude: 45.64122685351364,\n' +
' longitude: 14.26590493128597\n' +
' },\n' +
' {\n' +
' altitude: 630.0829598206344,\n' +
' latitude: 45.64543355564817,\n' +
' longitude: 14.27242391207985\n' +
' },\n' +
' {\n' +
' altitude: 616.1839898415284,\n' +
' latitude: 45.6372792927328,\n' +
' longitude: 14.27533492411138\n' +
' },\n' +
' {\n' +
' altitude: 598.0603137354178,\n' +
' latitude: 45.64061299543953,\n' +
' longitude: 14.26161958465814\n' +
' },\n' +
' {\n' +
' altitude: 607.1243119862851,\n' +
' latitude: 45.64032340702919,\n' +
' longitude: 14.2682896662383\n' +
' }\n' +
......@@ -91,15 +83,17 @@
'me.onStart = function (timestamp) {\n' +
' me.direction_set = false;\n' +
' me.next_checkpoint = 0;\n' +
' me.takeOff();\n' +
'};\n' +
'\n' +
'me.onUpdate = function (timestamp) {\n' +
' if (!me.isReadyToFly()) { return; }\n' +
' if (!me.direction_set) {\n' +
' if (me.next_checkpoint < CHECKPOINT_LIST.length) {\n' +
' me.setTargetCoordinates(\n' +
' CHECKPOINT_LIST[me.next_checkpoint].latitude,\n' +
' CHECKPOINT_LIST[me.next_checkpoint].longitude,\n' +
' CHECKPOINT_LIST[me.next_checkpoint].altitude + ALTITUDE + ALTITUDE * me.id,\n' +
' ALTITUDE + ALTITUDE * me.id,\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
' console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);\n' +
......@@ -122,7 +116,8 @@
' }\n' +
' return;\n' +
' }\n' +
' me.exit(0);\n' +
' if (!me.isLanding()) { return me.land(); }\n' +
' if (me.getCurrentPosition().altitude <= 0) { return me.exit(0); }\n' +
'};',
DRAW = true,
LOG = true,
......@@ -133,6 +128,7 @@
LOGIC_FILE_LIST = [
'gadget_erp5_page_drone_simulator_logic.js',
'gadget_erp5_page_drone_simulator_fixedwingdrone.js',
'gadget_erp5_page_drone_simulator_multicopterdrone.js',
'gadget_erp5_page_drone_simulator_dronelogfollower.js'
];
......@@ -479,7 +475,7 @@
[domsugar('div')]).firstElementChild;
DRONE_LIST = [];
for (i = 0; i < options.number_of_drones; i += 1) {
DRONE_LIST[i] = {"id": i, "type": "FixedWingDroneAPI",
DRONE_LIST[i] = {"id": i, "type": "MulticopterDroneAPI",
"script_content": options.script};
}
game_parameters_json = {
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.60725.60577.24917</string> </value>
<value> <string>1015.14198.34281.16981</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709289017.41</float>
<float>1710429546.73</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -11,7 +11,7 @@
DEFAULT_SPEED = 16,
MAX_ACCELERATION = 6,
MAX_DECELERATION = 1,
MIN_SPEED = 12,
MIN_SPEED = 0,
MAX_SPEED = 26,
MAX_ROLL = 35,
MIN_PITCH = -20,
......@@ -97,6 +97,7 @@
LOGIC_FILE_LIST = [
'gadget_erp5_page_drone_simulator_logic.js',
'gadget_erp5_page_drone_simulator_fixedwingdrone.js',
'gadget_erp5_page_drone_simulator_multicopterdrone.js',
'gadget_erp5_page_drone_simulator_dronelogfollower.js'
];
......@@ -169,7 +170,7 @@
fragment = domsugar(gadget.element.querySelector('.simulator_div'),
[domsugar('div')]).firstElementChild;
for (i = 0; i < NUMBER_OF_DRONES; i += 1) {
DRONE_LIST[i] = {"id": i, "type": "FixedWingDroneAPI",
DRONE_LIST[i] = {"id": i, "type": "MulticopterDroneAPI",
"script_content": options.script};
}
game_parameters_json = {
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.60681.20667.37171</string> </value>
<value> <string>1012.50927.52040.41233</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709286436.53</float>
<float>1701096005.31</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