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

erp5_officejs_drone_simulator: define speed with setTargetCoordinates

Set speed with setTargetCoordinates instead of a separate function because some drones API have an unique call for setting both coordinates and speed and the rate of this call can be curbed.
parent 0d4b0f04
......@@ -345,7 +345,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.internal_setTargetCoordinates =
function (drone, coordinates, radius) {
function (drone, coordinates, speed, radius) {
if (radius) {
this._loiter_mode = true;
if (radius >= LOITER_LIMIT) {
......@@ -354,6 +354,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
} else {
this._loiter_mode = false;
}
this.setSpeed(drone, speed);
};
FixedWingDroneAPI.prototype.sendMsg = function (msg, to) {
......@@ -543,7 +544,12 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.triggerParachute = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 5);
drone.setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
5,
drone.getAirSpeed()
);
};
FixedWingDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition();
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.46032.14056.1553</string> </value>
<value> <string>1014.48041.44620.29337</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1696870145.24</float>
<float>1709113157.81</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -150,11 +150,11 @@ var DroneManager = /** @class */ (function () {
* Set a target point to move
*/
DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude) {
this._internal_setTargetCoordinates(latitude, longitude, altitude);
};
function (latitude, longitude, altitude, speed) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed);
};
DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, radius) {
function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay) {
return;
}
......@@ -165,6 +165,7 @@ var DroneManager = /** @class */ (function () {
return this._API.internal_setTargetCoordinates(
this,
this._targetCoordinates,
speed,
radius
);
};
......@@ -224,15 +225,6 @@ var DroneManager = /** @class */ (function () {
}
return this._API.setStartingPosition(this, x, y, z);
};
DroneManager.prototype.setAirSpeed = function (speed) {
if (!this._canPlay) {
return;
}
if (isNaN(speed)) {
throw new Error('Speed must be a number');
}
return this._API.setSpeed(this, speed);
};
DroneManager.prototype.setDirection = function (x, y, z) {
if (!this._canPlay) {
return;
......@@ -334,9 +326,15 @@ var DroneManager = /** @class */ (function () {
* Make the drone loiter (circle with a set radius)
*/
DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, radius);
};
function (latitude, longitude, altitude, radius, speed) {
this._internal_setTargetCoordinates(
latitude,
longitude,
altitude,
speed,
radius
);
};
DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) {
return this._API.getFlightParameters();
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.57487.9176.36369</string> </value>
<value> <string>1014.48183.45277.7697</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1697558075.38</float>
<float>1709113192.28</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -363,6 +363,10 @@
<p class="item-param-1">altitude: Float</p>
<p class="item-param-2">altitude value (in meters).</p>
</div>
<div>
<p class="item-param-1">speed: Float</p>
<p class="item-param-2">speed value (in meters per second).</p>
</div>
<div>
<h5 class="item-param-1">Example</h5>
......@@ -370,35 +374,12 @@
<div>
<p class="item-example">
me.setTargetCoordinates(lat, lon, altitude);<br>
me.setTargetCoordinates(lat, lon, altitude, speed);<br>
</p>
</div>
<div class="line"></div>
<!-- setAirSpeed -->
<h4 class="item-name" id="setAirSpeed"><span>setAirSpeed</span><span>: void</span></h4>
<p class="item-descr">Set the drone speed in meters/second. The drone will move at the given value.</p>
<div>
<h5 class="item-param-1">Param</h5>
<h5 class="item-param-2">Description</h5>
</div>
<div>
<p class="item-param-1">speed: Float</p>
<p class="item-param-2">Speed value</p>
</div>
<div>
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-param-1">me.setAirSpeed(16);<br>
</p>
<div class="line"></div>
<!-- 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>
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1013.8667.7605.21589</string> </value>
<value> <string>1014.45296.39536.30276</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1702410728.19</float>
<float>1708536065.15</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -77,6 +77,7 @@ var OperatorAPI = /** @class */ (function () {
MAX_PITCH = 25,
MAX_CLIMB_RATE = 8,
MAX_SINK_RATE = 3,
MAX_COMMAND_FREQUENCY = 2,
NUMBER_OF_DRONES = 5,
// Non-inputs parameters
EPSILON = "15",
......@@ -104,7 +105,7 @@ var OperatorAPI = /** @class */ (function () {
' );\n' +
'}\n' +
'\n' +
'me.onStart = function () {\n' +
'me.onStart = function (timestamp) {\n' +
' me.direction_set = false;\n' +
' me.dodging = false;\n' +
' me.ongoing_detection = false;\n' +
......@@ -136,7 +137,8 @@ var OperatorAPI = /** @class */ (function () {
' me.setTargetCoordinates(\n' +
' me.flag_positions[me.next_checkpoint].position.latitude,\n' +
' me.flag_positions[me.next_checkpoint].position.longitude,\n' +
' me.flag_positions[me.next_checkpoint].position.altitude + me.id\n' +
' me.flag_positions[me.next_checkpoint].position.altitude + me.id,\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
//' console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);\n' +
' }\n' +
......@@ -162,12 +164,6 @@ var OperatorAPI = /** @class */ (function () {
' }\n' +
' return;\n' +
' }\n' +
' if (me.next_checkpoint == me.flag_positions.length) {\n' +
' me.triggerParachute();\n' +
' }\n' +
' if (me.landed()) {\n' +
' me.exit();\n' +
' }\n' +
'};\n' +
'\n' +
'me.onDroneViewInfo = function (drone_view) {\n' +
......@@ -182,7 +178,7 @@ var OperatorAPI = /** @class */ (function () {
' } else {\n' +
' dodge_point.longitude = dodge_point.longitude * -1;\n' +
' }\n' +
' me.setTargetCoordinates(dodge_point.latitude, dodge_point.longitude, me.getCurrentPosition().altitude);\n' +
' me.setTargetCoordinates(dodge_point.latitude, dodge_point.longitude, me.getCurrentPosition().altitude, ' + DEFAULT_SPEED + ');\n' +
' return;\n' +
' }\n' +
'};',
......@@ -680,6 +676,17 @@ var OperatorAPI = /** @class */ (function () {
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_command_frequency": {
"description": "",
"title": "Drone max command frequency",
"default": gadget.state.drone_max_command_frequency,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_command_frequency",
"hidden": 0,
"type": "FloatField"
},
"my_number_of_drones": {
"description": "",
"title": "Number of drones",
......@@ -708,7 +715,8 @@ var OperatorAPI = /** @class */ (function () {
[["my_drone_min_speed"], ["my_drone_speed"], ["my_drone_max_speed"],
["my_drone_max_acceleration"], ["my_drone_max_deceleration"],
["my_drone_max_roll"], ["my_drone_min_pitch"], ["my_drone_max_pitch"],
["my_drone_max_sink_rate"], ["my_drone_max_climb_rate"]]
["my_drone_max_sink_rate"], ["my_drone_max_climb_rate"],
["my_drone_max_command_frequency"]]
]]
}
});
......@@ -836,6 +844,7 @@ var OperatorAPI = /** @class */ (function () {
"maxPitchAngle": parseFloat(gadget.state.drone_max_pitch),
"maxSinkRate": parseFloat(gadget.state.drone_max_sink_rate),
"maxClimbRate": parseFloat(gadget.state.drone_max_climb_rate),
"maxCommandFrequency": parseFloat(gadget.state.drone_max_command_frequency),
"list": drone_list
},
"gameTime": parseInt(gadget.state.simulation_time, 10),
......@@ -950,6 +959,7 @@ var OperatorAPI = /** @class */ (function () {
operator_script: DEFAULT_OPERATOR_SCRIPT,
drone_script: DEFAULT_SCRIPT_CONTENT,
number_of_drones: NUMBER_OF_DRONES,
drone_max_command_frequency: MAX_COMMAND_FREQUENCY,
drone_max_climb_rate: MAX_CLIMB_RATE,
drone_max_sink_rate: MAX_SINK_RATE,
drone_max_pitch: MAX_PITCH,
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.57494.145.60023</string> </value>
<value> <string>1014.55204.2137.9676</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1697558059.95</float>
<float>1709130500.2</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -53,13 +53,14 @@
'}\n' +
'\n' +
'me.onStart = function () {\n' +
' assert(me.getAirSpeed(), 16, "Initial speed");\n' +
' assert(me.getAirSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getYaw(), 0, "Yaw angle")\n' +
' me.initialPosition = me.getCurrentPosition();\n' +
' me.setTargetCoordinates(\n' +
' me.initialPosition.latitude + 0.01,\n' +
' me.initialPosition.longitude,\n' +
' me.getAltitudeAbs()\n' +
' me.getAltitudeAbs(),\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
'};\n' +
'\n' +
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.54933.34862.768</string> </value>
<value> <string>1014.55202.48917.18107</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709114352.45</float>
<float>1709130419.7</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -349,7 +349,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.internal_setTargetCoordinates =
function (drone, coordinates, radius) {
function (drone, coordinates, speed, radius) {
if (radius) {
this._loiter_mode = true;
if (radius >= LOITER_LIMIT) {
......@@ -358,6 +358,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
} else {
this._loiter_mode = false;
}
this.setSpeed(drone, speed);
};
FixedWingDroneAPI.prototype.sendMsg = function (msg, to) {
......@@ -502,7 +503,12 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.triggerParachute = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 5);
drone.setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
5,
drone.getAirSpeed()
);
};
FixedWingDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition();
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.48679.53693.47701</string> </value>
<value> <string>1014.11751.44914.51968</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1697030763.04</float>
<float>1706523358.41</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -136,11 +136,11 @@ var DroneManager = /** @class */ (function () {
* Set a target point to move
*/
DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude) {
this._internal_setTargetCoordinates(latitude, longitude, altitude);
function (latitude, longitude, altitude, speed) {
this._internal_setTargetCoordinates(latitude, longitude, altitude, speed);
};
DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, radius) {
function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay) {
return;
}
......@@ -150,6 +150,7 @@ var DroneManager = /** @class */ (function () {
return this._API.internal_setTargetCoordinates(
this,
this._targetCoordinates,
speed,
radius
);
};
......@@ -197,15 +198,6 @@ var DroneManager = /** @class */ (function () {
}
return this._API.setStartingPosition(this, x, y, z);
};
DroneManager.prototype.setAirSpeed = function (speed) {
if (!this._canPlay) {
return;
}
if (isNaN(speed)) {
throw new Error('Speed must be a number');
}
return this._API.setSpeed(this, speed);
};
DroneManager.prototype.setDirection = function (x, y, z) {
if (!this._canPlay) {
return;
......@@ -299,11 +291,12 @@ var DroneManager = /** @class */ (function () {
* Make the drone loiter (circle with a set radius)
*/
DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius) {
function (latitude, longitude, altitude, radius, speed) {
this._internal_setTargetCoordinates(
latitude,
longitude,
altitude,
speed,
radius
);
};
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.48744.22696.33177</string> </value>
<value> <string>1014.11746.34243.61149</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1697032866.09</float>
<float>1706523386.8</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -98,7 +98,8 @@
' 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' +
' CHECKPOINT_LIST[me.next_checkpoint].altitude + ALTITUDE + ALTITUDE * me.id,\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
' console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);\n' +
' }\n' +
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.48716.48246.13943</string> </value>
<value> <string>1014.54902.15254.29337</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1697031250.03</float>
<float>1709130323.68</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -57,13 +57,14 @@
'}\n' +
'\n' +
'me.onStart = function () {\n' +
' assert(me.getAirSpeed(), 16, "Initial speed");\n' +
' assert(me.getAirSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getYaw(), 0, "Yaw angle")\n' +
' me.initialPosition = me.getCurrentPosition();\n' +
' me.setTargetCoordinates(\n' +
' me.initialPosition.latitude + 0.01,\n' +
' me.initialPosition.longitude,\n' +
' me.getAltitudeAbs()\n' +
' me.getAltitudeAbs(),\n' +
' '+ DEFAULT_SPEED + '\n' +
' );\n' +
'};\n' +
'\n' +
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1012.50925.12802.42871</string> </value>
<value> <string>1014.55202.15664.53026</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1701095838.64</float>
<float>1709130383.65</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