fixed bug with moving car
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user