From 70e527dcfa26de0936adaf1e3c0e26ce673bc352 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Fri, 3 Apr 2015 17:40:54 +0200 Subject: reimplement motor load instrument --- .../main/scala/vfd/dashboard/MavlinkSocket.scala | 2 +- .../src/main/scala/vfd/dashboard/ui/Layout.scala | 35 +++-- .../vfd/dashboard/ui/instruments/Balance.scala | 27 ---- .../dashboard/ui/instruments/Distribution.scala | 26 ++++ .../vfd/dashboard/ui/instruments/Generic.scala | 2 +- vfd-main/public/images/instruments/balance.svg | 169 --------------------- .../public/images/instruments/distribution.svg | 169 +++++++++++++++++++++ 7 files changed, 218 insertions(+), 212 deletions(-) delete mode 100644 vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Balance.scala create mode 100644 vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Distribution.scala delete mode 100644 vfd-main/public/images/instruments/balance.svg create mode 100644 vfd-main/public/images/instruments/distribution.svg diff --git a/vfd-dashboard/src/main/scala/vfd/dashboard/MavlinkSocket.scala b/vfd-dashboard/src/main/scala/vfd/dashboard/MavlinkSocket.scala index 9476794..fb1856c 100644 --- a/vfd-dashboard/src/main/scala/vfd/dashboard/MavlinkSocket.scala +++ b/vfd-dashboard/src/main/scala/vfd/dashboard/MavlinkSocket.scala @@ -13,7 +13,7 @@ import rx.core.Rx import rx.core.Var import rx.ops.RxOps -class MavlinkSocket(url: String, remoteSystemId: Int) { +class MavlinkSocket(url: String, val remoteSystemId: Int) { lazy val packet: Var[Packet] = Var(Packet.empty) lazy val message: Rx[Message] = packet.map{p => diff --git a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/Layout.scala b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/Layout.scala index 1b1540e..a2e03ef 100644 --- a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/Layout.scala +++ b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/Layout.scala @@ -4,15 +4,8 @@ import rx.Obs import scalatags.JsDom.all._ import vfd.dashboard.Environment import vfd.dashboard.MavlinkSocket -import vfd.dashboard.ui.instruments.Altimeter -import vfd.dashboard.ui.instruments.Balance -import vfd.dashboard.ui.instruments.Bar -import vfd.dashboard.ui.instruments.Compass -import vfd.dashboard.ui.instruments.Generic -import vfd.dashboard.ui.instruments.Horizon -import org.mavlink.messages.Heartbeat -import org.mavlink.messages.Attitude -import vfd.dashboard.ui.instruments.Clock +import vfd.dashboard.ui.instruments._ +import org.mavlink.messages._ class Layout(socket: MavlinkSocket)(implicit env: Environment) { @@ -55,13 +48,14 @@ class Layout(socket: MavlinkSocket)(implicit env: Environment) { val motor1 = new Generic(0, 50, 100, "%") val motor2 = new Generic(0, 50, 100, "%") val motor3 = new Generic(0, 50, 100, "%") - val powerDistribution = new Balance() - val batteryLevel = new Bar() + val powerDistribution = new Distribution + val batteryLevel = new Bar val top = header( div("Flight Control Panel"), div((new Clock).element), - div("System #")) + div("UAV " + socket.remoteSystemId) + ) val left = panel( map, @@ -69,9 +63,9 @@ class Layout(socket: MavlinkSocket)(implicit env: Environment) { thead("Motors"), tbody( tr( - td(motor0.element), - td(), td(motor1.element), + td(), + td(motor0.element), td() ), tr( @@ -137,6 +131,18 @@ class Layout(socket: MavlinkSocket)(implicit env: Environment) { horizon.value() = (att.pitch, att.roll) compass.value() = att.yaw + case s: ServoOutputRaw => + val m0 = 100 * (s.servo1Raw - 1000) / 1000 + val m1 = 100 * (s.servo2Raw - 1000) / 1000 + val m2 = 100 * (s.servo3Raw - 1000) / 1000 + val m3 = 100 * (s.servo4Raw - 1000) / 1000 + + motor0.value() = m0 + motor1.value() = m1 + motor2.value() = m2 + motor3.value() = m3 + powerDistribution.value() = (m0, m1, m2, m3) + //TODO route other messages case _ => () @@ -144,4 +150,5 @@ class Layout(socket: MavlinkSocket)(implicit env: Environment) { } } + } \ No newline at end of file diff --git a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Balance.scala b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Balance.scala deleted file mode 100644 index ef5a3cc..0000000 --- a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Balance.scala +++ /dev/null @@ -1,27 +0,0 @@ -package vfd.dashboard.ui.instruments - -import org.scalajs.dom.html -import vfd.dashboard.Environment - -class Balance(implicit env: Environment) extends SvgInstrument[(Double, Double, Double, Double)] { - import SvgInstrument._ - - val initial = (0.0, 0.0, 0.0, 0.0) - - lazy val element = svgObject("balance") - lazy val position = part("position") - lazy val moveable = Seq(position) - - protected def update(value: (Double, Double, Double, Double)) = { - val m0 = value._1 - val m1 = value._2 - val m2 = value._3 - val m3 = value._4 - val s = m0 + m1 + m2 + m3 - val i = (m0 - m2) / s - val j = (m1 - m3) / s - val x = 0.5 * (i - j) - val y = 0.5 * (-i - j) - translate(position, (x * 50).toInt, (y * 50).toInt) - } -} \ No newline at end of file diff --git a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Distribution.scala b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Distribution.scala new file mode 100644 index 0000000..caeac33 --- /dev/null +++ b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Distribution.scala @@ -0,0 +1,26 @@ +package vfd.dashboard.ui.instruments + +import org.scalajs.dom.html +import vfd.dashboard.Environment + +class Distribution(implicit env: Environment) extends SvgInstrument[(Double, Double, Double, Double)] { + import SvgInstrument._ + + val initial = (0.0, 0.0, 0.0, 0.0) + + lazy val element = svgObject("distribution") + lazy val position = part("position") + lazy val moveable = Seq(position) + + private final val Radius = 50 //px + + protected def update(value: (Double, Double, Double, Double)) = { + val sum = value._1 + value._2 + value._3 + value._4 + val i = (value._1 - value._3) / sum + val j = (value._2 - value._4) / sum + val x = math.sqrt(2) / 2 * (i - j) + val y = math.sqrt(2) / 2 * (-i - j) + translate(position, (x * Radius).toInt, (y * Radius).toInt) + } + +} \ No newline at end of file diff --git a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Generic.scala b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Generic.scala index c46bdcc..af9469a 100644 --- a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Generic.scala +++ b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/Generic.scala @@ -34,7 +34,7 @@ class Generic( } protected def update(value: Double) = { - rotate(handElement, (value * 270 / (max - min)).toInt) + rotate(handElement, value / (max - min) * math.Pi * 3 / 2) valueElement.textContent = value.toString } } \ No newline at end of file diff --git a/vfd-main/public/images/instruments/balance.svg b/vfd-main/public/images/instruments/balance.svg deleted file mode 100644 index 57511e9..0000000 --- a/vfd-main/public/images/instruments/balance.svg +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vfd-main/public/images/instruments/distribution.svg b/vfd-main/public/images/instruments/distribution.svg new file mode 100644 index 0000000..4061720 --- /dev/null +++ b/vfd-main/public/images/instruments/distribution.svg @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3