diff --git a/car_fmw/src/Voyager.kt b/car_fmw/src/Voyager.kt index cdb59ab889b..779991f189e 100644 --- a/car_fmw/src/Voyager.kt +++ b/car_fmw/src/Voyager.kt @@ -1,9 +1,12 @@ object Voyager { val VELOCITY_DRIVE: Double = 0.03 // centimeter in millisecond - val VEL0CITY_ROUTATE: Double = 0.001 // degree in millisecond + val VEL0CITY_ROUTATE: Double = 0.015 // degree in millisecond val SEGMENT_SIZE: Int = 30 // centimeter + val MAX_ANGLE: Int = 180 // degree + val ENGINE_DELAY: Int = 500 // milisecond + fun run() { while (true) { var distance = Sonar.getDistance(0) @@ -12,19 +15,25 @@ object Voyager { distance = Sonar.getDistance(0) } - rotate(Random.getInt()) + rotate(Random.getInt() % MAX_ANGLE) } } private fun rotate(degree: Int) { - val time = (degree.toDouble() / VELOCITY_DRIVE).toInt() + val duration = (degree.toDouble() / VELOCITY_DRIVE).toInt() Engine.left() - Time.wait(time) + Time.wait(duration) } private fun drive(direction: RouteType, distance: Int) { - val time = (distance.toDouble() / VELOCITY_DRIVE).toInt() + val duration = (distance.toDouble() / VELOCITY_DRIVE).toInt() Engine.drive(direction.id) - Time.wait(time) + Time.wait(duration) + smoothStop() + } + + private fun smoothStop() { + Engine.stop() + Time.wait(ENGINE_DELAY) } } \ No newline at end of file diff --git a/car_fmw/src/include/Random.kt b/car_fmw/src/include/Random.kt index 9756c56f8ad..2979d92f5df 100644 --- a/car_fmw/src/include/Random.kt +++ b/car_fmw/src/include/Random.kt @@ -1,6 +1,6 @@ -external fun car_random_int(): Int +external fun car_random_get_int(): Int object Random { - fun getInt(): Int = car_random_int() + fun getInt(): Int = car_random_get_int() } diff --git a/car_fmw/src/main.kt b/car_fmw/src/main.kt index ec66dda6298..65d6f22cd38 100644 --- a/car_fmw/src/main.kt +++ b/car_fmw/src/main.kt @@ -10,7 +10,7 @@ fun main() { Leds.set(Leds.GREEN, true) /* car task */ - Control.run() +// Control.run() /* Voyager */ Voyager.run()