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