From 481f62fb6ccca1ece4a99cbba98b8e44c77c743c Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 11 Jan 2021 00:00:00 +0100 Subject: [PATCH 1/6] added http logger --- web/http.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/http.go b/web/http.go index f4b2226..cd4f54c 100644 --- a/web/http.go +++ b/web/http.go @@ -4,6 +4,7 @@ import ( "errors" "git.timovolkmann.de/gyrogpsc/core" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/template/html" "github.com/gofiber/websocket/v2" "github.com/google/uuid" @@ -14,7 +15,8 @@ func CreateServer(s *core.TrackingService, sub core.Subscriber, c *core.Configur app := fiber.New(fiber.Config{ Views: fiberTemplateEngine(c), }) - app.Static("/static", "static") + app.Use(logger.New()) + app.Static("/static", "./static") // Application Main Page app.Get("/", fiberHomeHandler) From 9f91328c08ca55fc8323fe50ae16f5a6c9d152d3 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 11 Jan 2021 00:00:30 +0100 Subject: [PATCH 2/6] fixed weird behavior --- core/pipeline_replay.go | 14 +++++++++----- core/service.go | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/pipeline_replay.go b/core/pipeline_replay.go index 53c0208..c9d2e89 100644 --- a/core/pipeline_replay.go +++ b/core/pipeline_replay.go @@ -23,9 +23,13 @@ func (p *pipelineReplay) Stop() { logrus.Debugln("replay channel already closed") } }() - logrus.Debugln("send stop signal") - p.stopChan <- struct{}{} - logrus.Debugln("stop signal sent") + logrus.Debugln("send stop signal...") + select { + case p.stopChan <- struct{}{}: + logrus.Debugln("stop signal sent") + //default: + // logrus.Debugln("stop signal skipped") + } } func NewReplayPipeline(p Publisher, t *Tracking) *pipelineReplay { @@ -59,7 +63,7 @@ func (p *pipelineReplay) channelFromTracking(t *Tracking) chan interface{} { if timeCounter >= durationSinceLastEvent { select { case <-p.stopChan: - logrus.Debugln("replay stopped") + logrus.Debugln("received stop signal: replay stopped") break br case ch <- &(t.Data[i]): } @@ -72,7 +76,7 @@ func (p *pipelineReplay) channelFromTracking(t *Tracking) chan interface{} { logrus.Infoln("replay: tracking replay finished") select { case <-p.stopChan: - logrus.Debugln("replay pipeline closed") + logrus.Debugln("received stop signal: replay pipeline closed") } close(p.replayChan) }() diff --git a/core/service.go b/core/service.go index b7b0410..ffe74ae 100644 --- a/core/service.go +++ b/core/service.go @@ -243,8 +243,12 @@ func (t *TrackingService) LoadTracking(trackingId uuid.UUID, replay bool) (*Trac } t.safelyReplaceTracking(*tracking) if t.replaypipe != nil { - t.replaypipe.Stop() t.replaypipe = nil + select { + case <-t.replaypipe.stopChan: + logrus.Warnln("blocking channel closed") + default: + } } t.replaypipe = NewReplayPipeline(t.publisher, t.tracking) t.publisher.SetStreaming(true) From 13013336298ff96a99ee990c474f574638e41d7a Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 11 Jan 2021 00:01:00 +0100 Subject: [PATCH 3/6] BIG FRONTEND REFRESH =) --- static/scripts/cubes.js | 89 +++++++++++++++++++++++++++++++++-- static/scripts/speedometer.js | 4 +- static/scripts/websocket.js | 49 ++++++++++--------- static/style.css | 5 ++ templates/index.html | 85 ++++++++++++++++++++------------- 5 files changed, 173 insertions(+), 59 deletions(-) diff --git a/static/scripts/cubes.js b/static/scripts/cubes.js index 27c8179..1ce2920 100644 --- a/static/scripts/cubes.js +++ b/static/scripts/cubes.js @@ -58,14 +58,17 @@ cube2.position.x = 0 let manCalibration = new THREE.Euler( 0, 0, 0, 'XYZ' ) let calibrationRot = new THREE.Quaternion() +let quaternionOffset = document.getElementById("quaternionOffset") + function renderTCP(x, y, z) { let calibration = new THREE.Quaternion().setFromEuler(manCalibration) // let calibration = new THREE.Quaternion().setFromEuler(new THREE.Euler( radFromAngle, 0, 0, 'YXZ' )) let eul = new THREE.Euler( x, z, y, 'YXZ' ); // let eul = new THREE.Euler( x, z, y, 'ZXY' ); // XYZ XZY YZX YXZ ZXY ZYX + cube2.quaternion.setFromEuler(eul).multiply(calibrationRot).multiply(calibration) - cube2.quaternion.setFromEuler(eul).multiply(calibrationRot)//.multiply(calibration) + quaternionOffset.innerHTML = `Lage Abweichung: ${(cube2.quaternion.angleTo(cube.quaternion) * 180 / Math.PI).toFixed(2) }°` renderer.render(scene, camera); } @@ -114,15 +117,16 @@ function manualCalibration(evt) { let con = document.getElementById("manCalContainer") console.log("mancal", con.style.display) if (calState === false) { + delCalibration() calState = !calState console.log("mancal ON") con.style.display = "block" - delCalibration() } else { + delCalibration() calState = !calState console.log("mancal OFF") con.style.display = "none" - manCalibration = new THREE.Euler( 0, 0, 0, 'YXZ' ) + manCalibration = new THREE.Euler( 0, 0, 0, 'XYZ' ) pitchRange.value = 0 yawRange.value = 0 rollRange.value = 0 @@ -138,3 +142,82 @@ function calibrate(evt) { document.getElementById("deleteCalibration").onclick = delCalibration document.getElementById("manualCalibration").onclick = manualCalibration document.getElementById("calibrate").onclick = calibrate + + +// indicators // + +var options = { + size : 200, // Sets the size in pixels of the indicator (square) + roll : 0, // Roll angle in degrees for an attitude indicator + pitch : 0, // Pitch angle in degrees for an attitude indicator + heading: 0, // Heading angle in degrees for an heading indicator + vario: 0, // Variometer in 1000 feets/min for the variometer indicator + airspeed: 0, // Air speed in knots for an air speed indicator + altitude: 0, // Altitude in feets for an altimeter indicator + pressure: 1000, // Pressure in hPa for an altimeter indicator + showBox : true, // Sets if the outer squared box is visible or not (true or false) + img_directory : 'static/indicators/img/' // The directory where the images are saved to +} + +var headingSer = $.flightIndicator('#headingSer', 'heading', options); +var headingTcp = $.flightIndicator('#headingTcp', 'heading', options); +var attitudeSer = $.flightIndicator('#attitudeSer', 'attitude', options); +var attitudeTcp = $.flightIndicator('#attitudeTcp', 'attitude', options); +// var variometer = $.flightIndicator('#variometer', 'variometer', options); +var airspeed = $.flightIndicator('#airspeed', 'airspeed', options); +var altimeter = $.flightIndicator('#altimeter', 'altimeter', options); + +var airspeedLabel = document.getElementById("airspeedLabel") +var altitudeLabel = document.getElementById("altitudeLabel") + +function setIndicatorsTcp(sensordata) { + // let q = new THREE.Euler().setFromQuaternion( quaternionRawTcp, 'YXZ' ) // XYZ XZY YZX YXZ ZXY ZYX + let q = new THREE.Euler().setFromQuaternion( cube2.quaternion, 'YXZ' ) // XYZ XZY YZX YXZ ZXY ZYX + + if (sensordata.Orientation[0] !== 0 && sensordata.Orientation[1] !== 0) { + //attitudeTcp.setPitch(sensordata.Orientation[0]) + attitudeTcp.setPitch(-q.x * 180 / Math.PI * -1) + //attitudeTcp.setRoll(sensordata.Orientation[1]) + attitudeTcp.setRoll(-q.z * 180 / Math.PI * -1) + } + + // Heading from quaternion + // if (sensordata.Orientation[2] !== 0) { + // // headingTcp.setHeading((-sensordata.Orientation[2]-90)%360) + // let h = q.y * 180 / Math.PI * -1 + // headingTcp.setHeading(h) + // } + let heading = sensordata.HeadDevice + if (heading !== 0) { + headingTcp.setHeading(heading) + } +} + +function setIndicatorsSer(sensordata) { + let q = new THREE.Euler().setFromQuaternion( cube.quaternion, 'YXZ' ) + + if (sensordata.Orientation[0] !== 0 && sensordata.Orientation[1] !== 0) { + attitudeSer.setPitch(sensordata.Orientation[0]) + attitudeSer.setRoll(sensordata.Orientation[1]) + } + + // Heading from quaternion + // if (sensordata.Orientation[2] !== 0) { + // // headingTcp.setHeading((-sensordata.Orientation[2]-90)%360) + // let h = q.y * 180 / Math.PI * -1 + // headingSer.setHeading(h) + // } + let heading = sensordata.HeadDevice + if (heading !== 0) { + headingSer.setHeading(heading) + } + if (sensordata.Speed !== 0) { + airspeed.setAirSpeed(sensordata.Speed * 3.6) + airspeedLabel.innerHTML = `Ref. Speed: ${(sensordata.Speed * 3.6).toFixed(1)} km/h` + } + if (sensordata.Position[2] !== 0) { + altimeter.setAltitude((sensordata.Position[2] * 10).toFixed()) + altitudeLabel.innerHTML = `HMSL: ${(sensordata.Position[2]).toFixed(2)} m` + } +} + diff --git a/static/scripts/speedometer.js b/static/scripts/speedometer.js index 2ceb297..315e209 100644 --- a/static/scripts/speedometer.js +++ b/static/scripts/speedometer.js @@ -152,7 +152,7 @@ function addSpeedSerial(speedSERIAL){ var speedSERIALkmh = (speedSERIAL * 3.6) var speedSERIALpercent = (speedSERIALkmh/250)*100 mySpeedometer.data.datasets[1].data = [speedSERIALpercent, 100-speedSERIALpercent]; - document.getElementById("speedSERIAL").innerHTML = "Speed Ublox (km/h): " + speedSERIALkmh.toFixed(1) + document.getElementById("speedSERIAL").innerHTML = `Ublox: ${speedSERIALkmh.toFixed(1)} km/h` mySpeedometer.update(); } @@ -160,6 +160,6 @@ function addSpeedTcp(speedTCP){ var speedTCPkmh = (speedTCP * 3.6) var speedTCPpercent = (speedTCPkmh/250)*100; mySpeedometer.data.datasets[0].data = [speedTCPpercent, 100-speedTCPpercent]; - document.getElementById("speedTCP").innerHTML = "Speed Smartphone (km/h): " + speedTCPkmh.toFixed(1) + document.getElementById("speedTCP").innerHTML = `Phone: ${speedTCPkmh.toFixed(1)} km/h` mySpeedometer.update(); } diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js index 5868447..11ba5d8 100644 --- a/static/scripts/websocket.js +++ b/static/scripts/websocket.js @@ -10,7 +10,7 @@ window.addEventListener("load", function(evt) { const wsOnCloseF = function (evt) { ws = null; - print2("CLOSE"); + print2("CLOSED"); var intervalId; intervalId = setInterval(() => { console.log("reconnect websocket...") @@ -29,21 +29,18 @@ window.addEventListener("load", function(evt) { }, 1000) } const wsOnMessageF = function (evt) { - //print2("RESPONSE: " + evt.data); - // let dat = JSON.parse(evt.data)["bmi26x gyroscope"] - // let dat = JSON.parse(evt.data)["lsm6dsm gyroscope"] - //let dat = JSON.parse(evt.data)["lsm6ds3c gyroscope"] let dat = JSON.parse(evt.data) - // dataSmartphone.push(dat) - //console.log(evt.data) - // console.log("JSON geparsed onmessage", dat) + //console.log(dat) + if ('SOURCE_TCP' in dat) { + setIndicatorsTcp(dat.SOURCE_TCP) + } try{ if(!(dat.SOURCE_TCP.Orientation[0] === 0) && !(dat.SOURCE_TCP.Orientation[1] === 0) && !(dat.SOURCE_TCP.Orientation[2] === 0)){ - // document.getElementById("gyroscopeTCP").style.transform = `rotateX(${(dat.SOURCE_TCP.Orientation[0])%360}deg) rotateY(${(dat.SOURCE_TCP.Orientation[1])%360}deg) rotateZ(0deg)` - // document.getElementById("gyroscopeTCP").style.transform = `rotateY(0deg) rotateX(${(-dat.SOURCE_TCP.Orientation[0])}deg) rotateZ(${(dat.SOURCE_TCP.Orientation[1])}deg) ` - // document.getElementById("gyroscopeTCP").style.transform = `rotateX(${(dat.SOURCE_TCP.Orientation[0])%360}deg) rotateZ(${(dat.SOURCE_TCP.Orientation[1])%360}deg) rotateY(${(dat.SOURCE_TCP.Orientation[2])%360}deg)` - // console.log(dat.SOURCE_TCP.Orientation) - renderTCP(dat.SOURCE_TCP.Orientation[0]*Math.PI/180,-dat.SOURCE_TCP.Orientation[1]*Math.PI/180,dat.SOURCE_TCP.Orientation[2]*Math.PI/180) + let heading = (dat.SOURCE_TCP.Orientation[2]+90)%360 // dat.SOURCE_TCP.Orientation[2]// + // if (dat.SOURCE_TCP.HeadDevice !== 0) { heading = dat.SOURCE_TCP.HeadDevice; } + // if (dat.SOURCE_TCP.HeadMotion !== 0) { heading = dat.SOURCE_TCP.HeadMotion; console.log("head motion") } + + renderTCP(dat.SOURCE_TCP.Orientation[0]*Math.PI/180,-dat.SOURCE_TCP.Orientation[1]*Math.PI/180,heading*Math.PI/180) } if(!(dat.SOURCE_TCP.Position[1] === 0) && !(dat.SOURCE_TCP.Position[0] === 0)){ document.getElementById("TCPlong").innerHTML = "Smartphone long: " + dat.SOURCE_TCP.Position[1] @@ -55,15 +52,20 @@ window.addEventListener("load", function(evt) { addSpeedTcp(dat.SOURCE_TCP.Speed); } if(!(dat.SOURCE_TCP.HeadDevice === 0)){ - document.getElementById("compassTCP").innerHTML = "Smartphone:
" + dat.SOURCE_TCP.HeadDevice.toFixed(0) + "°" - document.getElementById("needleTCP").style.transform = `rotate(${dat.SOURCE_TCP.HeadDevice}deg)` + document.getElementById("compassTCP").innerHTML = " Heading Device: " + dat.SOURCE_TCP.HeadDevice.toFixed(2) + "°" + // document.getElementById("needleTCP").style.transform = `rotate(${dat.SOURCE_TCP.HeadDevice}deg)` + } + if(!(dat.SOURCE_TCP.HeadMotion === 0)) { + document.getElementById("compassTCPMot").innerHTML = "Heading Motion: " + dat.SOURCE_TCP.HeadMotion.toFixed(2) + "°" } } catch{ // console.log("no TCP data") } - + if ('SOURCE_SERIAL' in dat) { + setIndicatorsSer(dat.SOURCE_SERIAL) + } try{ if(!(dat.SOURCE_SERIAL.Orientation[0] === 0) && /*!(dat.SOURCE_SERIAL.Orientation[1] === 0) &&*/ !(dat.SOURCE_SERIAL.Orientation[2] === 0)){ // document.getElementById("gyroscopeSERIAL").style.transform = `rotateX(${dat.SOURCE_SERIAL.Orientation[0]}deg) rotateY(${dat.SOURCE_SERIAL.Orientation[1]}deg) rotateZ(0deg)` @@ -80,8 +82,11 @@ window.addEventListener("load", function(evt) { addSpeedSerial(dat.SOURCE_SERIAL.Speed); } if(!(dat.SOURCE_SERIAL.HeadDevice === 0)){ - document.getElementById("compassSERIAL").innerHTML = "Ublox: " + dat.SOURCE_SERIAL.HeadDevice.toFixed(0) + "°" - document.getElementById("needle").style.transform = `rotate(${dat.SOURCE_SERIAL.HeadDevice}deg)` + document.getElementById("compassSERIAL").innerHTML = "Heading Device: " + dat.SOURCE_SERIAL.HeadDevice.toFixed(2) + "°" + // document.getElementById("needle").style.transform = `rotate(${dat.SOURCE_SERIAL.HeadDevice}deg)` + } + if(!(dat.SOURCE_SERIAL.HeadMotion === 0)) { + document.getElementById("compassSERIALMot").innerHTML = "Heading Motion: " + dat.SOURCE_SERIAL.HeadDevice.toFixed(2) + "°" } }catch{ // console.log("no serial data") @@ -92,22 +97,22 @@ window.addEventListener("load", function(evt) { addSerialAccuracy(dat.SOURCE_SERIAL.HAcc, dat.SOURCE_SERIAL.VAcc) document.getElementById("serialHAcc").innerHTML = "Ublox HAcc: " + dat.SOURCE_SERIAL.HAcc.toFixed(2) + " m" document.getElementById("serialVAcc").innerHTML = "Ublox VAcc: " + dat.SOURCE_SERIAL.VAcc.toFixed(2) + " m" - console.log("acc: " + dat.SOURCE_SERIAL.HAcc, dat.SOURCE_SERIAL.VAcc) + // console.log("acc: " + dat.SOURCE_SERIAL.HAcc, dat.SOURCE_SERIAL.VAcc) } } catch{ - console.log("no Serial acc") + // console.log("no Serial acc") } try{ if(!(dat.SOURCE_TCP.HAcc === 0) && !(dat.SOURCE_TCP.VAcc === 0)){ addTCPAccuracy(dat.SOURCE_TCP.HAcc, dat.SOURCE_TCP.VAcc) document.getElementById("tcpHAcc").innerHTML = "Smartphone HAcc: " + dat.SOURCE_TCP.HAcc.toFixed(2) + " m" document.getElementById("tcpVAcc").innerHTML = "Smartphone VAcc: " + dat.SOURCE_TCP.VAcc.toFixed(2) + " m" - console.log("acc: " + dat.SOURCE_TCP.HAcc, dat.SOURCE_TCP.VAcc) + // console.log("acc: " + dat.SOURCE_TCP.HAcc, dat.SOURCE_TCP.VAcc) } } catch{ - console.log("no TCP acc") + // console.log("no TCP acc") } } const wsOnOpenF = function (evt) { diff --git a/static/style.css b/static/style.css index 763548d..6afe762 100644 --- a/static/style.css +++ b/static/style.css @@ -49,6 +49,7 @@ body{margin:0; padding:0; font-size:13px; font-family:Georgia, "Times New Roman" display: flex; flex-flow: wrap; width: 34%; + max-width: 460px; } .left-col { display: flex; @@ -469,3 +470,7 @@ label { margin-right: 10px; } width: 100%; height: 360px; } + +.compass-digital { + width: 400px; +} diff --git a/templates/index.html b/templates/index.html index 9d8c1cb..c8cd8af 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,15 +8,15 @@ + + + - -
-

"Verbinden" klicken um eine Verbindung mit dem Server aufzubauen. {{.}}



@@ -33,7 +33,7 @@ - +

-

.

+

CLOSED

@@ -121,40 +121,61 @@
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
-
-
-
-
-
- N - O - S - W -
-
-
-
+ style="display:inline-block; width: 200px; margin-right: 0; color: rgba(214, 69, 65, 1); font: 15px 'Helvetica Neue', Arial, Helvetica, sans-serif">
-
-
-
-
-
- N - O - S - W -
-
+ style="color: rgba(30, 139, 195, 1); font: 15px 'Helvetica Neue', Arial, Helvetica, sans-serif">
+ +
+
+ + + + + +
+
From 730207c6377d20b4d41392d339f2d9dc1c797a68 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 11 Jan 2021 00:21:32 +0100 Subject: [PATCH 4/6] frontend bugfixes --- static/scripts/cubes.js | 6 +++--- static/scripts/websocket.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/static/scripts/cubes.js b/static/scripts/cubes.js index 1ce2920..27611d0 100644 --- a/static/scripts/cubes.js +++ b/static/scripts/cubes.js @@ -197,8 +197,8 @@ function setIndicatorsSer(sensordata) { let q = new THREE.Euler().setFromQuaternion( cube.quaternion, 'YXZ' ) if (sensordata.Orientation[0] !== 0 && sensordata.Orientation[1] !== 0) { - attitudeSer.setPitch(sensordata.Orientation[0]) - attitudeSer.setRoll(sensordata.Orientation[1]) + attitudeSer.setPitch(-sensordata.Orientation[0]) + attitudeSer.setRoll(-sensordata.Orientation[1]) } // Heading from quaternion @@ -207,7 +207,7 @@ function setIndicatorsSer(sensordata) { // let h = q.y * 180 / Math.PI * -1 // headingSer.setHeading(h) // } - let heading = sensordata.HeadDevice + let heading = sensordata.HeadMotion if (heading !== 0) { headingSer.setHeading(heading) } diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js index 11ba5d8..add721d 100644 --- a/static/scripts/websocket.js +++ b/static/scripts/websocket.js @@ -86,7 +86,7 @@ window.addEventListener("load", function(evt) { // document.getElementById("needle").style.transform = `rotate(${dat.SOURCE_SERIAL.HeadDevice}deg)` } if(!(dat.SOURCE_SERIAL.HeadMotion === 0)) { - document.getElementById("compassSERIALMot").innerHTML = "Heading Motion: " + dat.SOURCE_SERIAL.HeadDevice.toFixed(2) + "°" + document.getElementById("compassSERIALMot").innerHTML = "Heading Motion: " + dat.SOURCE_SERIAL.HeadMotion.toFixed(2) + "°" } }catch{ // console.log("no serial data") From b4a3b09fb151df109cbf3946d3493bdb4b7d3c9b Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 11 Jan 2021 01:18:38 +0100 Subject: [PATCH 5/6] backend bugfixes --- core/pipeline_replay.go | 13 +++++++------ core/service.go | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/pipeline_replay.go b/core/pipeline_replay.go index c9d2e89..7f40d18 100644 --- a/core/pipeline_replay.go +++ b/core/pipeline_replay.go @@ -61,17 +61,18 @@ func (p *pipelineReplay) channelFromTracking(t *Tracking) chan interface{} { durationSinceLastEvent := t.Data[i].Servertime.UnixNano() - lastTs timeCounter := time.Now().UTC().UnixNano() - lastTsNow if timeCounter >= durationSinceLastEvent { - select { - case <-p.stopChan: - logrus.Debugln("received stop signal: replay stopped") - break br - case ch <- &(t.Data[i]): - } logrus.Traceln("replay tracking: ", t.Data[i]) + ch <- &(t.Data[i]) lastTs = t.Data[i].Servertime.UnixNano() lastTsNow = time.Now().UTC().UnixNano() i++ } + select { + case <-p.stopChan: + logrus.Debugln("received stop signal: replay stopped") + break br + default: + } } logrus.Infoln("replay: tracking replay finished") select { diff --git a/core/service.go b/core/service.go index ffe74ae..706a1b1 100644 --- a/core/service.go +++ b/core/service.go @@ -243,12 +243,12 @@ func (t *TrackingService) LoadTracking(trackingId uuid.UUID, replay bool) (*Trac } t.safelyReplaceTracking(*tracking) if t.replaypipe != nil { - t.replaypipe = nil select { case <-t.replaypipe.stopChan: logrus.Warnln("blocking channel closed") default: } + t.replaypipe = nil } t.replaypipe = NewReplayPipeline(t.publisher, t.tracking) t.publisher.SetStreaming(true) From ed60415f27d1cd6be714b8a4d2e610ed4655427c Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 11 Jan 2021 02:08:41 +0100 Subject: [PATCH 6/6] jetzt hoffentlich xD --- static/scripts/cubes.js | 34 +++++++++++++++++++++++----------- static/scripts/websocket.js | 8 ++++---- templates/index.html | 6 +++--- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/static/scripts/cubes.js b/static/scripts/cubes.js index 27611d0..4f18b4f 100644 --- a/static/scripts/cubes.js +++ b/static/scripts/cubes.js @@ -55,15 +55,19 @@ scene.add(pointLight); cube.position.x = 0 cube2.position.x = 0 -let manCalibration = new THREE.Euler( 0, 0, 0, 'XYZ' ) +// calibration globals +let manCalibration = new THREE.Euler( 0, 0, 0, 'YXZ' ) let calibrationRot = new THREE.Quaternion() +let calPitch = 0 +let calRoll = 0 +let calYaw = 0 let quaternionOffset = document.getElementById("quaternionOffset") function renderTCP(x, y, z) { let calibration = new THREE.Quaternion().setFromEuler(manCalibration) // let calibration = new THREE.Quaternion().setFromEuler(new THREE.Euler( radFromAngle, 0, 0, 'YXZ' )) - let eul = new THREE.Euler( x, z, y, 'YXZ' ); + let eul = new THREE.Euler( x, y, z, 'YXZ' ); // let eul = new THREE.Euler( x, z, y, 'ZXY' ); // XYZ XZY YZX YXZ ZXY ZYX cube2.quaternion.setFromEuler(eul).multiply(calibrationRot).multiply(calibration) @@ -76,9 +80,7 @@ function renderTCP(x, y, z) { function renderSerial(x, y, z) { // requestAnimationFrame(renderSerial); - // let eul = new THREE.Euler( x, y, z, 'YXZ' ); // XYZ XZY YZX YXZ ZXY ZYX - // let eul = new THREE.Euler( x, z, y, 'ZXY' ); // XYZ XZY YZX YXZ ZXY ZYX - let eul = new THREE.Euler( x, z, y, 'YXZ' ); + let eul = new THREE.Euler( x, y, z, 'YXZ' ); // XYZ XZY YZX YXZ ZXY ZYX cube.quaternion.setFromEuler(eul) @@ -106,10 +108,12 @@ rollRange.oninput = () => { function delCalibration(evt) { calibrationRot = new THREE.Quaternion() - manCalibration = new THREE.Euler( 0, 0, 0, 'XYZ' ) + manCalibration = new THREE.Euler( 0, 0, 0, 'YXZ' ) pitchRange.value = 0 yawRange.value = 0 rollRange.value = 0 + calRoll = 0 + calPitch = 0 } var calState = false; @@ -126,7 +130,7 @@ function manualCalibration(evt) { calState = !calState console.log("mancal OFF") con.style.display = "none" - manCalibration = new THREE.Euler( 0, 0, 0, 'XYZ' ) + manCalibration = new THREE.Euler( 0, 0, 0, 'YXZ' ) pitchRange.value = 0 yawRange.value = 0 rollRange.value = 0 @@ -137,6 +141,14 @@ function calibrate(evt) { let serOrientation = cube.quaternion.clone() let tcpOrientation = cube2.quaternion.clone().multiply(calibrationRot.clone().invert()) let diff = tcpOrientation.invert().multiply(serOrientation) + + let old = new THREE.Euler().setFromQuaternion( cube2.quaternion, 'YXZ' ) + let dif = new THREE.Euler().setFromQuaternion( diff ) + console.log("OLD:","pitch", old.x * 180/Math.PI, "yaw", old.y * 180/Math.PI, "roll", old.z * 180/Math.PI) + console.log("DIFF:","pitch", dif.x * 180/Math.PI, "yaw", dif.y * 180/Math.PI, "roll", dif.z * 180/Math.PI) + calPitch = dif.x // * 180/Math.PI + calYaw = dif.y // * 180/Math.PI + calRoll = dif.z // * 180/Math.PI calibrationRot = diff }; document.getElementById("deleteCalibration").onclick = delCalibration @@ -176,9 +188,9 @@ function setIndicatorsTcp(sensordata) { if (sensordata.Orientation[0] !== 0 && sensordata.Orientation[1] !== 0) { //attitudeTcp.setPitch(sensordata.Orientation[0]) - attitudeTcp.setPitch(-q.x * 180 / Math.PI * -1) + attitudeTcp.setPitch(q.x * 180 / Math.PI) //attitudeTcp.setRoll(sensordata.Orientation[1]) - attitudeTcp.setRoll(-q.z * 180 / Math.PI * -1) + attitudeTcp.setRoll(q.z * 180 / Math.PI) } // Heading from quaternion @@ -197,8 +209,8 @@ function setIndicatorsSer(sensordata) { let q = new THREE.Euler().setFromQuaternion( cube.quaternion, 'YXZ' ) if (sensordata.Orientation[0] !== 0 && sensordata.Orientation[1] !== 0) { - attitudeSer.setPitch(-sensordata.Orientation[0]) - attitudeSer.setRoll(-sensordata.Orientation[1]) + attitudeSer.setPitch(sensordata.Orientation[0]) + attitudeSer.setRoll(sensordata.Orientation[1]) } // Heading from quaternion diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js index add721d..9460ec6 100644 --- a/static/scripts/websocket.js +++ b/static/scripts/websocket.js @@ -30,17 +30,17 @@ window.addEventListener("load", function(evt) { } const wsOnMessageF = function (evt) { let dat = JSON.parse(evt.data) - //console.log(dat) + // console.log(dat) if ('SOURCE_TCP' in dat) { setIndicatorsTcp(dat.SOURCE_TCP) } try{ if(!(dat.SOURCE_TCP.Orientation[0] === 0) && !(dat.SOURCE_TCP.Orientation[1] === 0) && !(dat.SOURCE_TCP.Orientation[2] === 0)){ - let heading = (dat.SOURCE_TCP.Orientation[2]+90)%360 // dat.SOURCE_TCP.Orientation[2]// + let heading = (dat.SOURCE_TCP.Orientation[2]+90)%360 // dat.SOURCE_TCP.Orientation[2] // // if (dat.SOURCE_TCP.HeadDevice !== 0) { heading = dat.SOURCE_TCP.HeadDevice; } // if (dat.SOURCE_TCP.HeadMotion !== 0) { heading = dat.SOURCE_TCP.HeadMotion; console.log("head motion") } - renderTCP(dat.SOURCE_TCP.Orientation[0]*Math.PI/180,-dat.SOURCE_TCP.Orientation[1]*Math.PI/180,heading*Math.PI/180) + renderTCP((dat.SOURCE_TCP.Orientation[0]*Math.PI/180),heading*Math.PI/180,-(dat.SOURCE_TCP.Orientation[1]*Math.PI/180)) } if(!(dat.SOURCE_TCP.Position[1] === 0) && !(dat.SOURCE_TCP.Position[0] === 0)){ document.getElementById("TCPlong").innerHTML = "Smartphone long: " + dat.SOURCE_TCP.Position[1] @@ -70,7 +70,7 @@ window.addEventListener("load", function(evt) { if(!(dat.SOURCE_SERIAL.Orientation[0] === 0) && /*!(dat.SOURCE_SERIAL.Orientation[1] === 0) &&*/ !(dat.SOURCE_SERIAL.Orientation[2] === 0)){ // document.getElementById("gyroscopeSERIAL").style.transform = `rotateX(${dat.SOURCE_SERIAL.Orientation[0]}deg) rotateY(${dat.SOURCE_SERIAL.Orientation[1]}deg) rotateZ(0deg)` // document.getElementById("gyroscopeSERIAL").style.transform = `rotateX(${dat.SOURCE_SERIAL.Orientation[0]}deg) rotateY(${dat.SOURCE_SERIAL.Orientation[1]}deg) rotateZ(${dat.SOURCE_SERIAL.Orientation[2]}deg)` - renderSerial(dat.SOURCE_SERIAL.Orientation[0]*Math.PI/180,dat.SOURCE_SERIAL.Orientation[1]*Math.PI/180,-dat.SOURCE_SERIAL.Orientation[2]*Math.PI/180) + renderSerial(dat.SOURCE_SERIAL.Orientation[0]*Math.PI/180,-dat.SOURCE_SERIAL.Orientation[2]*Math.PI/180,dat.SOURCE_SERIAL.Orientation[1]*Math.PI/180) } if(!(dat.SOURCE_SERIAL.Position[1] === 0) && !(dat.SOURCE_SERIAL.Position[0] === 0)){ document.getElementById("SERIALlong").innerHTML = "Ublox long: " + dat.SOURCE_SERIAL.Position[1] diff --git a/templates/index.html b/templates/index.html index c8cd8af..12d5af6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -182,11 +182,11 @@


Manuelle Kalibrierung

- - -