mirror of
https://github.com/CopterExpress/clover.git
synced 2026-05-26 21:19:35 +00:00
Add simple experimental web gcs
This commit is contained in:
29
clever/www/gcs.html
Normal file
29
clever/www/gcs.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Disconnected</title>
|
||||
<script src="js/roslib.js"></script>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
.dash {
|
||||
font-size: 30px;
|
||||
text-align: center;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
line-height: 150%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="dash">
|
||||
<div class="mode"> </div>
|
||||
<div class="battery"> </div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="js/gcs.js"></script>
|
||||
</html>
|
||||
69
clever/www/js/gcs.js
Normal file
69
clever/www/js/gcs.js
Normal file
@@ -0,0 +1,69 @@
|
||||
var body = document.querySelector('body');
|
||||
var titleEl = document.querySelector('title');
|
||||
var modeEl = document.querySelector('.mode');
|
||||
var batteryEl = document.querySelector('.battery');
|
||||
|
||||
var url = 'ws://' + location.host + ':9090';
|
||||
var ros = new ROSLIB.Ros({ url: url });
|
||||
|
||||
function speak(txt) {
|
||||
var utterance = new SpeechSynthesisUtterance(txt);
|
||||
window.speechSynthesis.speak(utterance);
|
||||
}
|
||||
|
||||
ros.on('connection', function () {
|
||||
body.classList.add('connected');
|
||||
titleEl.innerText = 'Connected';
|
||||
});
|
||||
|
||||
ros.on('close', function () {
|
||||
titleEl.innerText = 'Disconnected';
|
||||
modeEl.innerHTML = '';
|
||||
body.classList.remove('connected');
|
||||
setTimeout(function() {
|
||||
titleEl.innerText = 'Reconnecting';
|
||||
ros.connect(url);
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
var fcuState = {};
|
||||
|
||||
new ROSLIB.Topic({
|
||||
ros: ros,
|
||||
name: '/mavros/state',
|
||||
messageType: 'mavros_msgs/State'
|
||||
}).subscribe(function(msg) {
|
||||
modeEl.innerHTML = msg.mode;
|
||||
if (fcuState.mode != msg.mode) {
|
||||
// mode changed
|
||||
speak(msg.mode + ' flight mode');
|
||||
}
|
||||
fcuState = msg;
|
||||
});
|
||||
|
||||
new ROSLIB.Topic({
|
||||
ros: ros,
|
||||
name: '/mavros/statustext/recv',
|
||||
messageType: 'mavros_msgs/StatusText'
|
||||
}).subscribe(function(message) {
|
||||
var BLACKLIST = [];
|
||||
if (message.severity <= 4) {
|
||||
if (BLACKLIST.some(function(e) {
|
||||
return message.text.indexOf(e) != -1;
|
||||
})) {
|
||||
console.log('Filtered out message ' + message.text);
|
||||
return;
|
||||
}
|
||||
speak(message.text);
|
||||
}
|
||||
});
|
||||
|
||||
new ROSLIB.Topic({
|
||||
ros: ros,
|
||||
name: '/mavros/battery',
|
||||
messageType: 'sensor_msgs/BatteryState',
|
||||
throttle_rate: 5000
|
||||
}).subscribe(function(message) {
|
||||
var LOW_BATTERY = 3.8;
|
||||
batteryEl.innerHTML = (message.cell_voltage[0].toFixed(2) + ' V') || '';
|
||||
});
|
||||
Reference in New Issue
Block a user