Add waypoints to map, follow mode and show battery life
Esse commit está contido em:
+95
-18
@@ -69,16 +69,19 @@ body{
|
|||||||
<div id='data'>
|
<div id='data'>
|
||||||
<div id="phone-position">
|
<div id="phone-position">
|
||||||
Phone:
|
Phone:
|
||||||
<span class='lat'></span>,
|
<span class='lat'>0</span>,
|
||||||
<span class='lon'></span>
|
<span class='lon'>0</span>
|
||||||
(+/-<span class='accuracy'></span>m)
|
(+/-<span class='accuracy'>0</span>m)
|
||||||
</div>
|
</div>
|
||||||
<div id="drone-position">
|
<div id="drone-position">
|
||||||
Drone:
|
Drone:
|
||||||
<span class='lat'></span>,
|
<span class='lat'>0</span>,
|
||||||
<span class='lon'></span>
|
<span class='lon'>0</span>
|
||||||
<p>Distance:
|
<p>Distance:
|
||||||
<span class='distance'></span>
|
<span class='distance'>0</span>
|
||||||
|
</p>
|
||||||
|
<p>Battery:
|
||||||
|
<span class='battery'>0</span>%
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -91,8 +94,12 @@ body{
|
|||||||
<script src="/socket.io/socket.io.js"></script>
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var socket = io.connect('/');
|
var socket = io.connect('/');
|
||||||
var lat, lon, map, laptop, drone, phone, phonePath;
|
var lat, lon, map, laptop, drone, phone, phonePath, waypointPath, dronePath, startPosition;
|
||||||
var stop = true;
|
var targetLat, targetLon;
|
||||||
|
var waypointMarkers = [];
|
||||||
|
var activeWaypoints = [];
|
||||||
|
var waypoints = [];
|
||||||
|
var follow = false;
|
||||||
|
|
||||||
var phoneIcon = L.icon({
|
var phoneIcon = L.icon({
|
||||||
iconUrl: 'images/iphone.png'
|
iconUrl: 'images/iphone.png'
|
||||||
@@ -120,39 +127,106 @@ body{
|
|||||||
map.addLayer(googleLayer);
|
map.addLayer(googleLayer);
|
||||||
|
|
||||||
laptop = L.marker([lat, lon], {icon: laptopIcon}).addTo(map)
|
laptop = L.marker([lat, lon], {icon: laptopIcon}).addTo(map)
|
||||||
|
|
||||||
|
map.on('click', function(e) {
|
||||||
|
waypointMarkers.push(L.marker(e.latlng).addTo(map))
|
||||||
|
waypoints.push([e.latlng.lat, e.latlng.lng])
|
||||||
|
if(waypointPath == undefined){
|
||||||
|
waypointPath = L.polyline(waypoints, {color: 'blue'}).addTo(map);
|
||||||
|
} else {
|
||||||
|
waypointPath.setLatLngs(waypoints)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultMap(err){
|
function defaultMap(err){
|
||||||
console.log(err)
|
console.log(err)
|
||||||
initMap({coords: { latitude: 51, longitude: 2 }})
|
initMap({coords: { latitude: 51, longitude: 2 }})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearWaypoints(){
|
||||||
|
waypoints = []
|
||||||
|
map.removeLayer(waypointPath)
|
||||||
|
waypointPath = undefined
|
||||||
|
$.each(waypointMarkers, function(i,m){map.removeLayer(m)})
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCurrentTarget(lat, lon){
|
||||||
|
targetLat = lat
|
||||||
|
targetLon = lon
|
||||||
|
socket.emit('go', {lat: targetLat, lon: targetLon})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearCurrentTarget(){
|
||||||
|
targetLat = undefined
|
||||||
|
targetLon = undefined
|
||||||
|
socket.emit('stop')
|
||||||
|
}
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
$('#takeoff').click(function(){
|
$('#takeoff').click(function(){
|
||||||
|
follow = false
|
||||||
socket.emit('takeoff')
|
socket.emit('takeoff')
|
||||||
|
if (drone != null){
|
||||||
|
startPosition = [drone._latlng.lat, drone._latlng.lng]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
$('#land').click(function(){
|
$('#land').click(function(){
|
||||||
|
follow = false
|
||||||
socket.emit('land')
|
socket.emit('land')
|
||||||
|
startPosition = []
|
||||||
})
|
})
|
||||||
$('#move').click(function(){
|
$('#reset').click(function(){
|
||||||
stop = false;
|
socket.emit('reset')
|
||||||
})
|
})
|
||||||
$('#stop').click(function(){
|
$('#stop').click(function(){
|
||||||
stop = true;
|
follow = false
|
||||||
|
clearCurrentTarget()
|
||||||
|
})
|
||||||
|
$('#clear').click(function(){
|
||||||
|
follow = false
|
||||||
|
clearWaypoints()
|
||||||
|
})
|
||||||
|
$('#home').click(function(){
|
||||||
|
follow = false
|
||||||
|
activeWaypoints = [startPosition[0], startPosition[1]]
|
||||||
|
setCurrentTarget(startPosition[0], startPosition[1])
|
||||||
|
})
|
||||||
|
$('#go').click(function(){
|
||||||
|
follow = false
|
||||||
|
if(waypoints.length > 0){
|
||||||
|
activeWaypoints = waypoints.slice(0);
|
||||||
|
// go to next waypoint
|
||||||
|
setCurrentTarget(activeWaypoints[0][0], activeWaypoints[0][1])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$('#follow').click(function(){
|
||||||
|
follow = true
|
||||||
|
})
|
||||||
|
$('#manual').click(function(){
|
||||||
|
// control via xbox
|
||||||
|
follow = false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('connect', function(){
|
socket.on('connect', function(){
|
||||||
|
socket.on('waypointReached', function(data){
|
||||||
|
activeWaypoints.shift()
|
||||||
console.log('connected')
|
if(activeWaypoints.length > 0){
|
||||||
|
// go to next waypoint
|
||||||
socket.on('position', function(data){
|
setCurrentTarget(activeWaypoints[0][0], activeWaypoints[0][1])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
socket.on('drone', function(data){
|
||||||
if(data.lat != undefined){
|
if(data.lat != undefined){
|
||||||
if (drone == null){
|
if (drone == null){
|
||||||
drone = L.marker([data.lat, data.lon], {icon: droneIcon}).addTo(map)
|
drone = L.marker([data.lat, data.lon], {icon: droneIcon}).addTo(map)
|
||||||
|
dronePath = L.polyline([[data.lat, data.lon]], {color: 'green'}).addTo(map);
|
||||||
|
} else{
|
||||||
|
drone.setLatLng([data.lat, data.lon])
|
||||||
|
dronePath.addLatLng([data.lat, data.lon])
|
||||||
}
|
}
|
||||||
drone.setLatLng([data.lat, data.lon])
|
$('#drone-position .battery').text(data.battery)
|
||||||
$('#drone-position .lat').text(data.lat)
|
$('#drone-position .lat').text(data.lat)
|
||||||
$('#drone-position .lon').text(data.lon)
|
$('#drone-position .lon').text(data.lon)
|
||||||
$('#drone-position .distance').text(data.distance)
|
$('#drone-position .distance').text(data.distance)
|
||||||
@@ -171,6 +245,9 @@ body{
|
|||||||
phone.setLatLng([data.lat, data.lon])
|
phone.setLatLng([data.lat, data.lon])
|
||||||
phonePath.addLatLng([data.lat, data.lon])
|
phonePath.addLatLng([data.lat, data.lon])
|
||||||
}
|
}
|
||||||
|
if(follow){
|
||||||
|
setCurrentTarget(data.lat, data.lon)
|
||||||
|
}
|
||||||
$('#phone-position .lat').text(data.lat)
|
$('#phone-position .lat').text(data.lat)
|
||||||
$('#phone-position .lon').text(data.lon)
|
$('#phone-position .lon').text(data.lon)
|
||||||
$('#phone-position .accuracy').text(data.accuracy)
|
$('#phone-position .accuracy').text(data.accuracy)
|
||||||
|
|||||||
+19
-12
@@ -29,29 +29,26 @@ io.sockets.on('connection', function(socket) {
|
|||||||
socket.on('land', function(data){
|
socket.on('land', function(data){
|
||||||
console.log('land', data)
|
console.log('land', data)
|
||||||
client.land()
|
client.land()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
socket.on('reset', function(data){
|
||||||
|
console.log('reset', data)
|
||||||
|
client.disableEmergency()
|
||||||
|
})
|
||||||
socket.on('phone', function(data){
|
socket.on('phone', function(data){
|
||||||
console.log('phone', data)
|
console.log('phone', data)
|
||||||
targetLat = data.lat
|
targetLat = data.lat
|
||||||
targetLon = data.lon
|
targetLon = data.lon
|
||||||
phoneAccuracy = data.accuracy
|
phoneAccuracy = data.accuracy
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('stop', function(data){
|
socket.on('stop', function(data){
|
||||||
console.log('stop', data)
|
stop()
|
||||||
targetYaw = null
|
|
||||||
targetLat = null
|
|
||||||
targetLon = null
|
|
||||||
client.stop()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
io.sockets.emit('position', {lat: currentLat, lon: currentLon, distance: currentDistance})
|
io.sockets.emit('drone', {lat: currentLat, lon: currentLon, yaw: currentYaw, distance: currentDistance, battery: battery})
|
||||||
io.sockets.emit('drone', {lat: currentLat, lon: currentLon, yaw: currentYaw})
|
|
||||||
io.sockets.emit('phone', {lat: targetLat, lon: targetLon, accuracy: phoneAccuracy})
|
io.sockets.emit('phone', {lat: targetLat, lon: targetLon, accuracy: phoneAccuracy})
|
||||||
},1000)
|
},1000)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var arDrone = require('ar-drone');
|
var arDrone = require('ar-drone');
|
||||||
@@ -64,10 +61,19 @@ var client = arDrone.createClient();
|
|||||||
client.config('general:navdata_demo', 'FALSE');
|
client.config('general:navdata_demo', 'FALSE');
|
||||||
|
|
||||||
var targetLat, targetLon, targetYaw, cyaw, currentLat, currentLon,currentDistance, currentYaw, phoneAccuracy;
|
var targetLat, targetLon, targetYaw, cyaw, currentLat, currentLon,currentDistance, currentYaw, phoneAccuracy;
|
||||||
|
var battery = 0;
|
||||||
|
|
||||||
|
var stop = function(){
|
||||||
|
console.log('stop', data)
|
||||||
|
targetYaw = null
|
||||||
|
targetLat = null
|
||||||
|
targetLon = null
|
||||||
|
client.stop()
|
||||||
|
}
|
||||||
|
|
||||||
var handleNavData = function(data){
|
var handleNavData = function(data){
|
||||||
if ( data.demo == null || data.gps == null) return;
|
if ( data.demo == null || data.gps == null) return;
|
||||||
|
battery = data.demo.batteryPercentage
|
||||||
currentLat = data.gps.latitude
|
currentLat = data.gps.latitude
|
||||||
currentLon = data.gps.longitude
|
currentLon = data.gps.longitude
|
||||||
|
|
||||||
@@ -97,8 +103,9 @@ var handleNavData = function(data){
|
|||||||
client.front(0.05)
|
client.front(0.05)
|
||||||
} else {
|
} else {
|
||||||
targetYaw = null
|
targetYaw = null
|
||||||
client.stop()
|
io.sockets.emit('waypointReached', {lat: targetLat, lon: targetLon})
|
||||||
console.log('Reached ', targetLat, targetLon)
|
console.log('Reached ', targetLat, targetLon)
|
||||||
|
stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário