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

Multicopter API

See merge request !2004
parents 036f0c50 37a38939
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.64140.4755.42274</string> </value>
<value> <string>1020.30340.52915.63897</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1713430403.75</float>
<float>1730817258.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -426,7 +426,7 @@ var DroneManager = /** @class */ (function () {
return;
};
DroneManager.prototype.takeOff = function () {
return this._API.takeOff();
return this._API.takeOff(this);
};
DroneManager.prototype.land = function () {
if (!this.isLanding()) {
......@@ -773,6 +773,7 @@ var GameManager = /** @class */ (function () {
}
this.APIs_dict = {
FixedWingDroneAPI: FixedWingDroneAPI,
MulticopterDroneAPI: MulticopterDroneAPI,
EnemyDroneAPI: EnemyDroneAPI
};
if (this._game_parameters_json.debug_test_mode) {
......@@ -895,21 +896,13 @@ var GameManager = /** @class */ (function () {
if (drone.team === TEAM_ENEMY) {
return;
}
function distance(a, b) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) +
Math.pow((a.z - b.z), 2));
}
if (drone.position) {
//TODO epsilon distance is 15 because of fixed wing loiter flights
//there is not a proper collision
if (distance(drone.position, flag.location) <=
this._mapManager.getMapInfo().flag_distance_epsilon) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched flag ' + flag.id), false);
if (flag.weight > 0) {
flag.weight -= 1;
drone.score += flag.score; // move score to a global place? GM, MM?
}
if (drone.colliderMesh &&
drone.colliderMesh.intersectsMesh(flag, true)) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched flag ' + flag.id), false);
if (flag.weight > 0) {
flag.weight -= 1;
drone.score += flag.score; // move score to a global place? GM, MM?
}
}
};
......@@ -1061,11 +1054,14 @@ var GameManager = /** @class */ (function () {
drone_position.z
);
game_manager._flight_log[index].push([
current_time, geo_coordinates.latitude,
geo_coordinates.longitude,
map_info.start_AMSL + drone_position.z,
drone_position.z, drone.getYaw(), drone.getSpeed(),
drone.getClimbRate()
current_time.toFixed(0),
geo_coordinates.latitude.toFixed(4),
geo_coordinates.longitude.toFixed(4),
(map_info.start_AMSL + drone_position.z).toFixed(4),
drone_position.z.toFixed(4),
drone.getYaw().toFixed(0),
drone.getSpeed().toFixed(2),
drone.getClimbRate().toFixed(6)
]);
}
}
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1017.22735.36044.31948</string> </value>
<value> <string>1020.30714.54302.56558</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1718719762.65</float>
<float>1730822107.38</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,7 +5,7 @@
var MapUtils = /** @class */ (function () {
"use strict";
var FLAG_EPSILON = 15, R = 6371e3, FLAG_WEIGHT = 5, FLAG_SCORE = 5;
var R = 6371e3, FLAG_WEIGHT = 5, FLAG_SCORE = 5;
//** CONSTRUCTOR
function MapUtils(map_param) {
......@@ -27,8 +27,7 @@ var MapUtils = /** @class */ (function () {
);
_this.map_info = {
"depth": _this.map_param.depth,
"width": _this.map_param.width,
"flag_distance_epsilon": map_param.flag_distance_epsilon || FLAG_EPSILON
"width": _this.map_param.width
};
_this.map_info.height = _this.map_param.height;
_this.map_info.start_AMSL = _this.map_param.start_AMSL;
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1017.22488.12960.6280</string> </value>
<value> <string>1020.30710.25287.37376</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1718708011.02</float>
<float>1730822161.12</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -146,7 +146,7 @@
<div class="line"></div>
<h1>Fixed Wings Drone API</h1>
<h1>Drone API</h1>
<h3>API functions</h3>
......@@ -454,7 +454,7 @@
<!-- loiter -->
<h4 class="item-name" id="loiter"><span>loiter</span><span>: void</span></h4>
<p class="item-descr">Set the drone to loiter mode, it will loiter around the target coordinates. If the given radius is inferior to LOITER_LIMIT (30), then the chosen radius will be the last accepted value when calling loiter function (100 by default).</p>
<p class="item-descr">Set the drone to loiter mode (only exists for fixed-wings drones), it will loiter around the target coordinates. If the given radius is inferior to LOITER_LIMIT (30), then the chosen radius will be the last accepted value when calling loiter function (100 by default).</p>
<div>
<h5 class="item-param-1">Param</h5>
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.13928.44848.25668</string> </value>
<value> <string>1017.23884.35535.62190</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1710867839.5</float>
<float>1731938073.03</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,6 +19,10 @@
<script type="text/javascript" src="./libraries/seedrandom.min.js"></script>
<script src="gadget_erp5_page_drone_capture_map_utils.js" type="text/javascript"></script>
<!-- API scripts -->
<script src="gadget_erp5_page_drone_capture_flag_fixedwingdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_capture_flag_multicopterdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_capture_flag_script_page.js" type="text/javascript"></script>
</head>
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.65526.46361.27613</string> </value>
<value> <string>1017.23884.35535.62190</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1694194019.23</float>
<float>1730801080.42</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1016.21921.52144.47906</string> </value>
<value> <string>1020.51982.55228.2918</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1714738877.83</float>
<float>1732098322.73</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -63,6 +63,42 @@
<td>//textarea[@id="log_result_0"]</td>
<td></td>
<tr>
<!-- Change drone type -->
<tr>
<td>click</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_drone_capture_flag_script_page.html')]//button[text()="Parameters"]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//label[text()='Drone Type']</td>
<td></td>
<tr>
<tr>
<td>select</td>
<td>//select[@name="drone_type"]</td>
<td>value=Fixed Wings</td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//label[text()='Drone min speed']</td>
<td></td>
<tr>
<tr>
<td>click</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_drone_capture_flag_script_page.html')]//button[text()="Run"]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//span[@id="loading"]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[contains(text(), 'Download Simulation LOG')]</td>
<td></td>
<tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
......@@ -46,7 +46,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testDroneSimulatorFlight</string> </value>
<value> <string>testDroneCaptureFlagFixedWingFlight</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
......
......@@ -9,19 +9,19 @@
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Drone Capture Flag OJS app (expected failure)</td></tr>
<tr><td rowspan="1" colspan="3">Test Fixed Wing Drone Capture Flag OJS app (expected failure)</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Go to site -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/officejs_drone_capture_flag/app/#/?page=drone_capture_flag_test_page</td>
<td>${base_url}/web_site_module/officejs_drone_capture_flag/app/#/?page=drone_capture_flag_fixed_wing_test_page</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_drone_capture_flag_test_page.html')]//input[@type="submit" and @name="action_run"]</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_drone_capture_flag_fixed_wing_test_page.html')]//input[@type="submit" and @name="action_run"]</td>
<td></td>
<tr>
<tr>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testDroneCaptureFlagMulticopterFlight</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Drone Capture Flag OJS app (expected failure)</title>
<!-- This test is expected to fail as the drone simulator runs on a web worker canvas, which relies on a very new feature: offscreen canvas
---- This feature is not supported yet by the latest Firefox ESR used in the test nodes -->
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Multicopter Drone Capture Flag OJS app (expected failure)</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Go to site -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/officejs_drone_capture_flag/app/#/?page=drone_capture_flag_multicopter_test_page</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_drone_capture_flag_multicopter_test_page.html')]//input[@type="submit" and @name="action_run"]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//span[@id="loading"]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@data-gadget-url, 'babylonjs.gadget.html')]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@data-gadget-url, 'babylonjs.gadget.html')]//canvas[contains(@data-engine, 'Babylon.js')]</td>
<td></td>
<tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(text(), 'CONSOLE LOG ENTRIES:')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Initial speed: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Yaw angle: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Timestamp: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Distance: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Latitude: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Longitude: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Altitude: OK')]</td>
<td></td>
<tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Timeout: OK')]</td>
<td></td>
<tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<!--
data-i18n=Others
data-i18n=Tools
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Drone Simulator Test Page</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<!-- API scripts -->
<script src="gadget_erp5_page_drone_capture_flag_fixedwingdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_capture_flag_fixed_wing_test_page.js" type="text/javascript"></script>
</head>
<body>
<form>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
<input name="action_run" class="dialogconfirm" type="submit" value="Run" style="margin-bottom: 20pt;margin-top: 20pt;">
<a data-i18n="Storages"></a> <!-- for zelenium test common macro -->
<div class="simulator_div"></div>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view_babylonjs"
data-gadget-sandbox="public">
</div>
<div class="test_log"></div>
</form>
</body>
</html>
\ No newline at end of file
......@@ -73,7 +73,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_drone_capture_flag_test_page.html</string> </value>
<value> <string>gadget_erp5_page_drone_capture_flag_fixed_wing_test_page.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -83,7 +83,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test_capture_drone_flight_html</string> </value>
<value> <string>test_capture_drone_fixed_wing_flight_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -103,7 +103,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Drone Capture Flag Test Page</string> </value>
<value> <string>Drone Capture Flag Fixed Wing Test Page</string> </value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1009.56051.5673.26368</string> </value>
<value> <string>1020.30404.9679.22971</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1690898380.88</float>
<float>1730823497.17</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint indent: 2, maxlen: 100*/
/*global window, rJS, domsugar, document*/
(function (window, rJS, domsugar, document) {
/*global window, rJS, domsugar, document, FixedWingDroneAPI*/
(function (window, rJS, domsugar, document, FixedWingDroneAPI) {
"use strict";
var SIMULATION_SPEED = 1,
......@@ -17,17 +17,7 @@
INIT_LAT = 45.6412,
INIT_ALT = 15,
DEFAULT_SPEED = 16,
MAX_ACCELERATION = 6,
MAX_DECELERATION = 1,
MIN_SPEED = 12,
MAX_SPEED = 26,
MAX_ROLL = 35,
MIN_PITCH = -20,
MAX_PITCH = 25,
MAX_CLIMB_RATE = 8,
MAX_SINK_RATE = 3,
NUMBER_OF_DRONES = 1,
// Non-inputs parameters
DEFAULT_SCRIPT_CONTENT =
'function assert(a, b, msg) {\n' +
' if (a === b)\n' +
......@@ -49,14 +39,14 @@
'}\n' +
'\n' +
'function compare(coord1, coord2) {\n' +
' assert(coord1.latitude, coord2.latitude, "Latitude")\n' +
' assert(coord1.longitude, coord2.longitude, "Longitude")\n' +
' assert(coord1.altitude, coord2.altitude, "Altitude")\n' +
' assert(coord1.latitude, coord2.latitude, "Latitude");\n' +
' assert(coord1.longitude, coord2.longitude, "Longitude");\n' +
' assert(coord1.altitude, coord2.altitude, "Altitude");\n' +
'}\n' +
'\n' +
'me.onStart = function (timestamp) {\n' +
' assert(me.getSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getYaw(), 0, "Yaw angle")\n' +
' assert(me.getYaw(), 0, "Yaw angle");\n' +
' me.initialPosition = me.getCurrentPosition();\n' +
' me.start_time = timestamp;\n' +
' me.setTargetCoordinates(\n' +
......@@ -95,8 +85,9 @@
LOGIC_FILE_LIST = [
'gadget_erp5_page_drone_capture_flag_logic.js',
'gadget_erp5_page_drone_capture_map_utils.js',
'gadget_erp5_page_drone_capture_flag_fixedwingdrone.js',
'gadget_erp5_page_drone_capture_flag_enemydrone.js'
'gadget_erp5_page_drone_capture_flag_multicopterdrone.js',
'gadget_erp5_page_drone_capture_flag_enemydrone.js',
FixedWingDroneAPI.SCRIPT_NAME
];
rJS(window)
......@@ -118,7 +109,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": FixedWingDroneAPI.name,
"script_content": DEFAULT_SCRIPT_CONTENT};
}
map_json = {
......@@ -144,16 +135,6 @@
game_parameters_json = {
"debug_test_mode": true,
"drone": {
"maxAcceleration": MAX_ACCELERATION,
"maxDeceleration": MAX_DECELERATION,
"minSpeed": MIN_SPEED,
"speed": DEFAULT_SPEED,
"maxSpeed": MAX_SPEED,
"maxRoll": MAX_ROLL,
"minPitchAngle": MIN_PITCH,
"maxPitchAngle": MAX_PITCH,
"maxSinkRate": MAX_SINK_RATE,
"maxClimbRate": MAX_CLIMB_RATE,
"onUpdateInterval": ON_UPDATE_INTERVAL,
"list": DRONE_LIST
},
......@@ -170,6 +151,10 @@
"log_drone_flight": LOG,
"log_interval_time": LOG_TIME
};
Object.keys(FixedWingDroneAPI.FORM_VIEW).forEach(function (parameter) {
var field = FixedWingDroneAPI.FORM_VIEW[parameter];
game_parameters_json.drone[field.key] = field.default;
});
return gadget.declareGadget("babylonjs.gadget.html",
{element: fragment, scope: 'simulator'})
.push(function () {
......@@ -241,4 +226,4 @@
});
});
}(window, rJS, domsugar, document));
\ No newline at end of file
}(window, rJS, domsugar, document, FixedWingDroneAPI));
\ No newline at end of file
......@@ -75,7 +75,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_drone_capture_flag_test_page.js</string> </value>
<value> <string>gadget_erp5_page_drone_capture_flag_fixed_wing_test_page.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -85,7 +85,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test_capture_drone_flight_js</string> </value>
<value> <string>test_capture_drone_fixed_wing_flight_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -105,7 +105,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Drone Capture Flag Test Page JS</string> </value>
<value> <string>Drone Capture Flag Fixed Wing Test Page JS</string> </value>
</item>
<item>
<key> <string>version</string> </key>
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.64187.34381.50346</string> </value>
<value> <string>1020.30719.39240.47462</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1713428877.4</float>
<float>1730823482.02</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Others
data-i18n=Tools
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Drone Simulator Test Page</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<!-- API scripts -->
<script src="gadget_erp5_page_drone_capture_flag_multicopterdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_capture_flag_multicopter_test_page.js" type="text/javascript"></script>
</head>
<body>
<form>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
<input name="action_run" class="dialogconfirm" type="submit" value="Run" style="margin-bottom: 20pt;margin-top: 20pt;">
<a data-i18n="Storages"></a> <!-- for zelenium test common macro -->
<div class="simulator_div"></div>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view_babylonjs"
data-gadget-sandbox="public">
</div>
<div class="test_log"></div>
</form>
</body>
</html>
\ No newline at end of file
/*jslint indent: 2, maxlen: 100*/
/*global window, rJS, domsugar, document, MulticopterDroneAPI*/
(function (window, rJS, domsugar, document, MulticopterDroneAPI) {
"use strict";
var SIMULATION_SPEED = 100,
LOOP_INTERVAL = 1000 / 60,
ON_UPDATE_INTERVAL = LOOP_INTERVAL,
SIMULATION_TIME = 714 * LOOP_INTERVAL / 1000,
MIN_LAT = 45.6364,
MAX_LAT = 45.65,
MIN_LON = 14.2521,
MAX_LON = 14.2766,
map_height = 700,
start_AMSL = 595,
INIT_LON = 14.2658,
INIT_LAT = 45.6412,
INIT_ALT = 0,
DEFAULT_SPEED = 5,
STEP = 2.3992831666911723e-06 / 16,
TAKEOFF_ALTITUDE = 7,
NUMBER_OF_DRONES = 1,
DEFAULT_SCRIPT_CONTENT =
'function assert(a, b, msg) {\n' +
' if (a === b)\n' +
' console.log(msg + ": OK");\n' +
' else\n' +
' console.log(msg + ": FAIL");\n' +
'}\n' +
'\n' +
'function distance(lat1, lon1, lat2, lon2) {\n' +
' var R = 6371e3, // meters\n' +
' la1 = lat1 * Math.PI / 180, // lat, lon in radians\n' +
' la2 = lat2 * Math.PI / 180,\n' +
' lo1 = lon1 * Math.PI / 180,\n' +
' lo2 = lon2 * Math.PI / 180,\n' +
' haversine_phi = Math.pow(Math.sin((la2 - la1) / 2), 2),\n' +
' sin_lon = Math.sin((lo2 - lo1) / 2),\n' +
' h = haversine_phi + Math.cos(la1) * Math.cos(la2) * sin_lon * sin_lon;\n' +
' return 2 * R * Math.asin(Math.sqrt(h));\n' +
'}\n' +
'\n' +
'function compare(coord1, coord2) {\n' +
' assert(coord1.latitude, coord2.latitude, "Latitude");\n' +
' assert(coord1.longitude, coord2.longitude, "Longitude");\n' +
' assert(coord1.altitude, coord2.altitude, "Altitude");\n' +
'}\n' +
'\n' +
'me.onStart = function (timestamp) {\n' +
' assert(me.getSpeed(), 0, "Initial speed");\n' +
' assert(me.getYaw(), 0, "Yaw angle");\n' +
' me.start_time = timestamp;\n' +
' me.takeOff();\n' +
' me.direction_set = false;\n' +
' me.interval_ckecked = false;\n' +
'};\n' +
'\n' +
'me.onUpdate = function (timestamp) {\n' +
' if (!me.interval_ckecked) {\n' +
' var time_interval = timestamp - me.start_time,\n' +
' expected_interval = ' + LOOP_INTERVAL + ';\n' +
' assert(time_interval.toFixed(4), expected_interval.toFixed(4), "Timestamp");\n' +
' assert(Date.now(), timestamp, "Date");\n' +
' me.interval_ckecked = true;\n' +
' }\n' +
' if (!me.isReadyToFly()) {\n' +
' return;\n' +
' } else {\n' +
' if (me.direction_set === false) {\n' +
' me.initialPosition = me.getCurrentPosition();\n' +
' me.initialPosition.altitude = me.initialPosition.altitude.toFixed(2);\n' +
' assert(me.initialPosition.altitude, (' + TAKEOFF_ALTITUDE + ').toFixed(2),\n' +
' "Altitude");\n' +
' me.direction_set = true;\n' +
' return me.setTargetCoordinates(\n' +
' me.initialPosition.latitude + 0.01,\n' +
' me.initialPosition.longitude,\n' +
' me.getAltitudeAbs(),\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
' }\n' +
' }\n' +
' var current_position = me.getCurrentPosition(),\n' +
' realDistance = distance(\n' +
' me.initialPosition.latitude,\n' +
' me.initialPosition.longitude,\n' +
' me.getCurrentPosition().latitude,\n' +
' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\n' +
' expectedDistance = (me.getSpeed() * ' + LOOP_INTERVAL + ' / 1000).toFixed(8);\n' +
' assert(realDistance, expectedDistance, "Distance");\n' +
' current_position.latitude = current_position.latitude.toFixed(7);\n' +
' current_position.altitude = current_position.altitude.toFixed(2);\n' +
' compare(current_position, {\n' +
' latitude: (me.initialPosition.latitude + me.getSpeed() *' + STEP + ').toFixed(7),\n' +
' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' +
' });\n' +
'};',
DRAW = true,
LOG = true,
LOG_TIME = 1662.7915426540285,
DRONE_LIST = [],
LOGIC_FILE_LIST = [
'gadget_erp5_page_drone_capture_flag_logic.js',
'gadget_erp5_page_drone_capture_map_utils.js',
'gadget_erp5_page_drone_capture_flag_fixedwingdrone.js',
'gadget_erp5_page_drone_capture_flag_enemydrone.js',
MulticopterDroneAPI.SCRIPT_NAME
];
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareMethod('render', function render() {
var gadget = this;
return gadget.runGame();
})
.declareJob('runGame', function runGame() {
var gadget = this, i,
fragment = gadget.element.querySelector('.simulator_div'),
game_parameters_json, map_json, operator_init_msg;
DRONE_LIST = [];
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": MulticopterDroneAPI.name,
"script_content": DEFAULT_SCRIPT_CONTENT};
}
map_json = {
"height": map_height,
"start_AMSL": start_AMSL,
"min_lat": MIN_LAT,
"max_lat": MAX_LAT,
"min_lon": MIN_LON,
"max_lon": MAX_LON,
"flag_list": [],
"obstacle_list" : [],
"enemy_list" : [],
"initial_position": {
"longitude": INIT_LON,
"latitude": INIT_LAT,
"altitude": INIT_ALT
}
};
operator_init_msg = {
"flag_positions": []
};
/*jslint evil: false*/
game_parameters_json = {
"debug_test_mode": true,
"drone": {
"onUpdateInterval": ON_UPDATE_INTERVAL,
"list": DRONE_LIST
},
"gameTime": SIMULATION_TIME,
"simulation_speed": SIMULATION_SPEED,
"latency": {
"information": 0,
"communication": 0
},
"map": map_json,
"operator_init_msg": operator_init_msg,
"draw_flight_path": DRAW,
"temp_flight_path": true,
"log_drone_flight": LOG,
"log_interval_time": LOG_TIME
};
Object.keys(MulticopterDroneAPI.FORM_VIEW).forEach(function (parameter) {
var field = MulticopterDroneAPI.FORM_VIEW[parameter];
game_parameters_json.drone[field.key] = field.default;
});
return gadget.declareGadget("babylonjs.gadget.html",
{element: fragment, scope: 'simulator'})
.push(function () {
return gadget.getDeclaredGadget('form_view_babylonjs');
})
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
"my_babylonjs": {
"default": "",
"css_class": "",
"required": 0,
"editable": 1,
"key": "babylonjs",
"hidden": 0,
"type": "GadgetField",
"url": "babylonjs.gadget.html",
"sandbox": "public",
"renderjs_extra": '{"autorun": false, ' +
'"logic_file_list": ' + JSON.stringify(LOGIC_FILE_LIST) + ', ' +
'"game_parameters": ' + JSON.stringify(game_parameters_json) +
'}'
}
}},
"_links": {
"type": {
name: ""
}
}
},
form_definition: {
group_list: [[
"bottom",
[["my_babylonjs"]]
]]
}
});
})
.push(function () {
return gadget.getDeclaredGadget('form_view_babylonjs');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (result) {
var div = domsugar('div', { text: "CONSOLE LOG ENTRIES:" }), lines,
l, test_log_node = document.querySelector('.test_log');
document.querySelector('.container').parentNode.appendChild(div);
function appendToTestLog(test_log_node, message) {
var log_node = document.createElement("div"),
textNode = document.createTextNode(message);
log_node.appendChild(textNode);
test_log_node.appendChild(log_node);
}
lines = result.console_log.split('\n');
for (l = 0; l < lines.length; l += 1) {
if (lines[l] !== 'TIMEOUT!') {
appendToTestLog(test_log_node, lines[l]);
} else {
appendToTestLog(test_log_node, 'Timeout: OK');
return;
}
}
appendToTestLog(test_log_node, 'Timeout: FAILED');
}, function (error) {
return gadget.notifySubmitted({message: "Error: " + error.message,
status: 'error'});
});
});
}(window, rJS, domsugar, document, MulticopterDroneAPI));
\ No newline at end of file
......@@ -6,6 +6,8 @@
var DroneLogAPI = /** @class */ (function () {
"use strict";
var TOP_SPEED = 250; //so fast that it virtually "teleports" to target
DroneLogAPI.SCRIPT_NAME =
"gadget_erp5_page_drone_simulator_dronelogfollower.js";
//** CONSTRUCTOR
function DroneLogAPI(gameManager, drone_info, flight_parameters, id) {
this._gameManager = gameManager;
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.64101.28159.26163</string> </value>
<value> <string>1017.23884.35535.62190</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1713425784.77</float>
<float>1730898672.15</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -85,7 +85,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>drone_simulator_fixedwingdrone_js</string> </value>
<value> <string>drone_simulator_fixed_wing_drone_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.64203.48820.61559</string> </value>
<value> <string>1020.30338.10759.37171</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1713429850.09</float>
<float>1730799505.92</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -376,7 +376,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 () {
if (!this.isLanding()) {
......@@ -649,7 +649,7 @@ var GameManager = /** @class */ (function () {
header_list = ["timestamp (ms)", "latitude (°)", "longitude (°)",
"AMSL (m)", "rel altitude (m)", "yaw (°)",
"ground speed (m/s)", "climb rate (m/s)"];
for (drone = 0; drone < GAMEPARAMETERS.droneList.length; drone += 1) {
for (drone = 0; drone < GAMEPARAMETERS.drone.list.length; drone += 1) {
this._flight_log[drone] = [];
this._flight_log[drone].push(header_list);
this._log_count[drone] = 0;
......@@ -671,6 +671,7 @@ var GameManager = /** @class */ (function () {
}
this.APIs_dict = {
FixedWingDroneAPI: FixedWingDroneAPI,
MulticopterDroneAPI: MulticopterDroneAPI,
DroneLogAPI: DroneLogAPI
};
if (this._game_parameters_json.debug_test_mode) {
......@@ -844,11 +845,14 @@ var GameManager = /** @class */ (function () {
drone_position.z
);
game_manager._flight_log[index].push([
current_time, geo_coordinates.latitude,
geo_coordinates.longitude,
map_info.start_AMSL + drone_position.z,
drone_position.z, drone.getYaw(), drone.getSpeed(),
drone.getClimbRate()
current_time.toFixed(0),
geo_coordinates.latitude.toFixed(4),
geo_coordinates.longitude.toFixed(4),
(map_info.start_AMSL + drone_position.z).toFixed(4),
drone_position.z.toFixed(4),
drone.getYaw().toFixed(0),
drone.getSpeed().toFixed(2),
drone.getClimbRate().toFixed(6)
]);
}
}
......@@ -987,7 +991,7 @@ var GameManager = /** @class */ (function () {
_this._mapManager = new MapManager(ctx._scene, GAMEPARAMETERS.map,
GAMEPARAMETERS.initialPosition);
ctx._spawnDrones(_this._mapManager.getMapInfo().initial_position,
GAMEPARAMETERS.droneList, ctx);
GAMEPARAMETERS.drone.list, ctx);
// Hide the drone prefab
DroneManager.Prefab.isVisible = false;
//Hack to make advanced texture work
......@@ -1000,7 +1004,7 @@ var GameManager = /** @class */ (function () {
ctx._scene
);
document = documentTmp;
for (count = 0; count < GAMEPARAMETERS.droneList.length; count += 1) {
for (count = 0; count < GAMEPARAMETERS.drone.list.length; count += 1) {
controlMesh = ctx._droneList[count].infosMesh;
rect = new BABYLON.GUI.Rectangle();
rect.width = "10px";
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1017.22776.49981.4147</string> </value>
<value> <string>1020.23547.6727.25736</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1718722284.77</float>
<float>1730712553.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,6 +19,11 @@
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<!-- API scripts -->
<script src="gadget_erp5_page_drone_simulator_fixedwingdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_simulator_multicopterdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_simulator_dronelogfollower.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_simulator_log_page.js" type="text/javascript"></script>
</head>
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.22391.16038.6980</string> </value>
<value> <string>1017.23884.35535.62190</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1671109341.4</float>
<float>1730898722.9</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint indent: 2, maxlen: 100*/
/*global window, rJS, domsugar, document*/
(function (window, rJS, domsugar, document) {
/*global window, rJS, domsugar, document, DroneLogAPI, FixedWingDroneAPI, MulticopterDroneAPI*/
(function (window, rJS, domsugar, document, API_LIST) {
"use strict";
var SIMULATION_SPEED = 200,
......@@ -8,16 +8,16 @@
DRAW = true,
LOG = false,
DRONE_LIST = [
{"id": 0, "type": "DroneLogAPI", "log_content": ""},
{"id": 1, "type": "DroneLogAPI", "log_content": ""}
{"id": 0, "type": API_LIST[0].name, "log_content": ""},
{"id": 1, "type": API_LIST[0].name, "log_content": ""}
],
WIDTH = 680,
HEIGHT = 340,
LOGIC_FILE_LIST = [
'gadget_erp5_page_drone_simulator_logic.js',
'gadget_erp5_page_drone_simulator_fixedwingdrone.js',
'gadget_erp5_page_drone_simulator_dronelogfollower.js'
];
'gadget_erp5_page_drone_simulator_logic.js'
].concat(API_LIST.map(function (api) {
return api.SCRIPT_NAME;
}));
rJS(window)
/////////////////////////////////////////////////////////////////
......@@ -221,7 +221,8 @@
game_parameters_json = {
"drone": {
"maxAcceleration": 1,
"maxSpeed": 1
"maxSpeed": 1,
"list": DRONE_LIST
},
"gameTime": SIMULATION_TIME,
"simulation_speed": parseFloat(options.simulation_speed),
......@@ -244,8 +245,7 @@
},
"draw_flight_path": DRAW,
"log_drone_flight": LOG,
"temp_flight_path": false,
"droneList": DRONE_LIST
"temp_flight_path": false
};
return gadget.declareGadget("babylonjs.gadget.html",
{element: fragment, scope: 'simulator'})
......@@ -295,4 +295,4 @@
});
});
}(window, rJS, domsugar, document));
\ No newline at end of file
}(window, rJS, domsugar, document, [DroneLogAPI, FixedWingDroneAPI, MulticopterDroneAPI]));
\ No newline at end of file
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.48769.44767.36898</string> </value>
<value> <string>1020.32016.49807.50141</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1697034365.81</float>
<float>1730900244.98</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,6 +19,10 @@
<script src="gadget_global.js" type="text/javascript"></script>
<script src="domsugar.js" type="text/javascript"></script>
<!-- API scripts -->
<script src="gadget_erp5_page_drone_simulator_fixedwingdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_simulator_multicopterdrone.js" type="text/javascript"></script>
<script src="gadget_erp5_page_drone_simulator_script_page.js" type="text/javascript"></script>
</head>
......@@ -35,6 +39,6 @@
data-gadget-scope="form_view_babylonjs"
data-gadget-sandbox="public">
</div>
</form>
</form>
</body>
</html>
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.65523.1234.17</string> </value>
<value> <string>1020.30362.56361.22715</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1671032907.71</float>
<float>1730800996.91</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