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

erp5_officejs_drone_simulator: use multicopter API

parent 1631641c
......@@ -5,21 +5,149 @@
var FixedWingDroneAPI = /** @class */ (function () {
"use strict";
var DEFAULT_SPEED = 16,
PARACHUTE_SPEED = 8,
EARTH_GRAVITY = 9.81,
var EARTH_GRAVITY = 9.81,
LOITER_LIMIT = 30,
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,
VIEW_SCOPE = 100,
MAX_MESSAGE_SIZE = 1024;
MAX_MESSAGE_SIZE = 1024,
PARACHUTE_SPEED = 8,
VIEW_SCOPE = 100;
FixedWingDroneAPI.DRONE_TYPE = "Fixed Wings";
FixedWingDroneAPI.SCRIPT_NAME =
"gadget_erp5_page_drone_capture_flag_fixedwingdrone.js";
FixedWingDroneAPI.FORM_VIEW = {
"my_drone_min_speed": {
"description": "",
"title": "Drone min speed",
"default": 12,
"css_class": "",
"required": 1,
"editable": 1,
"key": "minSpeed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_speed": {
"description": "",
"title": "Drone speed",
"default": 16,
"css_class": "",
"required": 1,
"editable": 1,
"key": "speed",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_speed": {
"description": "",
"title": "Drone max speed",
"default": 26,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxSpeed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_acceleration": {
"description": "",
"title": "Drone max Acceleration",
"default": 6,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxAcceleration",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
"title": "Drone max Deceleration",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxDeceleration",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_roll": {
"description": "",
"title": "Drone max roll",
"default": 35,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxRoll",
"hidden": 0,
"type": "FloatField"
},
"my_drone_min_pitch": {
"description": "",
"title": "Drone min pitch",
"default": -20,
"css_class": "",
"required": 1,
"editable": 1,
"key": "minPitchAngle",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_pitch": {
"description": "",
"title": "Drone max pitch",
"default": 25,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxPitchAngle",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_sink_rate": {
"description": "",
"title": "Drone max sink rate",
"default": 3,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxSinkRate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_climb_rate": {
"description": "",
"title": "Drone max climb rate",
"default": 8,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxClimbRate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_speed_factor": {
"description": "",
"title": "Drone speed factor",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "speedFactor",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_command_frequency": {
"description": "",
"title": "Drone max command frequency",
"default": 5,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxCommandFrequency",
"hidden": 0,
"type": "FloatField"
}
};
//** CONSTRUCTOR
function FixedWingDroneAPI(gameManager, drone_info, flight_parameters, id) {
......@@ -98,14 +226,47 @@ var FixedWingDroneAPI = /** @class */ (function () {
/*
** Function called on every drone update, right before onUpdate AI script
*/
FixedWingDroneAPI.prototype.internal_position_update = function (context, delta_time) {
if (context.position.z > 0) {
this._updateSpeed(context, delta_time);
this._updatePosition(context, delta_time);
FixedWingDroneAPI.prototype.internal_position_update =
function (context, delta_time) {
var currentGeoCoordinates = this._mapManager.convertToGeoCoordinates(
context.position.x,
context.position.y,
context.position.z
),
targetCoordinates = this._mapManager.convertToGeoCoordinates(
context._targetCoordinates.x,
context._targetCoordinates.y,
context._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
distanceToTarget,
newYaw;
if (this._loiter_mode) {
distanceToTarget = Math.sqrt(
Math.pow(context._targetCoordinates.x - context.position.x, 2)
+ Math.pow(context._targetCoordinates.y - context.position.y, 2)
);
if (Math.abs(distanceToTarget - this._loiter_radius) <= 1) {
newYaw = bearing - 90;
} else if (distanceToTarget < this._loiter_radius) {
newYaw = bearing - 135;
} else {
newYaw = this._getNewYaw(context, bearing, delta_time);
}
} else {
context.setDirection(0, 0, 0);
newYaw = this._getNewYaw(context, bearing, delta_time);
}
this._updateSpeed(context, delta_time);
this._updatePosition(context, newYaw, delta_time);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
};
......@@ -140,115 +301,42 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) {
var speed = drone.get3DSpeed(), speedDiff, speedUpdate;
var speed = drone.get3DSpeed(), speedDiff,
speedUpdate = drone._acceleration * delta_time / 1000;
if (speed > this._targetSpeed) {
speedUpdate *= -1;
}
if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed;
speedUpdate = drone._acceleration * delta_time / 1000;
if (Math.abs(speedDiff) < Math.abs(speedUpdate)) {
drone._speed = this._targetSpeed;
drone._acceleration = 0;
} else {
drone._speed += speedUpdate;
}
}
};
FixedWingDroneAPI.prototype._updatePosition = function (drone, delta_time) {
var R = 6371e3,
currentGeoCoordinates = this._mapManager.convertToGeoCoordinates(
drone.position.x,
drone.position.y,
drone.position.z
),
targetCoordinates = this._mapManager.convertToGeoCoordinates(
drone._targetCoordinates.x,
drone._targetCoordinates.y,
drone._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
currentCosLat,
currentLatRad,
distance,
distanceCos,
distanceSin,
distanceToTarget,
currentSinLat,
currentLonRad,
groundSpeed,
newCoordinates,
newLatRad,
newLonRad,
newYaw,
newYawRad,
verticalSpeed,
yawToDirection;
if (this._loiter_mode) {
distanceToTarget = Math.sqrt(
Math.pow(drone._targetCoordinates.x - drone.position.x, 2)
+ Math.pow(drone._targetCoordinates.y - drone.position.y, 2)
);
if (Math.abs(distanceToTarget - this._loiter_radius) <= 1) {
newYaw = bearing - 90;
} else if (distanceToTarget < this._loiter_radius) {
newYaw = bearing - 135;
} else {
newYaw = this._getNewYaw(drone, bearing, delta_time);
}
} else {
newYaw = this._getNewYaw(drone, bearing, delta_time);
}
newYawRad = this._toRad(newYaw);
currentLatRad = this._toRad(currentGeoCoordinates.latitude);
currentCosLat = Math.cos(currentLatRad);
currentSinLat = Math.sin(currentLatRad);
currentLonRad = this._toRad(currentGeoCoordinates.longitude);
verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt(
Math.pow(drone.get3DSpeed(), 2) - Math.pow(verticalSpeed, 2)
);
distance = (groundSpeed * delta_time / 1000) / R;
distanceCos = Math.cos(distance);
distanceSin = Math.sin(distance);
newLatRad = Math.asin(
currentSinLat * distanceCos +
currentCosLat * distanceSin * Math.cos(newYawRad)
);
newLonRad = currentLonRad + Math.atan2(
Math.sin(newYawRad) * distanceSin * currentCosLat,
distanceCos - currentSinLat * Math.sin(newLatRad)
);
FixedWingDroneAPI.prototype._updatePosition =
function (drone, yaw, delta_time) {
var speed = drone.get3DSpeed(),
positionUpdate = speed * delta_time / 1000,
yawToDirection = this._toRad(-yaw + 90),
zNorm = this._getVerticalSpeed(drone) / speed,
xyCoef = Math.sqrt(1 - Math.abs(zNorm));
newCoordinates = this._mapManager.convertToLocalCoordinates(
this._toDeg(newLatRad),
this._toDeg(newLonRad),
drone.position.z
drone.setDirection(
xyCoef * Math.cos(yawToDirection),
xyCoef * Math.sin(yawToDirection),
zNorm
);
// swap y and z axis so z axis represents altitude
drone._controlMesh.position.addInPlace(new BABYLON.Vector3(
Math.abs(newCoordinates.x - drone.position.x) *
(newCoordinates.x < drone.position.x ? -1 : 1),
verticalSpeed * delta_time / 1000,
Math.abs(newCoordinates.y - drone.position.y) *
(newCoordinates.y < drone.position.y ? -1 : 1)
drone._direction.x * positionUpdate,
drone._direction.y * positionUpdate,
drone._direction.z * positionUpdate
));
yawToDirection = this._toRad(-newYaw + 90);
drone.setDirection(
groundSpeed * Math.cos(yawToDirection),
groundSpeed * Math.sin(yawToDirection),
verticalSpeed
);
};
FixedWingDroneAPI.prototype._getNewYaw =
......@@ -289,14 +377,20 @@ var FixedWingDroneAPI = /** @class */ (function () {
return verticalSpeed;
};
FixedWingDroneAPI.prototype._setSpeedInternal = function (speed) {
this._targetSpeed = speed;
};
FixedWingDroneAPI.prototype.setSpeed = function (drone, speed) {
this._targetSpeed = Math.max(
Math.min(speed, this.getMaxSpeed()),
this.getMinSpeed()
);
if (speed < this.getMinSpeed()) {
throw new Error('Requested speed must be greater than '
+ this.getMinSpeed());
}
this._requestedSpeed = Math.min(speed, this.getMaxSpeed());
this._setSpeedInternal(this._requestedSpeed * this.getSpeedFactor());
drone._acceleration = (this._targetSpeed > drone.get3DSpeed()) ?
this.getMaxAcceleration() : -this.getMaxDeceleration();
drone._acceleration = (this._targetSpeed > drone.get3DSpeed())
? this.getMaxAcceleration() : this.getMaxDeceleration();
};
FixedWingDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) {
......@@ -460,6 +554,9 @@ var FixedWingDroneAPI = /** @class */ (function () {
FixedWingDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxClimbRate;
};
FixedWingDroneAPI.prototype.getSpeedFactor = function () {
return this._flight_parameters.drone.speedFactor;
};
FixedWingDroneAPI.prototype.getMaxCommandFrequency = function () {
return this._flight_parameters.drone.maxCommandFrequency;
};
......@@ -511,7 +608,7 @@ 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) {
......
......@@ -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,15 +896,8 @@ 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) {
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) {
......@@ -911,7 +905,6 @@ var GameManager = /** @class */ (function () {
drone.score += flag.score; // move score to a global place? GM, MM?
}
}
}
};
GameManager.prototype._checkCollision = function (drone, other) {
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1017.23888.64540.55859</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>1730211399.63</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>
......
/*global BABYLON, console*/
/*jslint nomen: true, indent: 2, maxlen: 80, todo: true */
/************************** MULTICOPTER DRONE API ****************************/
var MulticopterDroneAPI = /** @class */ (function () {
"use strict";
var DEFAULT_SPEED = 5,
DEFAULT_TAKEOFF_ALTITUDE = 7,
MAX_MESSAGE_SIZE = 1024,
VIEW_SCOPE = 100;
MulticopterDroneAPI.DRONE_TYPE = "Multicopter";
MulticopterDroneAPI.SCRIPT_NAME =
"gadget_erp5_page_drone_capture_flag_multicopterdrone.js";
MulticopterDroneAPI.FORM_VIEW = {
"my_drone_max_speed": {
"description": "",
"title": "Drone max speed",
"default": 16,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxSpeed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_acceleration": {
"description": "",
"title": "Drone max Acceleration",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxAcceleration",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
"title": "Drone max Deceleration",
"default": 3,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxDeceleration",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_roll": {
"description": "",
"title": "Drone max roll",
"default": 13,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxRoll",
"hidden": 0,
"type": "FloatField"
},
"my_drone_speed_factor": {
"description": "",
"title": "Drone speed factor",
"default": 1.2,
"css_class": "",
"required": 1,
"editable": 1,
"key": "speedFactor",
"hidden": 0,
"type": "FloatField"
},
"my_drone_min_approach_speed": {
"description": "",
"title": "Drone min approach speed",
"default": 0.1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "minApproachSpeed",
"hidden": 0,
"type": "FloatField"
},
"my_drone_take_off_factor": {
"description": "",
"title": "Drone take off factor",
"default": 20,
"css_class": "",
"required": 1,
"editable": 1,
"key": "takeOffFactor",
"hidden": 0,
"type": "FloatField"
},
"my_drone_yaw_acceptance": {
"description": "",
"title": "Drone yaw acceptance",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "yawAcceptance",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_command_frequency": {
"description": "",
"title": "Drone max command frequency",
"default": 2,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxCommandFrequency",
"hidden": 0,
"type": "FloatField"
}
};
//** CONSTRUCTOR
function MulticopterDroneAPI(gameManager, drone_info, flight_parameters, id) {
this._gameManager = gameManager;
this._mapManager = this._gameManager._mapManager;
this._map_dict = this._mapManager.getMapInfo();
this._flight_parameters = flight_parameters;
this._id = id;
this._drone_info = drone_info;
//this._start_altitude = 0;
this._is_landing = false;
this._is_ready_to_fly = false;
this._drone_dict_list = [];
}
/*
** Function called on start phase of the drone, just before onStart AI script
*/
MulticopterDroneAPI.prototype.internal_start = function (drone) {
if (this.getMaxDeceleration() <= 0) {
throw new Error('max deceleration must be superior to 0');
}
if (this.getMaxAcceleration() <= 0) {
throw new Error('max acceleration must be superior to 0');
}
if (this.getMaxSpeed() <= 0) {
throw new Error('Max speed must be superior to 0');
}
drone._speed = drone._targetSpeed = 0;
if (this.getMaxRollAngle() <= 0) {
throw new Error('max roll angle must be superior to 0');
}
if (this.getMaxCommandFrequency() <= 0) {
throw new Error('max command frequence must be superior to 0');
}
return;
};
/*
** Function called on every drone update, right before onUpdate AI script
*/
MulticopterDroneAPI.prototype.internal_position_update =
function (context, delta_time) {
var currentGeoCoordinates = this._mapManager.convertToGeoCoordinates(
context.position.x,
context.position.y,
context.position.z
),
targetCoordinates = this._mapManager.convertToGeoCoordinates(
context._targetCoordinates.x,
context._targetCoordinates.y,
context._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
newYaw = this._getNewYaw(context, bearing, delta_time);
if (!this.isReadyToFly() && !this.isLanding()
&& context.position.z >= DEFAULT_TAKEOFF_ALTITUDE) {
this._is_ready_to_fly = true;
context._speed = 0;
}
if (Math.abs(bearing - newYaw) < this.getYawAcceptance()) {
this._updateSpeed(context, currentGeoCoordinates, targetCoordinates,
delta_time);
}
this._updatePosition(context, newYaw, delta_time);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
};
/*
** Function called on every drone update, right after onUpdate AI script
*/
MulticopterDroneAPI.prototype.internal_info_update = function (drone) {
var _this = this, drone_position = drone.getCurrentPosition(), drone_info;
/*if (_this._start_altitude > 0) { //TODO move start_altitude here
_this.reachAltitude(drone);
}*/
if (drone_position) {
drone_info = {
'altitudeRel' : drone_position.altitude,
'altitudeAbs' : _this._mapManager.getMapInfo().start_AMSL +
drone_position.altitude,
'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude,
'yaw': drone.getYaw(),
'speed': drone.getSpeed(),
'climbRate': drone.getClimbRate(),
'timestamp': drone_position.timestamp
};
_this._drone_dict_list[_this._id] = drone_info;
//broadcast drone info using internal msg
_this._gameManager._droneList.forEach(function (drone) {
if (drone.id !== _this._id) {
drone.internal_getMsg(drone_info, _this._id);
}
});
}
};
MulticopterDroneAPI.prototype._updateSpeed =
function (drone, currentGeoCoordinates, targetCoordinates, delta_time) {
var speed = drone.get3DSpeed(), speedDiff, speedUpdate,
distance = Math.sqrt(
Math.pow(
this._mapManager.mapUtils.latLonDistance(
[currentGeoCoordinates.latitude, currentGeoCoordinates.longitude],
[targetCoordinates.latitude, targetCoordinates.longitude]
),
2
) + Math.pow(
targetCoordinates.altitude - currentGeoCoordinates.altitude,
2
)
);
if (this._targetSpeed > distance) {
drone._acceleration = this.getMaxDeceleration();
this._targetSpeed = Math.max(distance, this.getMinApproachSpeed());
}
speedUpdate = drone._acceleration * delta_time / 1000;
if (speed > this._targetSpeed) {
speedUpdate *= -1;
}
if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed;
if (Math.abs(speedDiff) < Math.abs(speedUpdate)) {
drone._speed = this._targetSpeed;
} else {
drone._speed += speedUpdate;
}
}
};
MulticopterDroneAPI.prototype._updatePosition =
function (drone, yaw, delta_time) {
var positionUpdate = drone.get3DSpeed() * delta_time / 1000,
yawToDirection = this._toRad(-yaw + 90),
xDiff = drone._targetCoordinates.x - drone.position.x,
yDiff = drone._targetCoordinates.y - drone.position.y,
zDiff = drone._targetCoordinates.z - drone.position.z,
distanceToTarget = Math.sqrt(
Math.pow(xDiff, 2) + Math.pow(yDiff, 2) + Math.pow(zDiff, 2)
),
zNorm = zDiff / distanceToTarget,
xyCoef = Math.sqrt(1 - Math.abs(zNorm));
drone.setDirection(
xyCoef * Math.cos(yawToDirection),
xyCoef * Math.sin(yawToDirection),
zNorm
);
drone._controlMesh.position.addInPlace(new BABYLON.Vector3(
drone._direction.x * positionUpdate,
drone._direction.y * positionUpdate,
drone._direction.z * positionUpdate
));
};
MulticopterDroneAPI.prototype._getNewYaw =
function (drone, bearing, delta_time) {
// swap y and z axis so z axis represents altitude
var yaw = drone.getYaw(),
yawDiff = this._computeYawDiff(yaw, bearing),
yawUpdate = this.getYawVelocity(drone) * delta_time / 1000;
if (yawUpdate >= Math.abs(yawDiff)) {
yawUpdate = yawDiff;
} else if (yawDiff < 0) {
yawUpdate *= -1;
}
return yaw + yawUpdate;
};
MulticopterDroneAPI.prototype._setSpeedInternal = function (speed) {
this._targetSpeed = speed;
};
MulticopterDroneAPI.prototype.setSpeed = function (drone, speed) {
if (speed < 0) {
throw new Error('Requested speed must positive');
}
this._requestedSpeed = Math.min(speed, this.getMaxSpeed());
this._setSpeedInternal(this._requestedSpeed * this.getSpeedFactor());
drone._acceleration = (this._targetSpeed > drone.get3DSpeed())
? this.getMaxAcceleration() : this.getMaxDeceleration();
};
MulticopterDroneAPI.prototype.setStartingPosition =
function (drone, x, y, z) {
if (!drone._canPlay) {
if (z <= 0.05) {
z = 0.05;
}
drone._controlMesh.position = new BABYLON.Vector3(x, z, y);
}
drone._controlMesh.computeWorldMatrix(true);
drone._mesh.computeWorldMatrix(true);
};
MulticopterDroneAPI.prototype.internal_getMsg = function (msg, id) {
this._drone_dict_list[id] = msg;
};
MulticopterDroneAPI.prototype.internal_setTargetCoordinates =
function (drone, coordinates, speed, radius) {
this.setSpeed(drone, speed);
};
MulticopterDroneAPI.prototype.sendMsg = function (msg, to) {
if (JSON.stringify(msg).length > MAX_MESSAGE_SIZE) {
//TODO what to do? truncate the msg? log a warning? crash the drone?
msg = {"error": "message too long (max 1024)"};
}
var _this = this,
droneList = _this._gameManager._droneList;
_this._gameManager.delay(function () {
if (to < 0) {
// Send to all drones
droneList.forEach(function (drone) {
if (drone.infosMesh) {
try {
drone.onGetMsg(msg);
} catch (error) {
console.warn('Drone crashed on onGetMsg due to error:', error);
drone._internal_crash();
}
}
});
} else {
// Send to specific drone
if (droneList[to].infosMesh) {
try {
droneList[to].onGetMsg(msg);
} catch (error) {
console.warn('Drone crashed on onGetMsg due to error:', error);
droneList[to]._internal_crash();
}
}
}
}, _this._flight_parameters.latency.communication);
};
MulticopterDroneAPI.prototype.log = function (msg) {
console.log("API say : " + msg);
};
MulticopterDroneAPI.prototype.getGameParameter = function (name) {
if (["gameTime", "map"].includes(name)) {
return this._gameManager.gameParameter[name];
}
};
/*
** Converts geo latitude-longitud coordinates (º) to x,y plane coordinates (m)
*/
MulticopterDroneAPI.prototype.processCoordinates = function (lat, lon, z) {
if (isNaN(lat) || isNaN(lon) || isNaN(z)) {
throw new Error('Target coordinates must be numbers');
}
var processed_coordinates =
this._mapManager.convertToLocalCoordinates(lat, lon, z);
return processed_coordinates;
};
MulticopterDroneAPI.prototype.getCurrentPosition = function (x, y, z) {
return this._mapManager.convertToGeoCoordinates(x, y, z);
};
MulticopterDroneAPI.prototype.getDroneViewInfo = function (drone) {
var context = this, result = { "obstacles": [], "drones": [] }, distance,
other_position, drone_position = drone.getCurrentPosition();
function calculateDistance(a, b, _this) {
return _this._mapManager.latLonDistance([a.latitude, a.longitude],
[b.latitude, b.longitude]);
}
context._gameManager._droneList.forEach(function (other) {
if (other.can_play && drone.id !== other.id) {
other_position = other.getCurrentPosition();
distance = calculateDistance(drone_position, other_position, context);
if (distance <= VIEW_SCOPE) {
result.drones.push({
position: other.getCurrentPosition(),
direction: other.direction,
rotation: other.rotation,
speed: other.speed,
team: other.team
});
}
}
});
context._map_dict.obstacle_list.forEach(function (obstacle) {
distance = calculateDistance(drone_position, obstacle.position, context);
if (distance <= VIEW_SCOPE) {
result.obstacles.push(obstacle);
}
});
if (drone.__is_getting_drone_view !== true) {
drone.__is_getting_drone_view = true;
context._gameManager.delay(function () {
drone.__is_getting_drone_view = false;
try {
drone.onDroneViewInfo(result);
} catch (error) {
console.warn('Drone crashed on drone view due to error:', error);
drone._internal_crash();
}
}, 1000);
}
};
MulticopterDroneAPI.prototype.getDroneAI = function () {
return null;
};
MulticopterDroneAPI.prototype.getMaxSpeed = function () {
return this._flight_parameters.drone.maxSpeed;
};
MulticopterDroneAPI.prototype.getMaxDeceleration = function () {
return this._flight_parameters.drone.maxDeceleration;
};
MulticopterDroneAPI.prototype.getMaxAcceleration = function () {
return this._flight_parameters.drone.maxAcceleration;
};
MulticopterDroneAPI.prototype.getMaxRollAngle = function () {
return this._flight_parameters.drone.maxRoll;
};
MulticopterDroneAPI.prototype.getMaxSinkRate = function () {
return this._flight_parameters.drone.maxSpeed;
};
MulticopterDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxSpeed;
};
MulticopterDroneAPI.prototype.getSpeedFactor = function () {
return this._flight_parameters.drone.speedFactor;
};
MulticopterDroneAPI.prototype.getMinApproachSpeed = function () {
return this._flight_parameters.drone.minApproachSpeed;
};
MulticopterDroneAPI.prototype.getTakeOffFactor = function () {
return this._flight_parameters.drone.takeOffFactor;
};
MulticopterDroneAPI.prototype.getYawAcceptance = function () {
return this._flight_parameters.drone.yawAcceptance;
};
MulticopterDroneAPI.prototype.getMaxCommandFrequency = function () {
return this._flight_parameters.drone.maxCommandFrequency;
};
MulticopterDroneAPI.prototype.getYawVelocity = function (drone) {
return this.getMaxRollAngle();
};
MulticopterDroneAPI.prototype.getYaw = function (drone) {
var direction = drone.worldDirection;
return this._toDeg(Math.atan2(direction.x, direction.z));
};
MulticopterDroneAPI.prototype._computeBearing =
function (lat1, lon1, lat2, lon2) {
var dLon = this._toRad(lon2 - lon1),
lat1Rad = this._toRad(lat1),
lat2Rad = this._toRad(lat2),
x = Math.cos(lat2Rad) * Math.sin(dLon),
y = Math.cos(lat1Rad) * Math.sin(lat2Rad)
- Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(dLon);
return this._toDeg(Math.atan2(x, y));
};
MulticopterDroneAPI.prototype._computeYawDiff = function (yaw1, yaw2) {
var diff = yaw2 - yaw1;
diff += (diff > 180) ? -360 : (diff < -180) ? 360 : 0;
return diff;
};
MulticopterDroneAPI.prototype._toRad = function (angle) {
return angle * Math.PI / 180;
};
MulticopterDroneAPI.prototype._toDeg = function (angle) {
return angle * 180 / Math.PI;
};
MulticopterDroneAPI.prototype.getClimbRate = function (drone) {
return drone.worldDirection.y * drone.get3DSpeed();
};
MulticopterDroneAPI.prototype.getSpeed = function (drone) {
var direction = drone.worldDirection;
return Math.sqrt(
Math.pow(direction.x * drone.get3DSpeed(), 2)
+ Math.pow(direction.z * drone.get3DSpeed(), 2)
);
};
MulticopterDroneAPI.prototype.takeOff = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone._internal_setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
DEFAULT_TAKEOFF_ALTITUDE,
DEFAULT_SPEED
);
drone._acceleration = this.getMaxAcceleration() / this.getTakeOffFactor();
};
MulticopterDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone._internal_setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
0,
DEFAULT_SPEED
);
this._is_ready_to_fly = false;
this._is_landing = true;
};
MulticopterDroneAPI.prototype.isReadyToFly = function () {
return this._is_ready_to_fly;
};
MulticopterDroneAPI.prototype.isLanding = function () {
return this._is_landing;
};
MulticopterDroneAPI.prototype.getInitialAltitude = function () {
return this._map_dict.start_AMSL;
};
MulticopterDroneAPI.prototype.getAltitudeAbs = function (altitude) {
return altitude + this._map_dict.start_AMSL;
};
MulticopterDroneAPI.prototype.getMinHeight = function () {
return 0;
};
MulticopterDroneAPI.prototype.getMaxHeight = function () {
return 800;
};
MulticopterDroneAPI.prototype.getOnUpdateInterval = function () {
return this._flight_parameters.drone.onUpdateInterval;
};
MulticopterDroneAPI.prototype.getFlightParameters = function () {
return this._flight_parameters;
};
return MulticopterDroneAPI;
}());
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_drone_capture_flag_multicopterdrone.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>drone_capture_flag_multicopterdrone_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Multicopter Drone (API)</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1730800031.8</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1020.34636.19071.11520</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1731937150.42</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1730799819.74</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -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>
......
/*jslint indent: 2, maxlen: 100*/
/*global window, rJS, domsugar, document, Blob, MapUtils, RSVP*/
/*global window, rJS, domsugar, document, Blob, MapUtils, RSVP, FixedWingDroneAPI,
MulticopterDroneAPI*/
/******************************* OPERATOR API ********************************/
var OperatorAPI = /** @class */ (function () {
......@@ -23,10 +24,9 @@ var OperatorAPI = /** @class */ (function () {
return OperatorAPI;
}());
(function (window, rJS, domsugar, document, Blob, MapUtils, RSVP) {
(function (window, rJS, domsugar, document, Blob, MapUtils, RSVP, API_LIST) {
"use strict";
//Drone default values - TODO: get them from the drone API
var SIMULATION_SPEED = 60,
SIMULATION_TIME = 270,
//default square map
......@@ -65,21 +65,10 @@ var OperatorAPI = /** @class */ (function () {
"altitude": 15}}],
"initial_position": {"latitude": 45.642813275,
"longitude": 14.270231599999988,
"altitude": 15}
"altitude": 0}
},
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,
MAX_COMMAND_FREQUENCY = 2,
NUMBER_OF_DRONES = 5,
// Non-inputs parameters
EPSILON = "15",
DEFAULT_OPERATOR_SCRIPT = 'var map = operator.getMapJSON();\n' +
'operator.sendMsg({flag_positions: map.flag_list});\n',
......@@ -109,6 +98,7 @@ var OperatorAPI = /** @class */ (function () {
' me.direction_set = false;\n' +
' me.dodging = false;\n' +
' me.ongoing_detection = false;\n' +
' me.takeOff();\n' +
'};\n' +
'\n' +
'me.onGetMsg = function (msg) {\n' +
......@@ -119,6 +109,9 @@ var OperatorAPI = /** @class */ (function () {
'};\n' +
'\n' +
'me.onUpdate = function (timestamp) {\n' +
' if (!me.isReadyToFly()) {\n' +
' return;\n' +
' }\n' +
' if (!me.flag_positions) return;\n' +
' if (me.dodging) {\n' +
' me.current_position = me.getCurrentPosition();\n' +
......@@ -189,9 +182,10 @@ var OperatorAPI = /** @class */ (function () {
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'
],
].concat(API_LIST.map(function (api) {
return api.SCRIPT_NAME;
})),
DISPLAY_MAP_PARAMETER = 'display_map_parameter',
DISPLAY_RANDOMIZE = 'display_randomize',
DISPLAY_OPERATOR_PARAMETER = 'display_operator_parameter',
......@@ -199,6 +193,12 @@ var OperatorAPI = /** @class */ (function () {
DISPLAY_GAME_PARAMETER = 'display_game_parameter',
DISPLAY_PLAY = "display_play";
function getAPI(droneType) {
return API_LIST.find(function (api) {
return api.DRONE_TYPE === droneType;
});
}
function renderGadgetHeader(gadget, loading) {
var element_list = [],
game_map_icon = 'ui-icon-map-marker',
......@@ -534,7 +534,7 @@ var OperatorAPI = /** @class */ (function () {
// Game parameters
//////////////////////////////////////////////////
function renderGameParameterView(gadget) {
var form_gadget;
var api = getAPI(gadget.state.drone_type), erp5_view, form_gadget;
renderGadgetHeader(gadget, true);
return gadget.declareGadget("gadget_erp5_form.html", {
scope: "parameter_form"
......@@ -542,9 +542,21 @@ var OperatorAPI = /** @class */ (function () {
.push(function (sub_gadget) {
form_gadget = sub_gadget;
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
erp5_view = {
"my_drone_type": {
"description": "Type of drone to simulate",
"title": "Drone Type",
"items": API_LIST.map(function (api) {
return api.DRONE_TYPE;
}),
"value": gadget.state.drone_type,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_type",
"hidden": 0,
"type": "ListField"
},
"my_simulation_speed": {
"description": "",
"title": "Simulation Speed",
......@@ -578,127 +590,6 @@ var OperatorAPI = /** @class */ (function () {
"hidden": 0,
"type": "IntegerField"
},
"my_drone_min_speed": {
"description": "",
"title": "Drone min speed",
"default": gadget.state.drone_min_speed,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_min_speed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_speed": {
"description": "",
"title": "Drone speed",
"default": gadget.state.drone_speed,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_speed",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_speed": {
"description": "",
"title": "Drone max speed",
"default": gadget.state.drone_max_speed,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_speed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_acceleration": {
"description": "",
"title": "Drone max Acceleration",
"default": gadget.state.drone_max_acceleration,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_acceleration",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
"title": "Drone max Deceleration",
"default": gadget.state.drone_max_deceleration,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_deceleration",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_roll": {
"description": "",
"title": "Drone max roll",
"default": gadget.state.drone_max_roll,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_roll",
"hidden": 0,
"type": "FloatField"
},
"my_drone_min_pitch": {
"description": "",
"title": "Drone min pitch",
"default": gadget.state.drone_min_pitch,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_min_pitch",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_pitch": {
"description": "",
"title": "Drone max pitch",
"default": gadget.state.drone_max_pitch,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_pitch",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_sink_rate": {
"description": "",
"title": "Drone max sink rate",
"default": gadget.state.drone_max_sink_rate,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_sink_rate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_climb_rate": {
"description": "",
"title": "Drone max climb rate",
"default": gadget.state.drone_max_climb_rate,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_climb_rate",
"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",
......@@ -710,7 +601,15 @@ var OperatorAPI = /** @class */ (function () {
"hidden": 0,
"type": "IntegerField"
}
}},
};
Object.keys(api.FORM_VIEW).forEach(function (parameter) {
erp5_view[parameter] = api.FORM_VIEW[parameter];
erp5_view[parameter].default = gadget.state[erp5_view[parameter].key];
});
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": erp5_view},
"_links": {
"type": {
name: ""
......@@ -720,15 +619,13 @@ var OperatorAPI = /** @class */ (function () {
form_definition: {
group_list: [[
"left",
[["my_simulation_speed"], ["my_simulation_time"], ["my_onupdate_interval"],
["my_number_of_drones"], ["my_map_seed"]]
[["my_drone_type"], ["my_simulation_speed"], ["my_simulation_time"],
["my_onupdate_interval"], ["my_number_of_drones"]]
], [
"right",
[["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_command_frequency"]]
Object.keys(api.FORM_VIEW).map(function (property_name) {
return [property_name];
})
]]
}
});
......@@ -806,6 +703,13 @@ var OperatorAPI = /** @class */ (function () {
});
}
function formToFilename(form, drone) {
return Object.keys(form).map(function (field_name) {
var key = form[field_name].key;
return key + "_" + drone[key];
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -817,10 +721,33 @@ var OperatorAPI = /** @class */ (function () {
return this.triggerSubmit();
})
.allowPublicAcquisition('notifyChange', function (argument_list, scope) {
return this.triggerAPIChange(scope);
})
.declareMethod("triggerSubmit", function () {
return;
})
.declareMethod("triggerAPIChange", function (scope) {
var gadget = this,
sub_gadget;
return gadget.getDeclaredGadget(scope)
.push(function (result) {
sub_gadget = result;
return sub_gadget.getContent();
})
.push(function (result) {
if (result.hasOwnProperty("drone_type")
&& gadget.state.drone_type !== result.drone_type) {
return gadget.changeState({
drone_type: result.drone_type
});
}
});
})
.declareJob('runGame', function runGame(do_nothing) {
if (do_nothing) {
// Cancel the previous job execution
......@@ -829,13 +756,14 @@ var OperatorAPI = /** @class */ (function () {
var gadget = this,
i,
parsed_map,
fragment = gadget.element.querySelector('.simulator_div'),
game_parameters_json,
drone_list = [];
fragment = domsugar(gadget.element.querySelector('.simulator_div'),
[domsugar('div')]).firstElementChild;
[domsugar('div')]).firstElementChild,
game_parameters_json,
drone_list = [],
api = getAPI(gadget.state.drone_type),
drone_parameter_list = Object.keys(api.FORM_VIEW);
for (i = 0; i < gadget.state.number_of_drones; i += 1) {
drone_list[i] = {"id": i, "type": "FixedWingDroneAPI",
drone_list[i] = {"id": i, "type": api.name,
"script_content": gadget.state.drone_script};
}
try {
......@@ -846,17 +774,6 @@ var OperatorAPI = /** @class */ (function () {
}
game_parameters_json = {
"drone": {
"maxAcceleration": parseFloat(gadget.state.drone_max_acceleration),
"maxDeceleration": parseInt(gadget.state.drone_max_deceleration, 10),
"minSpeed": parseInt(gadget.state.drone_min_speed, 10),
"speed": parseFloat(gadget.state.drone_speed),
"maxSpeed": parseInt(gadget.state.drone_max_speed, 10),
"maxRoll": parseFloat(gadget.state.drone_max_roll),
"minPitchAngle": parseFloat(gadget.state.drone_min_pitch),
"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),
"onUpdateInterval": parseInt(gadget.state.onupdate_interval, 10),
"list": drone_list
},
......@@ -873,6 +790,19 @@ var OperatorAPI = /** @class */ (function () {
"log_drone_flight": LOG,
"log_interval_time": LOG_TIME
};
drone_parameter_list.forEach(function (parameter) {
var field = api.FORM_VIEW[parameter];
switch (field.type) {
case 'IntegerField':
game_parameters_json.drone[field.key] = parseInt(gadget.state[field.key], 10);
break;
case 'FloatField':
game_parameters_json.drone[field.key] = parseFloat(gadget.state[field.key]);
break;
default:
throw new Error("Unhandled field type");
}
});
return gadget.declareGadget("babylonjs.gadget.html",
{element: fragment, scope: 'simulator'})
.push(function () {
......@@ -932,18 +862,9 @@ var OperatorAPI = /** @class */ (function () {
blob = new Blob([log_content], {type: 'text/plain'});
a = domsugar('a', {
text: 'Download Simulation LOG ' + i,
download: 'simulation_log_' + i +
'_speed_' + game_parameters_json.drone.speed +
'_min-speed_' + game_parameters_json.drone.minSpeed +
'_max-speed_' + game_parameters_json.drone.maxSpeed +
'_max-accel_' + game_parameters_json.drone.maxAcceleration +
'_max-decel_' + game_parameters_json.drone.maxDeceleration +
'_max-roll_' + game_parameters_json.drone.maxRoll +
'_min-pitch_' + game_parameters_json.drone.minPitchAngle +
'_max-pitch_' + game_parameters_json.drone.maxPitchAngle +
'_max-sink_' + game_parameters_json.drone.maxSinkRate +
'_max-climb_' + game_parameters_json.drone.maxClimbRate +
'.txt',
download: ['simulation_log_' + i].concat(
formToFilename(api.FORM_VIEW, game_parameters_json.drone)
).join("_") + ".txt",
href: window.URL.createObjectURL(blob)
});
log = domsugar('textarea',
......@@ -969,20 +890,10 @@ var OperatorAPI = /** @class */ (function () {
})
.setState({
drone_type: API_LIST[0].DRONE_TYPE,
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,
drone_min_pitch: MIN_PITCH,
drone_max_roll: MAX_ROLL,
drone_max_deceleration: MAX_DECELERATION,
drone_max_acceleration: MAX_ACCELERATION,
drone_max_speed: MAX_SPEED,
drone_speed: DEFAULT_SPEED,
drone_min_speed: MIN_SPEED,
onupdate_interval: ONUPDATE_INTERVAL,
simulation_time: SIMULATION_TIME,
simulation_speed: SIMULATION_SPEED,
......@@ -994,10 +905,14 @@ var OperatorAPI = /** @class */ (function () {
})
.declareMethod('render', function render() {
var gadget = this;
return gadget.changeState({
display_step: DISPLAY_PLAY
})
var gadget = this,
api = getAPI(gadget.state.drone_type),
new_state = { display_step: DISPLAY_PLAY };
Object.keys(api.FORM_VIEW).forEach(function (parameter) {
var field = api.FORM_VIEW[parameter];
new_state[field.key] = field.default;
});
return gadget.changeState(new_state)
.push(function () {
return gadget.updateHeader({
page_title: 'Drone Capture Flag',
......@@ -1007,7 +922,7 @@ var OperatorAPI = /** @class */ (function () {
})
.onStateChange(function (modification_dict) {
var gadget = this;
var gadget = this, api;
if (gadget.state.display_step === DISPLAY_MAP_PARAMETER) {
if (modification_dict.hasOwnProperty('display_step')) {
......@@ -1048,6 +963,15 @@ var OperatorAPI = /** @class */ (function () {
return renderPlayView(gadget);
}
if (modification_dict.hasOwnProperty('drone_type')) {
api = getAPI(gadget.state.drone_type);
Object.keys(api.FORM_VIEW).forEach(function (parameter) {
var field = api.FORM_VIEW[parameter];
gadget.state[field.key] = field.default;
});
return renderGameParameterView(gadget);
}
if (modification_dict.hasOwnProperty('display_step')) {
throw new Error('Unhandled display step: ' + gadget.state.display_step);
}
......@@ -1170,4 +1094,4 @@ var OperatorAPI = /** @class */ (function () {
}(window, rJS, domsugar, document, Blob, MapUtils, RSVP));
\ No newline at end of file
}(window, rJS, domsugar, document, Blob, MapUtils, RSVP, [MulticopterDroneAPI, FixedWingDroneAPI]));
\ No newline at end of file
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1020.20542.569.24900</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>1730211735.44</float>
<float>1732098322.73</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -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>
......
......@@ -6,19 +6,147 @@ var FixedWingDroneAPI = /** @class */ (function () {
"use strict";
// var TAKEOFF_RADIUS = 60,
var DEFAULT_SPEED = 16,
PARACHUTE_SPEED = 8,
EARTH_GRAVITY = 9.81,
var EARTH_GRAVITY = 9.81,
LOITER_LIMIT = 30,
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;
PARACHUTE_SPEED = 8;
FixedWingDroneAPI.DRONE_TYPE = "Fixed Wings";
FixedWingDroneAPI.SCRIPT_NAME =
"gadget_erp5_page_drone_simulator_fixedwingdrone.js";
FixedWingDroneAPI.FORM_VIEW = {
"my_drone_min_speed": {
"description": "",
"title": "Drone min speed",
"default": 12,
"css_class": "",
"required": 1,
"editable": 1,
"key": "minSpeed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_speed": {
"description": "",
"title": "Drone speed",
"default": 16,
"css_class": "",
"required": 1,
"editable": 1,
"key": "speed",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_speed": {
"description": "",
"title": "Drone max speed",
"default": 26,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxSpeed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_acceleration": {
"description": "",
"title": "Drone max Acceleration",
"default": 6,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxAcceleration",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
"title": "Drone max Deceleration",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxDeceleration",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_roll": {
"description": "",
"title": "Drone max roll",
"default": 35,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxRoll",
"hidden": 0,
"type": "FloatField"
},
"my_drone_min_pitch": {
"description": "",
"title": "Drone min pitch",
"default": -20,
"css_class": "",
"required": 1,
"editable": 1,
"key": "minPitchAngle",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_pitch": {
"description": "",
"title": "Drone max pitch",
"default": 25,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxPitchAngle",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_sink_rate": {
"description": "",
"title": "Drone max sink rate",
"default": 3,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxSinkRate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_climb_rate": {
"description": "",
"title": "Drone max climb rate",
"default": 8,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxClimbRate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_speed_factor": {
"description": "",
"title": "Drone speed factor",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "speedFactor",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_command_frequency": {
"description": "",
"title": "Drone max command frequency",
"default": 5,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxCommandFrequency",
"hidden": 0,
"type": "FloatField"
}
};
//** CONSTRUCTOR
function FixedWingDroneAPI(gameManager, drone_info, flight_parameters, id) {
......@@ -102,9 +230,46 @@ var FixedWingDroneAPI = /** @class */ (function () {
/*
** Function called on every drone update, right before onUpdate AI script
*/
FixedWingDroneAPI.prototype.internal_position_update = function (context, delta_time) {
FixedWingDroneAPI.prototype.internal_position_update =
function (context, delta_time) {
var currentGeoCoordinates = this._mapManager.convertToGeoCoordinates(
context.position.x,
context.position.y,
context.position.z
),
targetCoordinates = this._mapManager.convertToGeoCoordinates(
context._targetCoordinates.x,
context._targetCoordinates.y,
context._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
distanceToTarget,
newYaw;
if (this._loiter_mode) {
distanceToTarget = Math.sqrt(
Math.pow(context._targetCoordinates.x - context.position.x, 2)
+ Math.pow(context._targetCoordinates.y - context.position.y, 2)
);
if (Math.abs(distanceToTarget - this._loiter_radius) <= 1) {
newYaw = bearing - 90;
} else if (distanceToTarget < this._loiter_radius) {
newYaw = bearing - 135;
} else {
newYaw = this._getNewYaw(context, bearing, delta_time);
}
} else {
newYaw = this._getNewYaw(context, bearing, delta_time);
}
this._updateSpeed(context, delta_time);
this._updatePosition(context, delta_time);
this._updatePosition(context, newYaw, delta_time);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
......@@ -140,115 +305,42 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) {
var speed = drone.get3DSpeed(), speedDiff, speedUpdate;
var speed = drone.get3DSpeed(), speedDiff,
speedUpdate = drone._acceleration * delta_time / 1000;
if (speed > this._targetSpeed) {
speedUpdate *= -1;
}
if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed;
speedUpdate = drone._acceleration * delta_time / 1000;
if (Math.abs(speedDiff) < Math.abs(speedUpdate)) {
drone._speed = this._targetSpeed;
drone._acceleration = 0;
} else {
drone._speed += speedUpdate;
}
}
};
FixedWingDroneAPI.prototype._updatePosition = function (drone, delta_time) {
var R = 6371e3,
currentGeoCoordinates = this._mapManager.convertToGeoCoordinates(
drone.position.x,
drone.position.y,
drone.position.z
),
targetCoordinates = this._mapManager.convertToGeoCoordinates(
drone._targetCoordinates.x,
drone._targetCoordinates.y,
drone._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
currentCosLat,
currentLatRad,
distance,
distanceCos,
distanceSin,
distanceToTarget,
currentSinLat,
currentLonRad,
groundSpeed,
newCoordinates,
newLatRad,
newLonRad,
newYaw,
newYawRad,
verticalSpeed,
yawToDirection;
if (this._loiter_mode) {
distanceToTarget = Math.sqrt(
Math.pow(drone._targetCoordinates.x - drone.position.x, 2)
+ Math.pow(drone._targetCoordinates.y - drone.position.y, 2)
);
FixedWingDroneAPI.prototype._updatePosition =
function (drone, yaw, delta_time) {
var speed = drone.get3DSpeed(),
positionUpdate = speed * delta_time / 1000,
yawToDirection = this._toRad(-yaw + 90),
zNorm = this._getVerticalSpeed(drone) / speed,
xyCoef = Math.sqrt(1 - Math.abs(zNorm));
if (Math.abs(distanceToTarget - this._loiter_radius) <= 1) {
newYaw = bearing - 90;
} else if (distanceToTarget < this._loiter_radius) {
newYaw = bearing - 135;
} else {
newYaw = this._getNewYaw(drone, bearing, delta_time);
}
} else {
newYaw = this._getNewYaw(drone, bearing, delta_time);
}
newYawRad = this._toRad(newYaw);
currentLatRad = this._toRad(currentGeoCoordinates.latitude);
currentCosLat = Math.cos(currentLatRad);
currentSinLat = Math.sin(currentLatRad);
currentLonRad = this._toRad(currentGeoCoordinates.longitude);
verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt(
Math.pow(drone.get3DSpeed(), 2) - Math.pow(verticalSpeed, 2)
);
distance = (groundSpeed * delta_time / 1000) / R;
distanceCos = Math.cos(distance);
distanceSin = Math.sin(distance);
newLatRad = Math.asin(
currentSinLat * distanceCos
+ currentCosLat * distanceSin * Math.cos(newYawRad)
);
newLonRad = currentLonRad + Math.atan2(
Math.sin(newYawRad) * distanceSin * currentCosLat,
distanceCos - currentSinLat * Math.sin(newLatRad)
);
newCoordinates = this._mapManager.convertToLocalCoordinates(
this._toDeg(newLatRad),
this._toDeg(newLonRad),
drone.position.z
drone.setDirection(
xyCoef * Math.cos(yawToDirection),
xyCoef * Math.sin(yawToDirection),
zNorm
);
// swap y and z axis so z axis represents altitude
drone._controlMesh.position.addInPlace(new BABYLON.Vector3(
Math.abs(newCoordinates.x - drone.position.x)
* (newCoordinates.x < drone.position.x ? -1 : 1),
verticalSpeed * delta_time / 1000,
Math.abs(newCoordinates.y - drone.position.y)
* (newCoordinates.y < drone.position.y ? -1 : 1)
drone._direction.x * positionUpdate,
drone._direction.y * positionUpdate,
drone._direction.z * positionUpdate
));
yawToDirection = this._toRad(-newYaw + 90);
drone.setDirection(
groundSpeed * Math.cos(yawToDirection),
groundSpeed * Math.sin(yawToDirection),
verticalSpeed
);
};
FixedWingDroneAPI.prototype._getNewYaw =
......@@ -289,14 +381,20 @@ var FixedWingDroneAPI = /** @class */ (function () {
return verticalSpeed;
};
FixedWingDroneAPI.prototype._setSpeedInternal = function (speed) {
this._targetSpeed = speed;
};
FixedWingDroneAPI.prototype.setSpeed = function (drone, speed) {
this._targetSpeed = Math.max(
Math.min(speed, this.getMaxSpeed()),
this.getMinSpeed()
);
if (speed < this.getMinSpeed()) {
throw new Error('Requested speed must be greater than '
+ this.getMinSpeed());
}
this._requestedSpeed = Math.min(speed, this.getMaxSpeed());
this._setSpeedInternal(this._requestedSpeed * this.getSpeedFactor());
drone._acceleration = (this._targetSpeed > drone.get3DSpeed())
? this.getMaxAcceleration() : -this.getMaxDeceleration();
? this.getMaxAcceleration() : this.getMaxDeceleration();
};
FixedWingDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) {
......@@ -412,6 +510,9 @@ var FixedWingDroneAPI = /** @class */ (function () {
FixedWingDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxClimbRate;
};
FixedWingDroneAPI.prototype.getSpeedFactor = function () {
return this._flight_parameters.drone.speedFactor;
};
FixedWingDroneAPI.prototype.getMaxCommandFrequency = function () {
return this._flight_parameters.drone.maxCommandFrequency;
};
......@@ -464,7 +565,7 @@ 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) {
......
......@@ -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) {
......@@ -990,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
......@@ -1003,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.23929.56045.37085</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>1719320607.48</float>
<float>1730712553.54</float>
<string>UTC</string>
</tuple>
</state>
......
/*global BABYLON, console*/
/*jslint nomen: true, indent: 2, maxlen: 80, todo: true */
/************************** MULTICOPTER DRONE API ****************************/
var MulticopterDroneAPI = /** @class */ (function () {
"use strict";
var DEFAULT_SPEED = 5,
DEFAULT_TAKEOFF_ALTITUDE = 7;
MulticopterDroneAPI.DRONE_TYPE = "Multicopter";
MulticopterDroneAPI.SCRIPT_NAME =
"gadget_erp5_page_drone_simulator_multicopterdrone.js";
MulticopterDroneAPI.FORM_VIEW = {
"my_drone_max_speed": {
"description": "",
"title": "Drone max speed",
"default": 16,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxSpeed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_acceleration": {
"description": "",
"title": "Drone max Acceleration",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxAcceleration",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
"title": "Drone max Deceleration",
"default": 3,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxDeceleration",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_roll": {
"description": "",
"title": "Drone max roll",
"default": 13,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxRoll",
"hidden": 0,
"type": "FloatField"
},
"my_drone_speed_factor": {
"description": "",
"title": "Drone speed factor",
"default": 1.2,
"css_class": "",
"required": 1,
"editable": 1,
"key": "speedFactor",
"hidden": 0,
"type": "FloatField"
},
"my_drone_min_approach_speed": {
"description": "",
"title": "Drone min approach speed",
"default": 0.1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "minApproachSpeed",
"hidden": 0,
"type": "FloatField"
},
"my_drone_take_off_factor": {
"description": "",
"title": "Drone take off factor",
"default": 20,
"css_class": "",
"required": 1,
"editable": 1,
"key": "takeOffFactor",
"hidden": 0,
"type": "FloatField"
},
"my_drone_yaw_acceptance": {
"description": "",
"title": "Drone yaw acceptance",
"default": 1,
"css_class": "",
"required": 1,
"editable": 1,
"key": "yawAcceptance",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_command_frequency": {
"description": "",
"title": "Drone max command frequency",
"default": 2,
"css_class": "",
"required": 1,
"editable": 1,
"key": "maxCommandFrequency",
"hidden": 0,
"type": "FloatField"
}
};
//** CONSTRUCTOR
function MulticopterDroneAPI(gameManager, drone_info, flight_parameters, id) {
this._gameManager = gameManager;
this._mapManager = this._gameManager._mapManager;
this._map_dict = this._mapManager.getMapInfo();
this._flight_parameters = flight_parameters;
this._id = id;
this._drone_info = drone_info;
//this._start_altitude = 0;
this._is_landing = false;
this._is_ready_to_fly = false;
this._drone_dict_list = [];
}
Object.defineProperty(MulticopterDroneAPI.prototype, "isCollidable", {
get: function () { return true; },
enumerable: true,
configurable: true
});
/*
** Function called on start phase of the drone, just before onStart AI script
*/
MulticopterDroneAPI.prototype.internal_start = function (drone) {
if (this.getMaxDeceleration() <= 0) {
throw new Error('max deceleration must be superior to 0');
}
if (this.getMaxAcceleration() <= 0) {
throw new Error('max acceleration must be superior to 0');
}
if (this.getMaxSpeed() <= 0) {
throw new Error('Max speed must be superior to 0');
}
drone._speed = drone._targetSpeed = 0;
if (this.getMaxRollAngle() <= 0) {
throw new Error('max roll angle must be superior to 0');
}
if (this.getMaxCommandFrequency() <= 0) {
throw new Error('max command frequence must be superior to 0');
}
return;
};
/*
** Function called on every drone update, right before onUpdate AI script
*/
MulticopterDroneAPI.prototype.internal_position_update =
function (context, delta_time) {
var currentGeoCoordinates = this._mapManager.convertToGeoCoordinates(
context.position.x,
context.position.y,
context.position.z
),
targetCoordinates = this._mapManager.convertToGeoCoordinates(
context._targetCoordinates.x,
context._targetCoordinates.y,
context._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
newYaw = this._getNewYaw(context, bearing, delta_time);
if (!this.isReadyToFly() && !this.isLanding()
&& context.position.z >= DEFAULT_TAKEOFF_ALTITUDE) {
this._is_ready_to_fly = true;
context._speed = 0;
}
if (Math.abs(bearing - newYaw) < this.getYawAcceptance()) {
this._updateSpeed(context, currentGeoCoordinates, targetCoordinates,
delta_time);
}
this._updatePosition(context, newYaw, delta_time);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
};
/*
** Function called on every drone update, right after onUpdate AI script
*/
MulticopterDroneAPI.prototype.internal_info_update = function (drone) {
var _this = this, drone_position = drone.getCurrentPosition(), drone_info;
/*if (_this._start_altitude > 0) { //TODO move start_altitude here
_this.reachAltitude(drone);
}*/
if (drone_position) {
drone_info = {
'altitudeRel' : drone_position.altitude,
'altitudeAbs' : _this._mapManager.getMapInfo().start_AMSL +
drone_position.altitude,
'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude,
'yaw': drone.getYaw(),
'speed': drone.getSpeed(),
'climbRate': drone.getClimbRate(),
'timestamp': drone_position.timestamp
};
_this._drone_dict_list[_this._id] = drone_info;
//broadcast drone info using internal msg
_this._gameManager._droneList.forEach(function (drone) {
if (drone.id !== _this._id) {
drone.internal_getMsg(drone_info, _this._id);
}
});
}
};
MulticopterDroneAPI.prototype._updateSpeed =
function (drone, currentGeoCoordinates, targetCoordinates, delta_time) {
var speed = drone.get3DSpeed(), speedDiff, speedUpdate,
distance = Math.sqrt(
Math.pow(
this._mapManager.mapUtils.latLonDistance(
[currentGeoCoordinates.latitude, currentGeoCoordinates.longitude],
[targetCoordinates.latitude, targetCoordinates.longitude]
),
2
) + Math.pow(
targetCoordinates.altitude - currentGeoCoordinates.altitude,
2
)
);
if (this._targetSpeed > distance) {
drone._acceleration = this.getMaxDeceleration();
this._targetSpeed = Math.max(distance, this.getMinApproachSpeed());
}
speedUpdate = drone._acceleration * delta_time / 1000;
if (speed > this._targetSpeed) {
speedUpdate *= -1;
}
if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed;
if (Math.abs(speedDiff) < Math.abs(speedUpdate)) {
drone._speed = this._targetSpeed;
} else {
drone._speed += speedUpdate;
}
}
};
MulticopterDroneAPI.prototype._updatePosition =
function (drone, yaw, delta_time) {
var positionUpdate = drone.get3DSpeed() * delta_time / 1000,
yawToDirection = this._toRad(-yaw + 90),
xDiff = drone._targetCoordinates.x - drone.position.x,
yDiff = drone._targetCoordinates.y - drone.position.y,
zDiff = drone._targetCoordinates.z - drone.position.z,
distanceToTarget = Math.sqrt(
Math.pow(xDiff, 2) + Math.pow(yDiff, 2) + Math.pow(zDiff, 2)
),
zNorm = zDiff / distanceToTarget,
xyCoef = Math.sqrt(1 - Math.abs(zNorm));
drone.setDirection(
xyCoef * Math.cos(yawToDirection),
xyCoef * Math.sin(yawToDirection),
zNorm
);
drone._controlMesh.position.addInPlace(new BABYLON.Vector3(
drone._direction.x * positionUpdate,
drone._direction.y * positionUpdate,
drone._direction.z * positionUpdate
));
};
MulticopterDroneAPI.prototype._getNewYaw =
function (drone, bearing, delta_time) {
// swap y and z axis so z axis represents altitude
var yaw = drone.getYaw(),
yawDiff = this._computeYawDiff(yaw, bearing),
yawUpdate = this.getYawVelocity(drone) * delta_time / 1000;
if (yawUpdate >= Math.abs(yawDiff)) {
yawUpdate = yawDiff;
} else if (yawDiff < 0) {
yawUpdate *= -1;
}
return yaw + yawUpdate;
};
MulticopterDroneAPI.prototype._setSpeedInternal = function (speed) {
this._targetSpeed = speed;
};
MulticopterDroneAPI.prototype.setSpeed = function (drone, speed) {
if (speed < 0) {
throw new Error('Requested speed must positive');
}
this._requestedSpeed = Math.min(speed, this.getMaxSpeed());
this._setSpeedInternal(this._requestedSpeed * this.getSpeedFactor());
drone._acceleration = (this._targetSpeed > drone.get3DSpeed())
? this.getMaxAcceleration() : this.getMaxDeceleration();
};
MulticopterDroneAPI.prototype.setStartingPosition =
function (drone, x, y, z) {
if (!drone._canPlay) {
if (z <= 0.05) {
z = 0.05;
}
drone._controlMesh.position = new BABYLON.Vector3(x, z, y);
}
drone._controlMesh.computeWorldMatrix(true);
drone._mesh.computeWorldMatrix(true);
};
MulticopterDroneAPI.prototype.internal_getMsg = function (msg, id) {
this._drone_dict_list[id] = msg;
};
MulticopterDroneAPI.prototype.internal_setTargetCoordinates =
function (drone, coordinates, speed, radius) {
this.setSpeed(drone, speed);
};
MulticopterDroneAPI.prototype.sendMsg = function (msg, to) {
var _this = this,
droneList = _this._gameManager._droneList;
_this._gameManager.delay(function () {
if (to < 0) {
// Send to all drones
droneList.forEach(function (drone) {
if (drone.infosMesh) {
try {
drone.onGetMsg(msg);
} catch (error) {
console.warn('Drone crashed on sendMsg due to error:', error);
drone._internal_crash();
}
}
});
} else {
// Send to specific drone
if (droneList[to].infosMesh) {
try {
droneList[to].onGetMsg(msg);
} catch (error) {
console.warn('Drone crashed on sendMsg due to error:', error);
droneList[to]._internal_crash();
}
}
}
}, _this._flight_parameters.latency.communication);
};
MulticopterDroneAPI.prototype.log = function (msg) {
console.log("API say : " + msg);
};
MulticopterDroneAPI.prototype.getGameParameter = function (name) {
if (["gameTime", "map"].includes(name)) {
return this._gameManager.gameParameter[name];
}
};
/*
** Converts geo latitude-longitud coordinates (º) to x,y plane coordinates (m)
*/
MulticopterDroneAPI.prototype.processCoordinates = function (lat, lon, z) {
if (isNaN(lat) || isNaN(lon) || isNaN(z)) {
throw new Error('Target coordinates must be numbers');
}
var processed_coordinates =
this._mapManager.convertToLocalCoordinates(lat, lon, z);
return processed_coordinates;
};
MulticopterDroneAPI.prototype.getCurrentPosition = function (x, y, z) {
return this._mapManager.convertToGeoCoordinates(x, y, z);
};
MulticopterDroneAPI.prototype.getDroneAI = function () {
return null;
};
MulticopterDroneAPI.prototype.getMaxSpeed = function () {
return this._flight_parameters.drone.maxSpeed;
};
MulticopterDroneAPI.prototype.getMaxDeceleration = function () {
return this._flight_parameters.drone.maxDeceleration;
};
MulticopterDroneAPI.prototype.getMaxAcceleration = function () {
return this._flight_parameters.drone.maxAcceleration;
};
MulticopterDroneAPI.prototype.getMaxRollAngle = function () {
return this._flight_parameters.drone.maxRoll;
};
MulticopterDroneAPI.prototype.getMaxSinkRate = function () {
return this._flight_parameters.drone.maxSpeed;
};
MulticopterDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxSpeed;
};
MulticopterDroneAPI.prototype.getSpeedFactor = function () {
return this._flight_parameters.drone.speedFactor;
};
MulticopterDroneAPI.prototype.getMinApproachSpeed = function () {
return this._flight_parameters.drone.minApproachSpeed;
};
MulticopterDroneAPI.prototype.getTakeOffFactor = function () {
return this._flight_parameters.drone.takeOffFactor;
};
MulticopterDroneAPI.prototype.getYawAcceptance = function () {
return this._flight_parameters.drone.yawAcceptance;
};
MulticopterDroneAPI.prototype.getMaxCommandFrequency = function () {
return this._flight_parameters.drone.maxCommandFrequency;
};
MulticopterDroneAPI.prototype.getYawVelocity = function (drone) {
return this.getMaxRollAngle();
};
MulticopterDroneAPI.prototype.getYaw = function (drone) {
var direction = drone.worldDirection;
return this._toDeg(Math.atan2(direction.x, direction.z));
};
MulticopterDroneAPI.prototype._computeBearing =
function (lat1, lon1, lat2, lon2) {
var dLon = this._toRad(lon2 - lon1),
lat1Rad = this._toRad(lat1),
lat2Rad = this._toRad(lat2),
x = Math.cos(lat2Rad) * Math.sin(dLon),
y = Math.cos(lat1Rad) * Math.sin(lat2Rad)
- Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(dLon);
return this._toDeg(Math.atan2(x, y));
};
MulticopterDroneAPI.prototype._computeYawDiff = function (yaw1, yaw2) {
var diff = yaw2 - yaw1;
diff += (diff > 180) ? -360 : (diff < -180) ? 360 : 0;
return diff;
};
MulticopterDroneAPI.prototype._toRad = function (angle) {
return angle * Math.PI / 180;
};
MulticopterDroneAPI.prototype._toDeg = function (angle) {
return angle * 180 / Math.PI;
};
MulticopterDroneAPI.prototype.getClimbRate = function (drone) {
return drone.worldDirection.y * drone.get3DSpeed();
};
MulticopterDroneAPI.prototype.getSpeed = function (drone) {
var direction = drone.worldDirection;
return Math.sqrt(
Math.pow(direction.x * drone.get3DSpeed(), 2)
+ Math.pow(direction.z * drone.get3DSpeed(), 2)
);
};
MulticopterDroneAPI.prototype.takeOff = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone._internal_setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
DEFAULT_TAKEOFF_ALTITUDE,
DEFAULT_SPEED
);
drone._acceleration = this.getMaxAcceleration() / this.getTakeOffFactor();
};
MulticopterDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone._internal_setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
0,
DEFAULT_SPEED
);
this._is_ready_to_fly = false;
this._is_landing = true;
};
MulticopterDroneAPI.prototype.isReadyToFly = function () {
return this._is_ready_to_fly;
};
MulticopterDroneAPI.prototype.isLanding = function () {
return this._is_landing;
};
MulticopterDroneAPI.prototype.getInitialAltitude = function () {
return this._map_dict.start_AMSL;
};
MulticopterDroneAPI.prototype.getAltitudeAbs = function (altitude) {
return altitude + this._map_dict.start_AMSL;
};
MulticopterDroneAPI.prototype.getMinHeight = function () {
return 0;
};
MulticopterDroneAPI.prototype.getMaxHeight = function () {
return 800;
};
MulticopterDroneAPI.prototype.getOnUpdateInterval = function () {
return this._flight_parameters.drone.onUpdateInterval;
};
MulticopterDroneAPI.prototype.getFlightParameters = function () {
return this._flight_parameters;
};
return MulticopterDroneAPI;
}());
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_drone_simulator_multicopterdrone.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>drone_simulator_multicopterdrone_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Multicopter Drone (API)</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1700754908.42</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1020.34636.19071.11520</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1731937140.0</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>1700754774.95</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -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>
......
......@@ -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>
......
/*jslint indent: 2, maxlen: 100*/
/*global window, rJS, domsugar, document, Blob*/
(function (window, rJS, domsugar, document, Blob) {
/*global window, rJS, domsugar, document, Blob, FixedWingDroneAPI, MulticopterDroneAPI*/
(function (window, rJS, domsugar, document, Blob, API_LIST) {
"use strict";
//Default values - TODO: get them from the drone API
var SIMULATION_SPEED = 200,
SIMULATION_TIME = 1500,
min_lat = 45.6364,
......@@ -11,25 +10,14 @@
min_lon = 14.2521,
max_lon = 14.2766,
map_height = 100,
start_AMSL = 595,
start_AMSL = 100,
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,
MAX_COMMAND_FREQUENCY = 2,
INITIAL_POSITION = {
"latitude": 45.6412,
"longitude": 14.2658,
"altitude": 15
"altitude": 0
},
NUMBER_OF_DRONES = 2,
// Non-inputs parameters
DEFAULT_SCRIPT_CONTENT =
'/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */\n' +
'/*global console, me*/\n' +
......@@ -74,7 +62,7 @@
' bearing: 94\n' +
' }\n' +
' ],\n' +
' R = 6371e3 // meters;\n' +
' R = 6371e3; // meters\n' +
'\n' +
' function to_deg(rad) {\n' +
' return rad * 180 / Math.PI;\n' +
......@@ -96,8 +84,8 @@
' bearing_rad = to_rad(e.bearing);\n' +
' relative_d = e.distance / R;\n' +
'\n' +
' lat_end = Math.asin(Math.sin(lat_start) * Math.cos(relative_d)\n' +
' + Math.cos(lat_start) * Math.sin(relative_d) * Math.cos(bearing_rad));\n' +
' lat_end = Math.asin(Math.sin(lat_start) * Math.cos(relative_d) +\n' +
' Math.cos(lat_start) * Math.sin(relative_d) * Math.cos(bearing_rad));\n' +
' lon_end = lon_start + Math.atan2(\n' +
' Math.sin(bearing_rad) * Math.sin(relative_d) * Math.cos(lat_start),\n' +
' Math.cos(relative_d) - Math.sin(lat_start) * Math.sin(lon_start));\n' +
......@@ -145,7 +133,7 @@
' me.setTargetCoordinates(\n' +
' CHECKPOINT_LIST[me.next_checkpoint].latitude,\n' +
' CHECKPOINT_LIST[me.next_checkpoint].longitude,\n' +
' ALTITUDE + ALTITUDE * me.id,\n' +
' ' + start_AMSL + ' + ALTITUDE + ALTITUDE * me.id,\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
' console.log("[DEMO] Going to Checkpoint", me.next_checkpoint);\n' +
......@@ -182,52 +170,64 @@
LOG = true,
LOG_TIME = 1662.7915426540285,
ONUPDATE_INTERVAL = 100,
DRONE_LIST = [],
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'
];
].concat(API_LIST.map(function (api) {
return api.SCRIPT_NAME;
}));
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('input[type="submit"]').click();
})
function getAPI(droneType) {
return API_LIST.find(function (api) {
return api.DRONE_TYPE === droneType;
});
}
.onEvent('submit', function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
function getContentFromParameterForm(gadget) {
return gadget.getDeclaredGadget('parameter_form')
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (input) {
gadget.runGame(input);
.push(function (content_dict) {
var key;
for (key in content_dict) {
if (content_dict.hasOwnProperty(key)) {
gadget.state[key] = content_dict[key];
}
}
});
}
//////////////////////////////////////////////////
// Game parameters
//////////////////////////////////////////////////
function renderGameParameterView(gadget) {
var api = getAPI(gadget.state.drone_type), erp5_view, form_gadget;
return gadget.declareGadget("gadget_erp5_form.html", {
scope: "parameter_form"
})
.push(function (sub_gadget) {
form_gadget = sub_gadget;
.declareMethod('render', function render() {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
erp5_view = {
"my_drone_type": {
"description": "Type of drone to simulate",
"title": "Drone Type",
"items": API_LIST.map(function (api) {
return api.DRONE_TYPE;
}),
"value": gadget.state.drone_type,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_type",
"hidden": 0,
"type": "ListField"
},
"my_simulation_speed": {
"description": "",
"title": "Simulation Speed",
"default": SIMULATION_SPEED,
"default": gadget.state.simulation_speed,
"css_class": "",
"required": 1,
"editable": 1,
......@@ -238,7 +238,7 @@
"my_simulation_time": {
"description": "Duration of the simulation (in seconds)",
"title": "Simulation Time",
"default": SIMULATION_TIME,
"default": gadget.state.simulation_time,
"css_class": "",
"required": 1,
"editable": 1,
......@@ -249,7 +249,7 @@
"my_onupdate_interval": {
"description": "Minimum interval (in milliseconds) between 2 executions of onUpdate function as well as periodicity to send telemetry to the swarm",
"title": "OnUpdate interval",
"default": ONUPDATE_INTERVAL,
"default": gadget.state.onupdate_interval,
"css_class": "",
"required": 1,
"editable": 1,
......@@ -257,127 +257,6 @@
"hidden": 0,
"type": "IntegerField"
},
"my_drone_min_speed": {
"description": "",
"title": "Drone min speed",
"default": MIN_SPEED,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_min_speed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_speed": {
"description": "",
"title": "Drone speed",
"default": DEFAULT_SPEED,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_speed",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_speed": {
"description": "",
"title": "Drone max speed",
"default": MAX_SPEED,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_speed",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_acceleration": {
"description": "",
"title": "Drone max Acceleration",
"default": MAX_ACCELERATION,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_acceleration",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
"title": "Drone max Deceleration",
"default": MAX_DECELERATION,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_deceleration",
"hidden": 0,
"type": "IntegerField"
},
"my_drone_max_roll": {
"description": "",
"title": "Drone max roll",
"default": MAX_ROLL,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_roll",
"hidden": 0,
"type": "FloatField"
},
"my_drone_min_pitch": {
"description": "",
"title": "Drone min pitch",
"default": MIN_PITCH,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_min_pitch",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_pitch": {
"description": "",
"title": "Drone max pitch",
"default": MAX_PITCH,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_pitch",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_sink_rate": {
"description": "",
"title": "Drone max sink rate",
"default": MAX_SINK_RATE,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_sink_rate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_climb_rate": {
"description": "",
"title": "Drone max climb rate",
"default": MAX_CLIMB_RATE,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_climb_rate",
"hidden": 0,
"type": "FloatField"
},
"my_drone_max_command_frequency": {
"description": "",
"title": "Drone max command frequency",
"default": MAX_COMMAND_FREQUENCY,
"css_class": "",
"required": 1,
"editable": 1,
"key": "drone_max_command_frequency",
"hidden": 0,
"type": "FloatField"
},
"my_minimum_latitud": {
"description": "",
"title": "Minimum latitude",
......@@ -480,7 +359,7 @@
"my_number_of_drones": {
"description": "",
"title": "Number of drones",
"default": NUMBER_OF_DRONES,
"default": gadget.state.number_of_drones,
"css_class": "",
"required": 1,
"editable": 1,
......@@ -488,19 +367,32 @@
"hidden": 0,
"type": "IntegerField"
},
"my_script": {
"default": DEFAULT_SCRIPT_CONTENT,
"my_drone_script": {
"description": "",
"title": "Drone script",
"default": gadget.state.drone_script,
"css_class": "",
"required": 1,
"editable": 1,
"key": "script",
"key": "drone_script",
"hidden": 0,
"type": "GadgetField",
"renderjs_extra": '{"editor": "codemirror", "maximize": true}',
"url": "gadget_editor.html",
"sandbox": "public"
"renderjs_extra": JSON.stringify({
"maximize": true,
"language": "en",
"portal_type": "Web Script",
"editor": "codemirror"
}),
"type": "GadgetField"
}
}},
};
Object.keys(api.FORM_VIEW).forEach(function (key) {
erp5_view[key] = api.FORM_VIEW[key];
});
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": erp5_view},
"_links": {
"type": {
name: ""
......@@ -510,84 +402,157 @@
form_definition: {
group_list: [[
"left",
[["my_simulation_speed"], ["my_simulation_time"], ["my_onupdate_interval"],
[["my_drone_type"], ["my_simulation_speed"], ["my_simulation_time"], ["my_onupdate_interval"],
["my_number_of_drones"], ["my_minimum_latitud"], ["my_maximum_latitud"],
["my_minimum_longitud"], ["my_maximum_longitud"],
["my_init_pos_lat"], ["my_init_pos_lon"], ["my_init_pos_alt"],
["my_map_height"]]
], [
"right",
[["my_start_AMSL"], ["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_command_frequency"]]
[["my_start_AMSL"]].concat(
Object.keys(api.FORM_VIEW).map(function (property_name) {
return [property_name];
})
)
], [
"bottom",
[["my_script"]]
[["my_drone_script"]]
]]
}
});
})
.push(function () {
return gadget.updateHeader({
page_title: 'Drone Simulator - Edit and run script',
page_icon: 'puzzle-piece'
// Attach the form to the page
domsugar(gadget.element.querySelector('div[data-gadget-scope="form_view"]'), [
form_gadget.element
]);
});
}
//////////////////////////////////////////////////
// Play
//////////////////////////////////////////////////
function renderPlayView(gadget) {
return gadget.declareGadget("gadget_erp5_form.html", {
scope: "form_view_babylonjs"
})
.push(function (sub_gadget) {
// Attach the form to the page
domsugar(gadget.element.querySelector('div[data-gadget-scope="form_view_babylonjs"]'), [
domsugar('div', {
'class': 'simulator_div'
}),
sub_gadget.element
]);
gadget.runGame();
});
}
function formToFilename(form, drone) {
return Object.keys(form).map(function (field_name) {
var key = form[field_name].key;
return key + "_" + drone[key];
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
.allowPublicAcquisition('notifyChange', function (argument_list, scope) {
return this.triggerAPIChange(scope);
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('input[type="submit"]').click();
})
.onEvent('submit', function () {
return this.getContent();
})
.declareMethod("triggerAPIChange", function (scope) {
var gadget = this,
sub_gadget;
return gadget.getDeclaredGadget(scope)
.push(function (result) {
sub_gadget = result;
return sub_gadget.getContent();
})
.push(function (result) {
if (gadget.state.drone_type !== result.drone_type) {
return gadget.changeState({
drone_type: result.drone_type
});
}
});
})
.declareJob('runGame', function runGame(options) {
.declareJob('runGame', function runGame() {
var gadget = this, i,
fragment = gadget.element.querySelector('.simulator_div'),
game_parameters_json;
fragment = domsugar(gadget.element.querySelector('.simulator_div'),
[domsugar('div')]).firstElementChild;
DRONE_LIST = [];
for (i = 0; i < options.number_of_drones; i += 1) {
DRONE_LIST[i] = {"id": i, "type": "FixedWingDroneAPI",
"script_content": options.script};
[domsugar('div')]).firstElementChild,
game_parameters_json,
drone_list = [],
api = getAPI(gadget.state.drone_type),
drone_parameter_list = Object.keys(api.FORM_VIEW);
for (i = 0; i < gadget.state.number_of_drones; i += 1) {
drone_list[i] = {"id": i, "type": api.name,
"script_content": gadget.state.drone_script};
}
game_parameters_json = {
"drone": {
"maxAcceleration": parseFloat(options.drone_max_acceleration),
"maxDeceleration": parseInt(options.drone_max_deceleration, 10),
"minSpeed": parseInt(options.drone_min_speed, 10),
"speed": parseFloat(options.drone_speed),
"maxSpeed": parseInt(options.drone_max_speed, 10),
"maxRoll": parseFloat(options.drone_max_roll),
"minPitchAngle": parseFloat(options.drone_min_pitch),
"maxPitchAngle": parseFloat(options.drone_max_pitch),
"maxSinkRate": parseFloat(options.drone_max_sink_rate),
"maxClimbRate": parseFloat(options.drone_max_climb_rate),
"maxCommandFrequency": parseFloat(options.drone_max_command_frequency),
"onUpdateInterval": parseInt(options.onupdate_interval, 10)
"onUpdateInterval": parseInt(gadget.state.onupdate_interval, 10),
"list": drone_list
},
"gameTime": parseInt(options.simulation_time, 10),
"simulation_speed": parseInt(options.simulation_speed, 10),
"gameTime": parseInt(gadget.state.simulation_time, 10),
"simulation_speed": parseInt(gadget.state.simulation_speed, 10),
"latency": {
"information": 0,
"communication": 0
},
"map": {
"min_lat": parseFloat(options.min_lat),
"max_lat": parseFloat(options.max_lat),
"min_lon": parseFloat(options.min_lon),
"max_lon": parseFloat(options.max_lon),
"height": parseInt(options.map_height, 10),
"start_AMSL": parseFloat(options.start_AMSL)
"min_lat": parseFloat(gadget.state.min_lat),
"max_lat": parseFloat(gadget.state.max_lat),
"min_lon": parseFloat(gadget.state.min_lon),
"max_lon": parseFloat(gadget.state.max_lon),
"height": parseInt(gadget.state.map_height, 10),
"start_AMSL": parseFloat(gadget.state.start_AMSL)
},
"initialPosition": {
"longitude": parseFloat(options.init_pos_lon),
"latitude": parseFloat(options.init_pos_lat),
"altitude": parseFloat(options.init_pos_alt)
"longitude": parseFloat(gadget.state.init_pos_lon),
"latitude": parseFloat(gadget.state.init_pos_lat),
"altitude": parseFloat(gadget.state.init_pos_alt)
},
"draw_flight_path": DRAW,
"temp_flight_path": true,
"log_drone_flight": LOG,
"log_interval_time": LOG_TIME,
"droneList": DRONE_LIST
"log_interval_time": LOG_TIME
};
drone_parameter_list.forEach(function (parameter) {
var field = api.FORM_VIEW[parameter];
switch (field.type) {
case 'IntegerField':
game_parameters_json.drone[field.key] = parseInt(gadget.state[field.key], 10);
break;
case 'FloatField':
game_parameters_json.drone[field.key] = parseFloat(gadget.state[field.key]);
break;
default:
throw new Error("Unhandled field type");
}
});
return gadget.declareGadget("babylonjs.gadget.html",
{element: fragment, scope: 'simulator'})
.push(function () {
......@@ -607,8 +572,7 @@
"type": "GadgetField",
"url": "babylonjs.gadget.html",
"sandbox": "public",
"renderjs_extra": '{"autorun": false, "width": ' + WIDTH + ', ' +
'"height": ' + HEIGHT + ', ' +
"renderjs_extra": '{"autorun": false, ' +
'"logic_file_list": ' + JSON.stringify(LOGIC_FILE_LIST) + ', ' +
'"game_parameters": ' + JSON.stringify(game_parameters_json) +
'}'
......@@ -643,18 +607,9 @@
blob = new Blob([log_content], {type: 'text/plain'});
a = domsugar('a', {
text: 'Download Simulation LOG ' + i,
download: 'simulation_log_' + i
+ '_speed_' + game_parameters_json.drone.speed
+ '_min-speed_' + game_parameters_json.drone.minSpeed
+ '_max-speed_' + game_parameters_json.drone.maxSpeed
+ '_max-accel_' + game_parameters_json.drone.maxAcceleration
+ '_max-decel_' + game_parameters_json.drone.maxDeceleration
+ '_max-roll_' + game_parameters_json.drone.maxRoll
+ '_min-pitch_' + game_parameters_json.drone.minPitchAngle
+ '_max-pitch_' + game_parameters_json.drone.maxPitchAngle
+ '_max-sink_' + game_parameters_json.drone.maxSinkRate
+ '_max-climb_' + game_parameters_json.drone.maxClimbRate
+ '.txt',
download: ['simulation_log_' + i].concat(
formToFilename(api.FORM_VIEW, game_parameters_json.drone)
).join("_") + ".txt",
href: window.URL.createObjectURL(blob)
});
log = domsugar('textarea', { value: log_content, id: 'log_result_' + i });
......@@ -670,6 +625,54 @@
return gadget.notifySubmitted({message: "Error: " + error.message,
status: 'error'});
});
})
.setState({
drone_type: API_LIST[0].DRONE_TYPE,
drone_script: DEFAULT_SCRIPT_CONTENT,
number_of_drones: NUMBER_OF_DRONES,
onupdate_interval: ONUPDATE_INTERVAL,
simulation_time: SIMULATION_TIME,
simulation_speed: SIMULATION_SPEED,
min_lat: min_lat,
max_lat: max_lat,
min_lon: min_lon,
max_lon: max_lon,
height: map_height,
start_AMSL: start_AMSL,
longitude: INITIAL_POSITION.longitude,
latitude: INITIAL_POSITION.latitude,
altitude: INITIAL_POSITION.altitude
})
.declareMethod('render', function render() {
var gadget = this;
return renderGameParameterView(gadget)
.push(function () {
return gadget.updateHeader({
page_title: 'Drone Simulator - Edit and run script',
page_icon: 'puzzle-piece'
});
});
})
.onStateChange(function (modification_dict) {
var gadget = this;
if (modification_dict.hasOwnProperty('drone_type')) {
return getContentFromParameterForm(this)
.push(function () {
return renderGameParameterView(gadget);
});
}
})
.declareMethod('getContent', function () {
var gadget = this;
return getContentFromParameterForm(this)
.push(function () {
return renderPlayView(gadget);
});
}, {mutex: 'changestate'});
}(window, rJS, domsugar, document, Blob));
\ No newline at end of file
}(window, rJS, domsugar, document, Blob, [MulticopterDroneAPI, FixedWingDroneAPI]));
\ No newline at end of file
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1020.29234.48115.42939</string> </value>
<value> <string>1020.49358.42946.36915</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1730734363.63</float>
<float>1731940826.8</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