From 11913e8a3427aedc904bf4f00f0a5369e5d2a10b Mon Sep 17 00:00:00 2001
From: Felix Agner <felix.agner@control.lth.se>
Date: Wed, 9 Nov 2022 14:54:57 +0100
Subject: [PATCH] bug fixes again

---
 src/getcoordinates.jl | 21 +++++++++++++++++++++
 test/testclient.jl    | 11 ++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/getcoordinates.jl b/src/getcoordinates.jl
index 153c4f4..3c6e86c 100644
--- a/src/getcoordinates.jl
+++ b/src/getcoordinates.jl
@@ -61,6 +61,27 @@ function getz(bot::TCPSocket)
     end
 end
 
+"""
+    gettheta(bot::TCPSocket)
+
+Returns the ``θ``-coordinate of the omnibot as `Float64`.
+"""
+function gettheta(bot::TCPSocket)
+    msg = "rtheta"
+    print(bot,msg)
+    ret = readline(bot)
+    if msg[1] == 'e'
+        error(ret)
+    end
+    try
+        return parse(Float64,ret)
+    catch e
+        if isa(e, ArgumentError)
+            throw(ArgumentError("Received $ret from the bot, which is not a valid float."))
+        end
+    end
+end
+
 """
     getmaxspeed(bot::TCPSocket)
 
diff --git a/test/testclient.jl b/test/testclient.jl
index bdca29d..d56fcd7 100644
--- a/test/testclient.jl
+++ b/test/testclient.jl
@@ -1,14 +1,15 @@
 using Omnibot
+using Sockets
 
-ip = "192.168.0.101"
+ip = getipaddr()
 bot = connectomnibot(ip)
 
 for i = 1:100
     setspeed(bot,[100,100,100])
-    println("x:"*getx(bot))
-    println("y:"*gety(bot))
-    println("z:"*getz(bot))
-    println("theta:"*gettheta(bot))
+    println("x:"*string(getx(bot)))
+    println("y:"*string(gety(bot)))
+    println("z:"*string(getz(bot)))
+    println("theta:"*string(gettheta(bot)))
     sleep(0.1)
 end
 
-- 
GitLab