amended to reflect route proto changes
This commit is contained in:
@@ -32,7 +32,7 @@ class Car constructor(routeExecutor: RouteExecutor, controller: Control) {
|
||||
}
|
||||
|
||||
fun stopCar() {
|
||||
move(MoveDirection.STOP, 0.0, {})
|
||||
move(MoveDirection.STOP, 0, {})
|
||||
}
|
||||
|
||||
fun refreshLocation(delta: Int) {
|
||||
@@ -59,7 +59,7 @@ class Car constructor(routeExecutor: RouteExecutor, controller: Control) {
|
||||
controller.stopCar()
|
||||
}
|
||||
|
||||
fun move(moveDirection: MoveDirection, value: Double, callBack: () -> Unit) {
|
||||
fun move(moveDirection: MoveDirection, value: Int, callBack: () -> Unit) {
|
||||
//value - angle for rotation command and distance for forward/backward command
|
||||
val functionAfterStty = { error: dynamic, stdOut: dynamic, stdErr: dynamic ->
|
||||
if (error != null) {
|
||||
@@ -86,7 +86,7 @@ class Car constructor(routeExecutor: RouteExecutor, controller: Control) {
|
||||
|
||||
}
|
||||
|
||||
fun getTimeForMoving(value: Double, velocity: Double): Int {
|
||||
return (1000 * Math.abs(value) / velocity).toInt()
|
||||
fun getTimeForMoving(value: Int, velocity: Double): Int {
|
||||
return (1000 * Math.abs(value.toDouble()) / velocity).toInt()
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,8 @@ class MicroController private constructor() {
|
||||
connectToServer(serverIp, serverPort)
|
||||
}
|
||||
|
||||
this.transportFilePath = "./temp"//todo need init
|
||||
this.transportFilePath = "./testTtyAcm"//todo need init
|
||||
mcTransport.initStreams(transportFilePath)
|
||||
|
||||
setInterval({ this.car.refreshLocation(deltaTimeLocationRefresh) }, deltaTimeLocationRefresh);
|
||||
setInterval({
|
||||
@@ -61,7 +62,7 @@ class MicroController private constructor() {
|
||||
if (sid != this.rcSid) {
|
||||
throw RcControlException()
|
||||
}
|
||||
car.move(command, 0.0, {})
|
||||
car.move(command, 0, {})
|
||||
rcHeartBeat(sid)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package carControl
|
||||
|
||||
import Car
|
||||
import RouteRequest
|
||||
|
||||
/**
|
||||
* Created by user on 7/27/16.
|
||||
*/
|
||||
interface RouteExecutor {
|
||||
|
||||
fun executeRoute(route: dynamic)
|
||||
fun executeRoute(route: RouteRequest)
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package carControl
|
||||
|
||||
import RouteRequest
|
||||
|
||||
/**
|
||||
* Created by user on 7/27/16.
|
||||
@@ -14,13 +15,14 @@ class RouteExecutorImpl : RouteExecutor {
|
||||
STOP
|
||||
}
|
||||
|
||||
override fun executeRoute(route: dynamic) {
|
||||
val wayPoints = route.way_points
|
||||
val commands: MutableList<Pair<MoveDirection, Double>> = mutableListOf()
|
||||
for (wayPoint in wayPoints) {
|
||||
val angle: Double = wayPoint.angle_delta
|
||||
val distance: Double = wayPoint.distance
|
||||
if (angle != 0.0) {
|
||||
override fun executeRoute(route: RouteRequest) {
|
||||
val angles = route.angles
|
||||
val distances = route.distances
|
||||
val commands: MutableList<Pair<MoveDirection, Int>> = mutableListOf()
|
||||
for (i in 0..angles.size - 1) {
|
||||
val angle: Int = angles[i]
|
||||
val distance: Int = distances[i]
|
||||
if (angle != 0) {
|
||||
val command = if (angle > 180) {
|
||||
MoveDirection.RIGHT
|
||||
} else {
|
||||
@@ -28,7 +30,7 @@ class RouteExecutorImpl : RouteExecutor {
|
||||
}
|
||||
commands.add(Pair(command, angle))
|
||||
}
|
||||
if (distance != 0.0) {
|
||||
if (distance != 0) {
|
||||
val command = if (distance > 0) {
|
||||
MoveDirection.FORWARD
|
||||
} else {
|
||||
@@ -37,11 +39,11 @@ class RouteExecutorImpl : RouteExecutor {
|
||||
commands.add(Pair(command, distance))
|
||||
}
|
||||
}
|
||||
commands.add(Pair(MoveDirection.STOP, 0.0))
|
||||
commands.add(Pair(MoveDirection.STOP, 0))
|
||||
executeCommand(commands, 0)
|
||||
}
|
||||
|
||||
fun executeCommand(commands: List<Pair<MoveDirection, Double>>, currentCommandIdx: Int) {
|
||||
fun executeCommand(commands: List<Pair<MoveDirection, Int>>, currentCommandIdx: Int) {
|
||||
if (currentCommandIdx == commands.size) {
|
||||
MicroController.instance.car.routeDone()
|
||||
}
|
||||
|
||||
@@ -19,12 +19,9 @@ class SetRoute : AbstractHandler {
|
||||
|
||||
override fun getBytesResponse(data: ByteArray, callback: (ByteArray) -> Unit) {
|
||||
val car = MicroController.instance.car
|
||||
|
||||
val message = fromServerObjectBuilder.build()
|
||||
message.mergeFrom(CodedInputStream(data))
|
||||
|
||||
car.routeExecutor.executeRoute(message)
|
||||
|
||||
val responseMessage = toServerObjectBuilder.setCode(0).build()
|
||||
val resultByteArray = ByteArray(responseMessage.getSizeNoTag())
|
||||
responseMessage.writeTo(CodedOutputStream(resultByteArray))
|
||||
|
||||
Reference in New Issue
Block a user