diff --git a/src/bin/GPS.hx b/src/bin/GPS.hx index 0acc230..9009a13 100644 --- a/src/bin/GPS.hx +++ b/src/bin/GPS.hx @@ -39,7 +39,7 @@ class GPS extends CLIAppBase { handle.writeLine("Accuracy: High"); } - var ins = INS.instance.getHeading(); + var ins = INS.getHeading(); if (ins != null) { handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}'); } else { @@ -61,7 +61,7 @@ class GPS extends CLIAppBase { }); registerAsyncSubcommand("ins",(args)->{ - return INS.instance.align().map((_)->{ + return INS.align().map((_)->{ handle.writeLine("INS aligned"); return true; }); diff --git a/src/kernel/Init.hx b/src/kernel/Init.hx index 454c22b..11e0b80 100644 --- a/src/kernel/Init.hx +++ b/src/kernel/Init.hx @@ -38,7 +38,6 @@ class Init { Net.init(); GPS.init(); - INS.instance = new INS(); // Register default terminate handler KernelEvents.onTerminate.handle(_->{ diff --git a/src/kernel/gps/INS.hx b/src/kernel/gps/INS.hx index 99768b7..6b7d4dd 100644 --- a/src/kernel/gps/INS.hx +++ b/src/kernel/gps/INS.hx @@ -7,46 +7,39 @@ import lib.Pos3; using tink.CoreApi; class INS { - public static var instance:INS; - - private var heading: Null = null; - private var alingment: Int = 1; // 0 = degraded, 1 = not aligned, 2 = aligned - - @:allow(kernel.Init) - private function new() { - - } + private static var heading: Null = null; + private static var alingment: Int = 1; // 0 = degraded, 1 = not aligned, 2 = aligned @:allow(kernel.turtle.Turtle) - private function moveForward() { + private static function moveForward() { if (heading == null) { - this.alingment = 0; + alingment = 0; return; } move(heading); } @:allow(kernel.turtle.Turtle) - private function moveBackward() { + private static function moveBackward() { if (heading == null) { - this.alingment = 0; + alingment = 0; return; } move(heading.negate()); } @:allow(kernel.turtle.Turtle) - private function moveUp() { + private static function moveUp() { move({x: 0, y: 1, z: 0}); } @:allow(kernel.turtle.Turtle) - private function moveDown() { + private static function moveDown() { move({x: 0, y: -1, z: 0}); } @:allow(kernel.turtle.Turtle) - private function turnLeft() { + private static function turnLeft() { if (heading == null) return; if (heading.x == 0 && heading.z == -1) { heading = {x: -1, y: 0, z: 0}; @@ -60,7 +53,7 @@ class INS { } @:allow(kernel.turtle.Turtle) - private function turnRight() { + private static function turnRight() { if (heading == null) return; if (heading.x == 0 && heading.z == -1) { heading = {x: 1, y: 0, z: 0}; @@ -73,18 +66,18 @@ class INS { } } - private function move(dir: Null) { + private static function move(dir: Null) { Log.debug('INS move: $dir'); var pos = GPS.getPosition(); var newPos = pos + dir; GPS.setINSPosition(newPos); } - public function getHeading():Null { + public static function getHeading():Null { return heading; } - public function align(): Promise { + public static function align(): Promise { Log.info("Aligning INS"); return new Promise((resolve,reject)->{ @@ -118,14 +111,14 @@ class INS { return; } - var heading = calcHeading(pos1,pos2,moved); - if (heading == null) { + var cHeading = calcHeading(pos1,pos2,moved); + if (cHeading == null) { Log.error("Can't calculate heading"); reject(new Error("Can't calculate heading")); return; } - this.heading = heading; + heading = cHeading; moveBack(moved); GPS.setINSPosition(pos1); @@ -138,7 +131,7 @@ class INS { } // -1 = not moved, 0 = back, 1 = forward, 2 = left, 3 = right - private function tryMoving():Int { + private static function tryMoving():Int { if (Turtle.instance.back().isSuccess()) { return 0; } else if (Turtle.instance.forward().isSuccess()) { @@ -156,7 +149,7 @@ class INS { } } - private function calcHeading(pos1: Pos3,pos2:Pos3,moved:Int): Null { + private static function calcHeading(pos1: Pos3,pos2:Pos3,moved:Int): Null { if (moved == 0) { return pos1 - pos2; } else if (moved == 1) { @@ -170,7 +163,7 @@ class INS { } } - private function moveBack(moved:Int) { + private static function moveBack(moved:Int) { if (moved == 0) { Turtle.instance.forward(); // cc.Turtle.forward(); @@ -190,7 +183,7 @@ class INS { } } - private function rotatePos3ToRight(pos:Pos3):Pos3 { + private static function rotatePos3ToRight(pos:Pos3):Pos3 { if (pos.x == 0 && pos.z == -1) { return {x: 1, y: 0, z: 0}; } else if (pos.x == -1 && pos.z == 0) { @@ -204,7 +197,7 @@ class INS { } } - private function rotatePos3ToLeft(pos3:Pos3):Pos3 { + private static function rotatePos3ToLeft(pos3:Pos3):Pos3 { return rotatePos3ToRight(rotatePos3ToRight(rotatePos3ToRight(pos3))); } diff --git a/src/kernel/turtle/Turtle.hx b/src/kernel/turtle/Turtle.hx index 56f3be1..52802a7 100644 --- a/src/kernel/turtle/Turtle.hx +++ b/src/kernel/turtle/Turtle.hx @@ -36,42 +36,42 @@ class Turtle { public function forward():Outcome { var r = cc.Turtle.forward(); var r2 = conterToOutcome(r); - if (r2.isSuccess()) INS.instance.moveForward(); + if (r2.isSuccess()) INS.moveForward(); return r2; } public function back():Outcome { var r = cc.Turtle.back(); var r2 = conterToOutcome(r); - if (r2.isSuccess()) INS.instance.moveBackward(); + if (r2.isSuccess()) INS.moveBackward(); return r2; } public function up():Outcome { var r = cc.Turtle.up(); var r2 = conterToOutcome(r); - if (r2.isSuccess()) INS.instance.moveUp(); + if (r2.isSuccess()) INS.moveUp(); return r2; } public function down():Outcome { var r = cc.Turtle.down(); var r2 = conterToOutcome(r); - if (r2.isSuccess()) INS.instance.moveDown(); + if (r2.isSuccess()) INS.moveDown(); return r2; } public function turnLeft():Outcome { var r = cc.Turtle.turnLeft(); var r2 = conterToOutcome(r); - if (r2.isSuccess()) INS.instance.turnRight(); + if (r2.isSuccess()) INS.turnRight(); return r2; } public function turnRight():Outcome { var r = cc.Turtle.turnRight(); var r2 = conterToOutcome(r); - if (r2.isSuccess()) INS.instance.turnRight(); + if (r2.isSuccess()) INS.turnRight(); return r2; }