-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengineTestScript.js
More file actions
128 lines (104 loc) · 3.26 KB
/
Copy pathengineTestScript.js
File metadata and controls
128 lines (104 loc) · 3.26 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
document.addEventListener('DOMContentLoaded', function() {
var startingWeight = 2
var endWeight = 1
var totalRecordedPoints = 13
var canvas = document.getElementById("myChart")
var force = [2.0, 7.8, 23.5, 37.3, 42.2, 40.2, 34.3, 27.5, 19.6, 13.7, 7.8, 3.9, 1.0];
var recordedTimes = [0, 0.099, 0.199, 0.298, 0.397, 0.496 ,0.596 ,0.695 ,0.794, 0.894, 0.993, 1.092, 1.191]
// These will be gathered from the data obtained from the sensor
var someLables = [];
for (var i = 0; i < totalRecordedPoints; i++) {
someLables.push(i);
}
var deltaWeight = startingWeight - endWeight
var sumOfForce = 0;
for(var num of force) {
sumOfForce += num;
}
console.log(sumOfForce)
var currentThrust;
var thrustGraphArray = [];
var weightArray = [];
var currentWeight = null;
// Gives how much percentage of the total force is the current data point
function givePercentageOfTotal(current, total) {
var percentage = current / total;
return percentage;
}
// Converts the previous percentage to estimated current weight
function convertPercentToCurrentWeight(currentWeight, percentage) {
var weight = currentWeight - percentage * deltaWeight;
return weight;
}
// Estimates the thurst graph points (Blue graph)
function convertWeigthAndYIntoThrustGraph(weight, pointY) {
var approximateThrust;
approximateThrust = pointY - weight;
return approximateThrust;
}
function calculateImpulseFromThrust(thrustPoint, deltaTime) {
var impulse = thrustPoint * deltaTime
return impulse
}
//Creating the estimated weight array (Yellow graph)
for (var y of force) {
if (currentWeight == null) {
currentWeight = startingWeight;
weightArray.push(currentWeight);
} else {
currentWeight = convertPercentToCurrentWeight(currentWeight, givePercentageOfTotal(y, sumOfForce));
weightArray.push(currentWeight);
}
}
console.log(weightArray);
// Estimating thrust graph (Blue)
for (var i = 0; i < totalRecordedPoints; i++) {
thrustGraphArray.push(convertWeigthAndYIntoThrustGraph(weightArray[i], force[i]));
}
console.log(thrustGraphArray);
//Making impulse array
var impulseGraphArray = []
var totalImpulse = 0;
for (var i = 0; i < recordedTimes.length - 1; i++) {
var currentImpulse = calculateImpulseFromThrust(thrustGraphArray[i], recordedTimes[i+1]-recordedTimes[i])
impulseGraphArray.push(currentImpulse);
totalImpulse += currentImpulse
}
console.log(impulseGraphArray)
console.log(totalImpulse)
// Drawing the chart
var chart = new Chart(canvas, {
type: 'line',
data: {
labels: recordedTimes,
datasets: [
{
label: 'Thrust Force (N)',
data: thrustGraphArray,
borderColor: 'blue',
fill: false
},
{
label: 'Force (N)',
data: force,
borderColor: 'red',
fill: false
},
{
label: 'Estimated weight of rocket (N)',
data: weightArray,
borderColor: 'yellow',
fill: false
},
{
label: 'Estimated impulse (N.s)',
data: impulseGraphArray,
borderColor: 'purple'
}
]
},
options: {
responsive: true
}
});
});