fixed bug with moving car

This commit is contained in:
MaximZaitsev
2016-08-23 12:47:34 +03:00
parent e7120103ee
commit bab24b47d1
3 changed files with 8 additions and 5 deletions
+6 -2
View File
@@ -12,8 +12,12 @@ class CarState private constructor() {
//if distance is positive - move forward, else backward
fun moving(distance: Int) {
x += (Math.cos(angle.toDouble()) * distance).toInt()
y += (Math.sin(angle.toDouble()) * distance).toInt()
x += (Math.cos(degreesToRadian(angle)) * distance).toInt()
y += (Math.sin(degreesToRadian(angle)) * distance).toInt()
}
private fun degreesToRadian(angleInDegrees: Int): Double {
return Math.PI * angleInDegrees / 180
}
//angle positive - rotation left
@@ -158,8 +158,8 @@ class ControllerEmulator : Controller {
when (currentCommand.first) {
MoveDirection.FORWARD -> carInstance.moving((commandTimeIncludeRandom * MOVE_VELOCITY).toInt() / 1000)
MoveDirection.BACKWARD -> carInstance.moving(-(commandTimeIncludeRandom * MOVE_VELOCITY).toInt() / 1000)
MoveDirection.RIGHT -> carInstance.rotate((commandTimeIncludeRandom * ROTATION_VELOCITY).toInt() / 1000)
MoveDirection.LEFT -> carInstance.rotate(-(commandTimeIncludeRandom * ROTATION_VELOCITY).toInt() / 1000)
MoveDirection.RIGHT -> carInstance.rotate(-(commandTimeIncludeRandom * ROTATION_VELOCITY).toInt() / 1000)
MoveDirection.LEFT -> carInstance.rotate((commandTimeIncludeRandom * ROTATION_VELOCITY).toInt() / 1000)
else -> {
}
}
@@ -30,7 +30,6 @@ class GetSonarData : AbstractHandler {
callback.invoke(encodeProtoBuf(responseMessage))
return
}
println("sonar")
controller.executeRequestSensorData(message, callback)
}
}