corrected constants, corrected moving in outer angle
This commit is contained in:
@@ -17,6 +17,7 @@ class AlgorithmThread(val algorithmImpl: AbstractAlgorithm) : Thread() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println("algorithm is finished!")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCount(count: Int) {
|
fun setCount(count: Int) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
override val WINDOW_SIZE = 3
|
override val WINDOW_SIZE = 3
|
||||||
|
|
||||||
//SHOULD BE CALIBRATED BEFORE RUNNING!!!!!!!!!!!
|
//SHOULD BE CALIBRATED BEFORE RUNNING!!!!!!!!!!!
|
||||||
private val CHARGE_CORRECTION = 0.88//on full charge ok is 0.83 - 0.86
|
private val CHARGE_CORRECTION = 0.87//on full charge ok is 0.83 - 0.86
|
||||||
|
|
||||||
private val MAX_DISTANCE_TO_WALL_AHEAD = 55 // reached the corner and should turn left
|
private val MAX_DISTANCE_TO_WALL_AHEAD = 55 // reached the corner and should turn left
|
||||||
private val OUTER_CORNER_DISTANCE_THRESHOLD = 90 // reached outer corner
|
private val OUTER_CORNER_DISTANCE_THRESHOLD = 90 // reached outer corner
|
||||||
@@ -25,7 +25,7 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
private val DISTANCE_TO_WALL_UPPER_BOUND = 60 // have to move closer to the parallel wall
|
private val DISTANCE_TO_WALL_UPPER_BOUND = 60 // have to move closer to the parallel wall
|
||||||
private val DISTANCE_TO_WALL_LOWER_BOUND = 40 // have to move farther to the parallel wall
|
private val DISTANCE_TO_WALL_LOWER_BOUND = 40 // have to move farther to the parallel wall
|
||||||
private val SPURIOUS_REFLECTION_DIFF = 70 // we're approaching corner and get spurious reflection from two walls on 60 meas. ! Should be before outer corner case !
|
private val SPURIOUS_REFLECTION_DIFF = 70 // we're approaching corner and get spurious reflection from two walls on 60 meas. ! Should be before outer corner case !
|
||||||
private val RANGE_FROM_ZERO_POINT_TO_FINISH_ALG = 50
|
private val RANGE_FROM_ZERO_POINT_TO_FINISH_ALG = 60
|
||||||
|
|
||||||
private var calibrateAfterRotate = false
|
private var calibrateAfterRotate = false
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
val resultBuilder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0))
|
val resultBuilder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0))
|
||||||
resultBuilder.setDirections(getIntArray(FORWARD, RIGHT, FORWARD))
|
resultBuilder.setDirections(getIntArray(FORWARD, RIGHT, FORWARD))
|
||||||
val wallAngle = calculateAngle(anglesDistances, state)
|
val wallAngle = calculateAngle(anglesDistances, state)
|
||||||
resultBuilder.setDistances(getIntArray(15, wallAngle.degs(), 70))
|
resultBuilder.setDistances(getIntArray(40, wallAngle.degs(), 75))
|
||||||
addWall(-wallAngle)
|
addWall(-wallAngle)
|
||||||
carAngle = RoomModel.walls.last().wallAngleOX.degs()
|
carAngle = RoomModel.walls.last().wallAngleOX.degs()
|
||||||
calibrateAfterRotate = true
|
calibrateAfterRotate = true
|
||||||
@@ -100,21 +100,23 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
private fun correctDistanceToParallelWall(anglesDistances: Map<Angle, AngleData>, state: CarState): RouteMetricRequest {
|
private fun correctDistanceToParallelWall(anglesDistances: Map<Angle, AngleData>, state: CarState): RouteMetricRequest {
|
||||||
val resultBuilder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0))
|
val resultBuilder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0))
|
||||||
|
|
||||||
val rotationDirection = if (anglesDistances[Angle(90)]!!.distance > 50) RIGHT else LEFT
|
val distToWall = anglesDistances[Angle(90)]!!.distance
|
||||||
|
val rotationDirection = if (distToWall > DISTANCE_TO_WALL_UPPER_BOUND) RIGHT else LEFT
|
||||||
val backRotationDirection = if (rotationDirection == RIGHT) LEFT else RIGHT
|
val backRotationDirection = if (rotationDirection == RIGHT) LEFT else RIGHT
|
||||||
resultBuilder.setDirections(getIntArray(rotationDirection, FORWARD, backRotationDirection))
|
resultBuilder.setDirections(getIntArray(rotationDirection, FORWARD, backRotationDirection))
|
||||||
resultBuilder.setDistances(getIntArray(15, 20, 5))
|
val rangeToCorridor = if (distToWall > DISTANCE_TO_WALL_UPPER_BOUND) {
|
||||||
|
distToWall - DISTANCE_TO_WALL_UPPER_BOUND
|
||||||
|
} else {
|
||||||
|
DISTANCE_TO_WALL_LOWER_BOUND - distToWall
|
||||||
|
}
|
||||||
|
resultBuilder.setDistances(getIntArray(2 * rangeToCorridor + 5, 20, (1.5 * rangeToCorridor).toInt()))
|
||||||
return resultBuilder.build()
|
return resultBuilder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveForward(distToWall: Int): RouteMetricRequest {
|
private fun moveForward(distToWall: Int): RouteMetricRequest {
|
||||||
val resultBuilder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0))
|
val resultBuilder = RouteMetricRequest.BuilderRouteMetricRequest(IntArray(0), IntArray(0))
|
||||||
resultBuilder.setDirections(getIntArray(FORWARD))
|
resultBuilder.setDirections(getIntArray(FORWARD))
|
||||||
if (distToWall == -1 || distToWall > 200) {
|
resultBuilder.setDistances(getIntArray(Math.max(distToWall / 4, 20)))
|
||||||
resultBuilder.setDistances(getIntArray(70))
|
|
||||||
} else {
|
|
||||||
resultBuilder.setDistances(getIntArray(Math.max(distToWall / 4, 20)))
|
|
||||||
}
|
|
||||||
return resultBuilder.build()
|
return resultBuilder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,16 +210,6 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Approaching inner corner and getting spurious reflection from 2 walls on 60 - just move forward to get closer to corner
|
// Approaching inner corner and getting spurious reflection from 2 walls on 60 - just move forward to get closer to corner
|
||||||
// if (dist70.distance - dist0.distance > SPURIOUS_REFLECTION_DIFF) {
|
|
||||||
// log("Spurious reflection detected, moving forward")
|
|
||||||
// return moveForward()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Approaching outer corner (parallel wall is ending soon, but not yet) - just move forward to get to the end of the wall
|
|
||||||
// if (dist80.distance == -1 || Math.abs(dist100.distance - dist80.distance) > ISOSCALENESS_MAX_DIFF) {
|
|
||||||
// log("Aprroaching outer corner, moving forward")
|
|
||||||
// return moveForward()
|
|
||||||
// }
|
|
||||||
|
|
||||||
for (i in 70..110 step 10) {
|
for (i in 70..110 step 10) {
|
||||||
if (i == 90) {
|
if (i == 90) {
|
||||||
@@ -248,6 +240,17 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
return correctDistanceToParallelWall(anglesDistances, state)
|
return correctDistanceToParallelWall(anglesDistances, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dist70.distance - dist0.distance > SPURIOUS_REFLECTION_DIFF) {
|
||||||
|
log("Spurious reflection detected, moving forward")
|
||||||
|
return moveForward(dist0.distance)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Approaching outer corner (parallel wall is ending soon, but not yet) - just move forward to get to the end of the wall
|
||||||
|
if (dist80.distance == -1 || Math.abs(dist100.distance - dist80.distance) > ISOSCALENESS_MAX_DIFF) {
|
||||||
|
log("Aprroaching outer corner, moving forward")
|
||||||
|
return moveForward(30)
|
||||||
|
}
|
||||||
|
|
||||||
// default case: everything is ok, just move forward
|
// default case: everything is ok, just move forward
|
||||||
log("Default case: moving forward")
|
log("Default case: moving forward")
|
||||||
return moveForward(dist0.distance)
|
return moveForward(dist0.distance)
|
||||||
@@ -278,11 +281,11 @@ class RoomBypassingAlgorithm(thisCar: Car, exchanger: Exchanger<IntArray>) : Abs
|
|||||||
carY -= (Math.sin(degreesToRadian(carAngle.toInt())) * route.distances[idx]).toInt()
|
carY -= (Math.sin(degreesToRadian(carAngle.toInt())) * route.distances[idx]).toInt()
|
||||||
}
|
}
|
||||||
LEFT -> {
|
LEFT -> {
|
||||||
// route.distances[idx] = (CHARGE_CORRECTION * route.distances[idx]).toInt()
|
route.distances[idx] = (CHARGE_CORRECTION * route.distances[idx]).toInt()
|
||||||
// carAngle += route.distances[idx]
|
// carAngle += route.distances[idx]
|
||||||
}
|
}
|
||||||
RIGHT -> {
|
RIGHT -> {
|
||||||
// route.distances[idx] = (CHARGE_CORRECTION * route.distances[idx]).toInt()
|
route.distances[idx] = (CHARGE_CORRECTION * route.distances[idx]).toInt()
|
||||||
// carAngle -= route.distances[idx]
|
// carAngle -= route.distances[idx]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user