car_srv: fix rotation angle

This commit is contained in:
e5l
2016-08-30 12:14:39 +03:00
parent e4474f774c
commit 8030c745e7
9 changed files with 26 additions and 42 deletions
-3
View File
@@ -73,7 +73,6 @@ object Control {
val attempts = request.attempts
val distances = IntArray(size)
var i = 0
while (i < size) {
distances[i] = sonarMeasure(request.smoothing, attempts[i], angles[i], request.windowSize)
@@ -89,11 +88,9 @@ object Control {
var i = 0
while (i < attempts) {
data[i] = Sonar.getSmoothDistance(angle, windowSize)
if (smoothing.id == SonarRequest.Smoothing.NONE.id && data[i] != -1) {
return data[i]
}
i++
}
+4
View File
@@ -18,5 +18,9 @@
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="server_main" target="1.5" />
<module name="server_test" target="1.5" />
</bytecodeTargetLevel>
</component>
</project>
+1 -1
View File
@@ -11,7 +11,7 @@
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useAutoImport" value="true" />
</GradleProjectSettings>
</option>
</component>
+2 -2
View File
@@ -13,8 +13,8 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="masterDetails">
<states>
+2
View File
@@ -3,6 +3,8 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/server.iml" filepath="$PROJECT_DIR$/.idea/modules/server.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/server_main.iml" filepath="$PROJECT_DIR$/.idea/modules/server_main.iml" group="server" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/server_test.iml" filepath="$PROJECT_DIR$/.idea/modules/server_test.iml" group="server" />
</modules>
</component>
</project>
+1 -24
View File
@@ -1,35 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="server" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="server" external.system.module.version="1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../../build/classes/main" />
<output-test url="file://$MODULE_DIR$/../../build/classes/test" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/../../../proto">
<sourceFolder url="file://$MODULE_DIR$/../../../proto/protofiles_sources/out" isTestSource="false" />
</content>
<content url="file://$MODULE_DIR$/../..">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/kotlin" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/../../.gradle" />
<excludeFolder url="file://$MODULE_DIR$/../../build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.0.3" level="project" />
<orderEntry type="module-library">
<library name="Gradle: protokot-runtime">
<CLASSES>
<root url="jar://$MODULE_DIR$/../../../proto/compiler/build/protokot-runtime.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Gradle: io.netty:netty-all:4.1.2.Final" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-runtime:1.0.3" level="project" />
</component>
</module>
@@ -24,12 +24,12 @@ class CarController(var car: Car) {
private var angle = 0.0
fun moveTo(to: Pair<Double, Double>) {
val oldAngle = angle
rotateOn(estimateAngle(position, to))
var driveAngle = (Math.toDegrees(Math.atan2(to.first, to.second)) + 360) % 360
rotateOn(angleDistance(angle, driveAngle))
drive(Direction.FORWARD, Math.max(0.0, distance(position, to)).toInt() - WALL_DISTANCE)
rotateOn(oldAngle)
}
position = to
}
fun rotateOn(target: Double) {
val rotateAngle = angleDistance(angle, target)
@@ -46,7 +46,7 @@ class CarController(var car: Car) {
}
fun scan(angles: IntArray): List<Pair<Double, Double>> {
val request = SonarRequest.BuilderSonarRequest(angles, IntArray(angles.size, { 5 }), 0, SonarRequest.Smoothing.MEDIAN).build()
val request = SonarRequest.BuilderSonarRequest(angles, IntArray(angles.size, { 1 }), 10, SonarRequest.Smoothing.MEDIAN).build()
val data = serialize(request.getSizeNoTag(), { i -> request.writeTo(i) })
val response = CarClient.sendRequest(car, CarClient.Request.SONAR, data).get().responseBodyAsBytes
@@ -1,16 +1,17 @@
package RoomScanner
class RoomScanner(val controller: CarController): Thread() {
class RoomScanner(val controller: CarController) : Thread() {
private val points = mutableListOf<Pair<Double, Double>>()
override fun run() {
println("Car connected ${controller.car.host}")
while (true) {
scan()
println("[${points.joinToString { "[${it.first}, ${it.second}]" }}}]")
println(plot(points))
}
}
fun scan() {
private fun scan() {
val horizon = IntArray(180 / 5, { it * 5 })
val iterationPoints = mutableListOf<Pair<Double, Double>>()
@@ -27,4 +28,6 @@ class RoomScanner(val controller: CarController): Thread() {
controller.moveTo(target)
}
private fun plot(points: MutableList<Pair<Double, Double>>) =
"x <- c(${points.joinToString { it.first.toInt().toString() }}) \n y <- c(${points.joinToString { it.second.toInt().toString() }})"
}
+5 -4
View File
@@ -13,9 +13,10 @@ import java.net.ConnectException
import java.rmi.UnexpectedException
object Client {
val group = NioEventLoopGroup()
val bootstrap = makeBootstrap()
val client = DefaultAsyncHttpClient()
private val group = NioEventLoopGroup()
private val bootstrap = makeBootstrap()
private val client = DefaultAsyncHttpClient()
private val timeout = 5 * 60 * 60 * 1000
fun shutDownClient() {
group.shutdownGracefully()
@@ -38,7 +39,7 @@ object Client {
}
fun makeRequest(request: String, data: ByteArray): ListenableFuture<Response> =
client.preparePost(request).setBody(data).execute() ?: throw UnexpectedException(request)
client.preparePost(request).setBody(data).setRequestTimeout(timeout).execute() ?: throw UnexpectedException(request)
private fun makeBootstrap(): Bootstrap {
val b = Bootstrap()