Commit 6f4d5ccc authored by Jake Read's avatar Jake Read

controller complete save one bug, move to testing

parent ceeff7a9
......@@ -13,6 +13,10 @@ So, first task is getting the embedded code up to competency. Compexity will liv
Then, steps / mm land, zeroing, etc, will live in JS. As will load cell calibration, and plotting, etc. I can bottle each of those low level commands in JS promises, making 'running' the machine big async codes. This should be easy-ish, let's see.
Have this all together, now just need to re-calibrate the load cell and debug some loadcell-not-ready errors that the embedded code occasionally throws.
![controller](/images/2020-07-11_dex-tools.png)
## Install
``npm install express``
......
......@@ -12,6 +12,8 @@ Copyright is retained and must be preserved. The work is provided as is;
no warranty is provided, and users accept all liability.
*/
import LineChart from "./utes/lineChart.js"
export default function DEXUI(){
// the machine object,
let dex = null
......@@ -172,7 +174,7 @@ export default function DEXUI(){
// testing
// test-by
let testStep = $('<input type="text" value="0.01">').addClass('inputwrap').get(0)
setPosition(incBy, 50, ypos += yinc + 10)
setPosition(testStep, 50, ypos += yinc + 10)
// start / stop testing
let testButton = $('<div>').addClass('button').get(0)
setPosition(testButton, 50, ypos += yinc)
......@@ -180,21 +182,95 @@ export default function DEXUI(){
testButton.update = (state) => {
if(state){
testing = true
$(testButton).text('disable motor')
$(testButton).css('background-color', '#b7f7c3')
$(testButton).text('stop testing')
$(testButton).css('background-color', '#f7bbb7')
} else {
testing = false
$(testButton).text('enable motor')
$(testButton).css('background-color', '#f7bbb7')
$(testButton).text('start testing')
$(testButton).css('background-color', '#b7f7c3')
}
}
testButton.update(testing)
$(testButton).click((evt) => {
if(testing){
// start testing
// stop
testButton.update(false)
} else {
// stop testing
runTest()
}
})
// util
let stringDate = () => {
let now = new Date()
return `${now.getFullYear()}-${now.getMonth()}-${now.getDate()}_${now.getHours()}-${now.getMinutes()}`
}
// testing
let testData = []
let runTest = async () => {
if(isWaiting()) return
position = 0
let startTime = performance.now()
testData = []
let drawData = []
testButton.update(true)
waiting()
while(testing){
try {
let time = (performance.now() - startTime) / 1000
// read 1st, then move,
let reading = await dex.readLoadcell()
loadDisplay.update(reading)
// store it, time, extension, load
testData.push([time, position, reading])
drawData.push([position, reading])
// and now,
let increment = await dex.step(testStep.value)
posDisplay.update(position += increment)
chart.draw(drawData)
} catch (err) {
console.error(err)
testButton.update(false)
}
}
clear()
}
// and finally, the doodling
let chart = new LineChart()
setPosition(chart.de, 220, 50)
// read request
let saveReq = $('<div>').addClass('button').get(0)
setPosition(saveReq, 50, ypos += yinc)
$(saveReq).text('save data')
$(saveReq).click((evt) => {
console.log()
dish(testData, 'csv', `${stringDate()}_dextest`)
})
let dish = (obj, format, name) => {
// serialize the thing
let url = null
if(format == 'json'){
url = URL.createObjectURL(new Blob([JSON.stringify(obj, null, 2)], {
type: "application/json"
}))
} else if (format == 'csv') {
let csvContent = "data:text/csv;charset=utf-8," //+ obj.map(e => e.join(',')).join('\n')
csvContent += "Time,Extension,Load\n"
csvContent += "(sec),(mm),(N)\n"
for(let line of obj){
csvContent += `${line[0].toFixed(3)},${line[1].toFixed(4)},${line[2].toFixed(4)}\n`
}
console.log(csvContent)
url = encodeURI(csvContent)
}
// hack to trigger the download,
let anchor = $('<a>ok</a>').attr('href', url).attr('download', name + `.${format}`).get(0)
$(document.body).append(anchor)
anchor.click()
}
}
......@@ -3,7 +3,7 @@
<head>
<title>dex-tools</title>
<!-- these three disable caching -->
<!-- these three disable caching, or like, should? -->
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
......@@ -11,12 +11,9 @@
<body>
<link href="style.css" rel="stylesheet">
<!--<link href="asset/emoji.css" rel="stylesheet">-->
<script src="libs/jquery.min.js"></script>
<script src="libs/math.js" type="text/javascript"></script>
<!-- <script src="libs/vue.js"></script> -->
<!--<script src="libs/d3.js"></script>-->
<!--<script src="libs/math.js" type="text/javascript"></script>-->
<script src="libs/d3.js"></script>
<script type="module" src="dex-client.js"></script>
<div id="wrapper">
......
This diff is collapsed.
......@@ -71,6 +71,11 @@ body {
background-color: #dbdbdb;
}
.chart{
position: absolute;
background-color: #dbdbdb;
}
/* svg bs */
.svgcont {
......
/*
lineChart.js
draws data to line chart
Jake Read at the Center for Bits and Atoms
(c) Massachusetts Institute of Technology 2019
This work may be reproduced, modified, distributed, performed, and
displayed for any purpose, but must acknowledge the squidworks and cuttlefish projects.
Copyright is retained and must be preserved. The work is provided as is;
no warranty is provided, and users accept all liability.
*/
// using https://bl.ocks.org/d3noob/402dd382a51a4f6eea487f9a35566de0
export default function LineChart() {
// dom elements
this.de = $('<div>').addClass('chart')
let uid = `lineChart_${parseInt(Math.random()*1000)}_uid`
$(this.de).attr('id', uid)
let cwidth = 500
let cheight = 500
$(this.de).css('width', `${cwidth}px`).css('height', `${cheight}px`)
// our vars,
var margin = {
top: 20,
right: 20,
bottom: 30,
left: 90
}
let width = cwidth - margin.left - margin.right
let height = cheight - margin.top - margin.bottom
var x = d3.scaleLinear().range([0, width])
var y = d3.scaleLinear().range([height, 0])
var thesvg = null
// make ah function
this.draw = (data) => {
var valueline = d3.line()
.x(function(d) {
return x(d[0])
})
.y(function(d) {
return y(d[1])
})
// scale
x.domain([d3.min(data, function(d) {
return d[0]
}), d3.max(data, function(d) {
return d[0];
})])
y.domain([d3.min(data, function(d) {
return d[1]
}), d3.max(data, function(d) {
return d[1];
})])
if (thesvg) {
d3.select(`#${uid}`).selectAll("*").remove()
}
thesvg = d3.select(`#${uid}`).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// write it?
thesvg.append("path")
.data([data])
.attr("class", "line")
.attr("stroke-width", "2px")
.attr("stroke", "black")
.attr("fill", "none")
.attr("d", valueline)
// write the x axis
thesvg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
// the y axis
thesvg.append("g")
.call(d3.axisLeft(y))
}
}
Time,Extension,Load
(sec),(mm),(N)
0.000,0.0000,-0.8306
0.885,0.0101,-0.7384
1.810,0.0202,-0.6066
2.735,0.0302,-0.4707
3.658,0.0403,-0.3288
4.583,0.0504,-0.1731
5.509,0.0605,-0.0307
6.432,0.0706,0.1063
7.357,0.0806,0.2443
8.281,0.0907,0.3777
9.205,0.1008,0.5180
10.131,0.1109,0.6616
11.054,0.1210,0.8096
11.980,0.1310,0.9703
12.905,0.1411,1.1126
13.830,0.1512,1.2508
14.752,0.1613,1.3932
15.679,0.1714,1.5450
16.603,0.1815,1.6891
17.527,0.1915,1.8363
18.452,0.2016,1.9876
19.376,0.2117,2.1519
20.302,0.2218,2.3068
21.225,0.2319,2.4594
22.151,0.2419,2.6131
23.073,0.2520,2.7592
24.001,0.2621,2.9075
24.923,0.2722,3.0533
25.851,0.2823,3.1999
26.772,0.2923,3.3583
27.700,0.3024,3.5000
28.625,0.3125,3.6418
29.549,0.3226,3.7791
30.474,0.3327,3.9222
31.397,0.3427,4.0580
32.323,0.3528,4.1981
33.247,0.3629,4.3354
34.173,0.3730,4.4833
35.096,0.3831,4.6177
36.022,0.3931,4.7530
36.948,0.4032,4.8940
37.872,0.4133,5.0311
38.796,0.4234,5.1690
39.720,0.4335,5.3012
40.646,0.4435,5.4357
41.571,0.4536,5.5802
42.494,0.4637,5.7074
43.420,0.4738,5.8327
44.344,0.4839,5.9571
45.269,0.4940,6.0861
46.193,0.5040,6.2123
47.118,0.5141,6.3369
48.042,0.5242,6.4586
48.967,0.5343,6.5900
49.893,0.5444,6.7077
50.816,0.5544,6.8211
51.741,0.5645,6.9360
52.666,0.5746,7.0474
53.591,0.5847,7.1607
54.515,0.5948,7.2679
55.439,0.6048,7.3724
56.364,0.6149,7.4850
57.289,0.6250,7.5770
58.213,0.6351,7.6656
59.137,0.6452,7.7487
60.062,0.6552,7.8262
60.988,0.6653,7.8909
61.913,0.6754,7.9421
62.837,0.6855,7.9745
63.761,0.6956,7.9945
64.686,0.7056,7.9768
65.609,0.7157,7.9338
66.535,0.7258,7.8761
67.460,0.7359,7.8033
68.384,0.7460,7.7282
69.310,0.7560,7.6459
70.233,0.7661,7.5660
71.157,0.7762,7.4934
72.082,0.7863,7.4048
73.007,0.7964,7.3232
73.933,0.8065,7.2450
74.855,0.8165,7.1749
75.780,0.8266,7.1067
76.705,0.8367,7.0402
77.631,0.8468,6.9711
78.553,0.8569,6.9067
79.478,0.8669,6.8320
80.403,0.8770,6.7590
81.328,0.8871,6.6926
82.252,0.8972,6.6265
83.178,0.9073,6.5685
84.102,0.9173,6.5076
85.027,0.9274,6.4490
85.950,0.9375,6.3997
86.875,0.9476,6.3351
87.799,0.9577,6.2768
88.724,0.9677,6.2197
89.650,0.9778,6.1683
90.575,0.9879,6.1175
91.498,0.9980,6.0716
92.424,1.0081,6.0253
93.351,1.0181,5.9878
94.275,1.0282,5.9372
95.198,1.0383,5.8868
96.122,1.0484,5.8454
97.047,1.0585,5.8038
97.973,1.0685,5.7674
98.897,1.0786,5.7277
99.822,1.0887,5.6916
100.746,1.0988,5.6681
101.671,1.1089,5.6336
102.597,1.1190,5.6007
103.521,1.1290,5.5677
104.445,1.1391,5.5422
105.371,1.1492,5.5152
106.295,1.1593,5.4894
107.220,1.1694,5.4660
108.144,1.1794,5.4569
109.070,1.1895,5.4393
109.994,1.1996,5.4198
110.921,1.2097,5.4036
111.849,1.2198,5.3881
112.772,1.2298,5.3794
113.694,1.2399,5.3653
114.619,1.2500,5.3519
115.545,1.2601,5.3480
116.468,1.2702,5.3280
117.392,1.2802,5.3105
118.316,1.2903,5.2942
119.242,1.3004,5.2828
120.167,1.3105,5.2706
121.098,1.3206,5.2631
122.018,1.3306,5.2525
122.947,1.3407,5.2533
123.868,1.3508,5.2409
124.793,1.3609,5.2284
125.717,1.3710,5.2194
126.645,1.3810,5.2074
127.572,1.3911,5.2017
128.493,1.4012,5.1931
129.420,1.4113,5.1852
130.342,1.4214,5.1872
131.270,1.4315,5.1766
132.193,1.4415,5.1702
133.119,1.4516,5.1624
134.042,1.4617,5.1586
134.966,1.4718,5.1527
135.891,1.4819,5.1496
136.817,1.4919,5.1452
137.744,1.5020,5.1536
138.666,1.5121,5.1518
139.590,1.5222,5.1381
140.515,1.5323,5.1325
141.443,1.5423,5.1274
142.367,1.5524,5.1263
143.288,1.5625,5.1243
144.209,1.5726,5.1226
145.055,1.5827,5.1434
145.976,1.5927,5.1369
146.905,1.6028,5.1318
147.830,1.6129,5.1263
148.750,1.6230,5.1263
149.680,1.6331,5.1231
150.604,1.6431,5.1216
151.531,1.6532,5.1170
152.453,1.6633,5.1241
153.376,1.6734,5.1203
154.298,1.6835,5.1141
155.224,1.6935,5.1117
156.151,1.7036,5.1086
157.074,1.7137,5.1117
157.998,1.7238,5.1112
158.929,1.7339,5.1116
159.849,1.7440,5.1230
160.774,1.7540,5.1202
161.703,1.7641,5.1207
162.624,1.7742,5.1196
163.550,1.7843,5.1196
164.470,1.7944,5.1191
165.396,1.8044,5.1213
166.319,1.8145,5.1223
167.248,1.8246,5.1318
168.173,1.8347,5.1289
169.098,1.8448,5.1250
170.018,1.8548,5.1240
170.952,1.8649,5.1203
171.866,1.8750,5.1239
172.799,1.8851,5.1244
173.720,1.8952,5.1278
174.640,1.9052,5.1419
175.566,1.9153,5.1421
176.493,1.9254,5.1430
177.419,1.9355,5.1425
178.346,1.9456,5.1425
179.267,1.9556,5.1391
180.192,1.9657,5.1411
181.113,1.9758,5.1405
182.037,1.9859,5.1471
182.966,1.9960,5.1445
183.888,2.0060,5.1425
184.812,2.0161,5.1452
185.742,2.0262,5.1436
186.663,2.0363,5.1439
187.590,2.0464,5.1387
188.512,2.0565,5.1362
189.434,2.0665,5.1433
190.359,2.0766,5.1409
191.282,2.0867,5.1408
192.123,2.0968,5.1534
193.051,2.1069,5.1563
193.973,2.1169,5.1567
194.897,2.1270,5.1601
195.821,2.1371,5.1606
196.749,2.1472,5.1698
197.671,2.1573,5.1686
198.595,2.1673,5.1666
199.522,2.1774,5.1675
200.451,2.1875,5.1629
201.370,2.1976,5.1623
202.296,2.2077,5.1580
203.218,2.2177,5.1550
204.145,2.2278,5.1600
205.067,2.2379,5.1540
205.991,2.2480,5.1523
206.919,2.2581,5.1507
207.841,2.2681,5.1553
208.768,2.2782,5.1548
209.695,2.2883,5.1570
210.622,2.2984,5.1584
211.539,2.3085,5.1697
212.462,2.3185,5.1680
213.390,2.3286,5.1635
214.312,2.3387,5.1620
215.238,2.3488,5.1583
216.161,2.3589,5.1573
217.088,2.3690,5.1554
218.010,2.3790,5.1577
218.937,2.3891,5.1650
219.861,2.3992,5.1586
220.786,2.4093,5.1536
221.707,2.4194,5.1485
222.634,2.4294,5.1470
223.565,2.4395,5.1417
224.484,2.4496,5.1386
225.408,2.4597,5.1333
226.339,2.4698,5.1379
227.259,2.4798,5.1331
228.185,2.4899,5.1265
229.108,2.5000,5.1218
230.028,2.5101,5.1176
230.957,2.5202,5.1161
231.883,2.5302,5.1136
232.807,2.5403,5.1132
233.730,2.5504,5.1201
234.653,2.5605,5.1131
235.578,2.5706,5.1082
236.500,2.5806,5.1064
237.423,2.5907,5.1074
238.271,2.6008,5.1183
239.190,2.6109,5.1190
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment