Skip to content

Commit

Permalink
Merge remote-tracking branch 'vliedel/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anne van Rossum committed Mar 13, 2013
2 parents cb34c2b + 7310c3a commit 3aa2936
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 119 deletions.
86 changes: 66 additions & 20 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ app.get('/drone', function (request,response) {
response.send(droneJSON);
});

app.get('/field', function (request,response) {
var fieldJSON = JSON.stringify(commandState);
response.send(fieldJSON);
});

var guiPort = 8080;

app.listen(process.argv[2]||guiPort);
Expand All @@ -84,9 +89,9 @@ function droneparameter(parameter, value) {

function getCommand() {
var command = new Array();
command.message_type = getvalue(commandState, "message_type");
command.message_type = getvalue(commandState, "type");
command.version = getvalue(commandState, "version");
command.timestamp=getvalue(commandState, "timestamp");
command.timestamp=getvalue(commandState, "time_stamp");
command.uav_id=getvalue(commandState, "uav_id");
command.message_id=getvalue(commandState, "message_id");
command.min_height=getvalue(commandState, "min_height");
Expand All @@ -109,24 +114,46 @@ function getCommand() {

function initialize() {
commandState = [];
commandState.push(new droneparameter("message_type","cmd"));
commandState.push(new droneparameter("type","cmd"));
commandState.push(new droneparameter("version",1));
commandState.push(new droneparameter("timestamp","2013-02-06T13:37:00.0000Z"));
commandState.push(new droneparameter("time_stamp","2013-02-06T13:37:00.0000Z"));
commandState.push(new droneparameter("uav_id",10));
commandState.push(new droneparameter("message_id",1));
commandState.push(new droneparameter("min_height",50));
commandState.push(new droneparameter("max_height",100));
commandState.push(new droneparameter("area_min_x",9000));
commandState.push(new droneparameter("area_min_y",9500));
commandState.push(new droneparameter("area_min_x",594624.0 + 1000));
commandState.push(new droneparameter("area_min_y",5760490.0 + 500));
commandState.push(new droneparameter("area_dx",1000));
commandState.push(new droneparameter("area_dy",3000));
commandState.push(new droneparameter("area_rotation",0));
commandState.push(new droneparameter("land_x",9050));
commandState.push(new droneparameter("land_y",9550));
commandState.push(new droneparameter("land_x",594624.0 + 1050));
commandState.push(new droneparameter("land_y",5760490.0 + 550));
commandState.push(new droneparameter("land_heading",4.7124));
commandState.push(new droneparameter("turn",true));
commandState.push(new droneparameter("auto_pilot_mode",0));
commandState.push(new droneparameter("enable_planner",1));

// Add lat/long versions
var x0 = getvalue(commandState, "area_min_x");
var y0 = getvalue(commandState, "area_min_y");
var dx = getvalue(commandState, "area_dx");
var dy = getvalue(commandState, "area_dy");
var gps = utmtogps(y0, x0, 31);
commandState.push(new droneparameter("area_lat_0",gps.latitude));
commandState.push(new droneparameter("area_long_0",gps.longitude));

gps = utmtogps(y0, x0+dx, 31);
commandState.push(new droneparameter("area_lat_1",gps.latitude));
commandState.push(new droneparameter("area_long_1",gps.longitude));

gps = utmtogps(y0+dy, x0+dx, 31);
commandState.push(new droneparameter("area_lat_2",gps.latitude));
commandState.push(new droneparameter("area_long_2",gps.longitude));

gps = utmtogps(y0+dy, x0, 31);
commandState.push(new droneparameter("area_lat_3",gps.latitude));
commandState.push(new droneparameter("area_long_3",gps.longitude));

};

function droneExists(uav_id) {
Expand All @@ -150,19 +177,38 @@ function newConnectionHandler(socket){
// Whenever a connection sends us an object...
socket.on('data', function(data){
// Output the question property of the client's message to the console
console.log("UAV state: " + data.state);
console.log("Battery level: " + data.battery_left);
console.log("Check " + drones.length + " existing drones");
if (!droneExists(data.uav_id)) {
drones.push(data);
}
var drone = getDrone(data.uav_id);
drone = data;
console.log("message_type: " + data.message_type);
if (data.message_type == "pos") {
console.log("UAV state: " + data.state);
console.log("Battery level: " + data.battery_left);
console.log("Check " + drones.length + " existing drones");
if (!droneExists(data.uav_id)) {
drones.push(data);
}
var index = 0;
for (var i = 0; i < drones.length; i++) {
if (drones[i].uav_id == data.uav_id)
index = i;
}
drones[index] = data;

var gps = utmtogps(drone.uav_y, drone.uav_x, 31);
console.log(gps);
drone.uav_x = gps.latitude;
drone.uav_y = gps.longitude;
var gps = utmtogps(drones[index].uav_y, drones[index].uav_x, 31);
console.log(gps);
drones[index].uav_x = gps.latitude;
drones[index].uav_y = gps.longitude;

gps = utmtogps(drones[index].dy1, drones[index].dx1, 31);
drones[index].dx1 = gps.latitude;
drones[index].dy1 = gps.longitude;

gps = utmtogps(drones[index].dy2, drones[index].dx2, 31);
drones[index].dx2 = gps.latitude;
drones[index].dy2 = gps.longitude;

gps = utmtogps(drones[index].dy3, drones[index].dx3, 31);
drones[index].dx3 = gps.latitude;
drones[index].dy3 = gps.longitude;
}

// Wait 250ms, then write an answer to the client's socket
setTimeout(function(){
Expand Down
9 changes: 0 additions & 9 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,12 @@ <h1>UAV Swarm Operator Console</h1>
<tr><th>Parameter</th><th>Value</th></tr>
</thead>
<tbody data-bind="foreach: droneparameters">
<!-- <tr style="cursor-pointer;" data-bind="event: {mouseover: hovered, mouseleave: unhovered},
click: $root.goToUAV" class=""> -->
<td data-bind="text: parameter"></td>
<td data-bind="text: value"></td>
</tr>
</tbody>
</table>

<!--
<button data-bind="click: abortMission, enable: chosenUAVId">Abort Mission</button>
<button data-bind="click: startLanding, enable: chosenUAVId">Land!</button>
-->
<!-- only over API
<button data-bind="click: addUAV">Add UAV</button>
-->
</div>

</div>
Expand Down
Loading

0 comments on commit 3aa2936

Please sign in to comment.