car_srv: fix rotation angle
This commit is contained in:
@@ -73,7 +73,6 @@ object Control {
|
|||||||
val attempts = request.attempts
|
val attempts = request.attempts
|
||||||
val distances = IntArray(size)
|
val distances = IntArray(size)
|
||||||
|
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < size) {
|
while (i < size) {
|
||||||
distances[i] = sonarMeasure(request.smoothing, attempts[i], angles[i], request.windowSize)
|
distances[i] = sonarMeasure(request.smoothing, attempts[i], angles[i], request.windowSize)
|
||||||
@@ -89,11 +88,9 @@ object Control {
|
|||||||
var i = 0
|
var i = 0
|
||||||
while (i < attempts) {
|
while (i < attempts) {
|
||||||
data[i] = Sonar.getSmoothDistance(angle, windowSize)
|
data[i] = Sonar.getSmoothDistance(angle, windowSize)
|
||||||
|
|
||||||
if (smoothing.id == SonarRequest.Smoothing.NONE.id && data[i] != -1) {
|
if (smoothing.id == SonarRequest.Smoothing.NONE.id && data[i] != -1) {
|
||||||
return data[i]
|
return data[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Generated
+4
@@ -18,5 +18,9 @@
|
|||||||
<processorPath useClasspath="true" />
|
<processorPath useClasspath="true" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="server_main" target="1.5" />
|
||||||
|
<module name="server_test" target="1.5" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="useAutoImport" value="true" />
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
Generated
+2
-2
@@ -13,8 +13,8 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</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">
|
<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$/out" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="masterDetails">
|
<component name="masterDetails">
|
||||||
<states>
|
<states>
|
||||||
|
|||||||
Generated
+2
@@ -3,6 +3,8 @@
|
|||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<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.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>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+1
-24
@@ -1,35 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<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">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<output url="file://$MODULE_DIR$/../../build/classes/main" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/../../build/classes/test" />
|
|
||||||
<exclude-output />
|
<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$/../..">
|
<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$/../../.gradle" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../../build" />
|
<excludeFolder url="file://$MODULE_DIR$/../../build" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<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>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -24,12 +24,12 @@ class CarController(var car: Car) {
|
|||||||
private var angle = 0.0
|
private var angle = 0.0
|
||||||
|
|
||||||
fun moveTo(to: Pair<Double, Double>) {
|
fun moveTo(to: Pair<Double, Double>) {
|
||||||
val oldAngle = angle
|
var driveAngle = (Math.toDegrees(Math.atan2(to.first, to.second)) + 360) % 360
|
||||||
rotateOn(estimateAngle(position, to))
|
rotateOn(angleDistance(angle, driveAngle))
|
||||||
drive(Direction.FORWARD, Math.max(0.0, distance(position, to)).toInt() - WALL_DISTANCE)
|
drive(Direction.FORWARD, Math.max(0.0, distance(position, to)).toInt() - WALL_DISTANCE)
|
||||||
rotateOn(oldAngle)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
position = to
|
||||||
|
}
|
||||||
|
|
||||||
fun rotateOn(target: Double) {
|
fun rotateOn(target: Double) {
|
||||||
val rotateAngle = angleDistance(angle, target)
|
val rotateAngle = angleDistance(angle, target)
|
||||||
@@ -46,7 +46,7 @@ class CarController(var car: Car) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun scan(angles: IntArray): List<Pair<Double, Double>> {
|
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 data = serialize(request.getSizeNoTag(), { i -> request.writeTo(i) })
|
||||||
val response = CarClient.sendRequest(car, CarClient.Request.SONAR, data).get().responseBodyAsBytes
|
val response = CarClient.sendRequest(car, CarClient.Request.SONAR, data).get().responseBodyAsBytes
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
package RoomScanner
|
package RoomScanner
|
||||||
|
|
||||||
class RoomScanner(val controller: CarController): Thread() {
|
class RoomScanner(val controller: CarController) : Thread() {
|
||||||
private val points = mutableListOf<Pair<Double, Double>>()
|
private val points = mutableListOf<Pair<Double, Double>>()
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
println("Car connected ${controller.car.host}")
|
||||||
while (true) {
|
while (true) {
|
||||||
scan()
|
scan()
|
||||||
println("[${points.joinToString { "[${it.first}, ${it.second}]" }}}]")
|
println(plot(points))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scan() {
|
private fun scan() {
|
||||||
val horizon = IntArray(180 / 5, { it * 5 })
|
val horizon = IntArray(180 / 5, { it * 5 })
|
||||||
val iterationPoints = mutableListOf<Pair<Double, Double>>()
|
val iterationPoints = mutableListOf<Pair<Double, Double>>()
|
||||||
|
|
||||||
@@ -27,4 +28,6 @@ class RoomScanner(val controller: CarController): Thread() {
|
|||||||
controller.moveTo(target)
|
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() }})"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ import java.net.ConnectException
|
|||||||
import java.rmi.UnexpectedException
|
import java.rmi.UnexpectedException
|
||||||
|
|
||||||
object Client {
|
object Client {
|
||||||
val group = NioEventLoopGroup()
|
private val group = NioEventLoopGroup()
|
||||||
val bootstrap = makeBootstrap()
|
private val bootstrap = makeBootstrap()
|
||||||
val client = DefaultAsyncHttpClient()
|
private val client = DefaultAsyncHttpClient()
|
||||||
|
private val timeout = 5 * 60 * 60 * 1000
|
||||||
|
|
||||||
fun shutDownClient() {
|
fun shutDownClient() {
|
||||||
group.shutdownGracefully()
|
group.shutdownGracefully()
|
||||||
@@ -38,7 +39,7 @@ object Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun makeRequest(request: String, data: ByteArray): ListenableFuture<Response> =
|
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 {
|
private fun makeBootstrap(): Bootstrap {
|
||||||
val b = Bootstrap()
|
val b = Bootstrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user