-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
99 lines (86 loc) · 3.55 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>
<head>
<title>Quadcopter</title>
<style>
body{margin:0;}
canvas{ width:100%; height: 100%;}
#data{color: white; position: absolute;}
</style>
</head>
<body>
<p id="data">
Vx: <span id="vx"></span><br>
Vy: <span id="vy"></span><br>
Vz: <span id="vz"></span><br>
<br>
x: <span id="px"></span><br>
y: <span id="py"></span><br>
z: <span id="pz"></span><br>
<br>
rot x: <span id="rotx"></span><br>
rot y: <span id="roty"></span><br>
rot z: <span id="rotz"></span><br>
<br>
thrust: <span id="thrust"></span><br>
<br>
torqueX: <span id="torqueX"></span><br>
torqueY: <span id="torqueY"></span><br>
torqueZ: <span id="torqueZ"></span><br>
<br>
Desired height: <span id="desH"></span><br>
Desired pitch: <span id="desP"></span><br>
Desired yaw: <span id="desY"></span><br>
Desired roll: <span id="desR"></span><br>
</p>
<script src="https://ajax.googleapis.com/ajax/libs/threejs/r69/three.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/1.2.0/math.min.js"></script>
<script src="scripts/mathFunctions.js"></script>
<script src="scripts/geometry.js"></script>
<script src="scripts/constants.js"></script>
<script src="scripts/thrustPD.js"></script>
<script src="scripts/positionCalculation.js"></script>
<script src="scripts/flightControl.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var copter = new Copter();
scene.add(copter.object);
// camera.up.set( 0, 0, 1 );
camera.position.x -= 5;
camera.position.z = 5;
copter.object.position.z = copter.positionInertial._data[2][0];
camera.up.set( 0, 0, 1 );
camera.lookAt(new THREE.Vector3(0,0,0));
var clock = new THREE.Clock()
var render = function () {
delta = clock.getDelta();
setTimeout(function() {requestAnimationFrame( render );}, 1000/30);
// Update velocities and rotations
var pos = copter.update(0.01);
// Display velocities on screen
document.getElementById('vx').innerHTML = pos[10];
document.getElementById('vy').innerHTML = pos[11];
document.getElementById('vz').innerHTML = pos[12];
document.getElementById('px').innerHTML = copter.object.position.x;
document.getElementById('py').innerHTML = copter.object.position.y;
document.getElementById('pz').innerHTML = copter.object.position.z;
document.getElementById('rotx').innerHTML = copter.object.rotation.x * 57.296; // <-- 180/pi
document.getElementById('roty').innerHTML = copter.object.rotation.y * 57.296; // <-- 180/pi
document.getElementById('rotz').innerHTML = copter.object.rotation.z * 57.296; // <-- 180/pi
document.getElementById('thrust').innerHTML = pos[6];
document.getElementById('torqueX').innerHTML = pos[7];
document.getElementById('torqueY').innerHTML = pos[8];
document.getElementById('torqueZ').innerHTML = pos[9];
document.getElementById('desH').innerHTML = copter.posMat._data[2][0];
document.getElementById('desP').innerHTML = copter.angMat._data[1][0];
document.getElementById('desY').innerHTML = copter.angMat._data[2][0];
document.getElementById('desR').innerHTML = copter.angMat._data[0][0];
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>