From 68119166bb4c716ff29ddb47e03ce65c82433c57 Mon Sep 17 00:00:00 2001 From: Felix Agner <felix.agner@control.lth.se> Date: Wed, 9 Nov 2022 10:59:31 +0100 Subject: [PATCH] cleaned up and added max-speed function --- src/Omnibot.jl | 1 + src/connectomnibot.jl | 2 - src/getcoordinates.jl | 123 ++++++++++++++++++++---------------------- src/setspeeds.jl | 6 +-- 4 files changed, 60 insertions(+), 72 deletions(-) diff --git a/src/Omnibot.jl b/src/Omnibot.jl index 92b4229..7c45a50 100644 --- a/src/Omnibot.jl +++ b/src/Omnibot.jl @@ -6,6 +6,7 @@ export gety export getz export gettheta +using Sockets include("connectomnibot.jl") include("setspeeds.jl") include("getcoordinates.jl") diff --git a/src/connectomnibot.jl b/src/connectomnibot.jl index 9c27ea8..723e2fe 100644 --- a/src/connectomnibot.jl +++ b/src/connectomnibot.jl @@ -1,5 +1,3 @@ -using Sockets - """ connectomnibot(ip::String;port::Int=9998) diff --git a/src/getcoordinates.jl b/src/getcoordinates.jl index 83d15c2..153c4f4 100644 --- a/src/getcoordinates.jl +++ b/src/getcoordinates.jl @@ -1,92 +1,83 @@ -using Sockets - """ -getx(bot::TCPSocket) + getx(bot::TCPSocket) Returns the x-coordinate of the omnibot as `Float64`. """ -function getx(bot::TCPSocket;) -msg = "rx" -print(bot,msg) -ret = readline(bot) -if msg[1] == 'e' - error(ret) -end -try - return parse(ret,Float64) -catch e - if isa(e, ArgumentError) - throw(ArgumentError("Received $ret from the bot, which is not a valid float.")) +function getx(bot::TCPSocket) + msg = "rx" + 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 - -end """ -gety(bot::TCPSocket) + gety(bot::TCPSocket) Returns the y-coordinate of the omnibot as `Float64`. """ -function gety(bot::TCPSocket;) -msg = "ry" -print(bot,msg) -ret = readline(bot) -if msg[1] == 'e' - error(ret) -end -try - return parse(ret,Float64) -catch e - if isa(e, ArgumentError) - throw(ArgumentError("Received $ret from the bot, which is not a valid float.")) +function gety(bot::TCPSocket) + msg = "ry" + 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 - - end """ -getz(bot::TCPSocket) + getz(bot::TCPSocket) Returns the z-coordinate of the omnibot as `Float64`. """ -function getz(bot::TCPSocket;) -msg = "rz" -print(bot,msg) -ret = readline(bot) -if msg[1] == 'e' - error(ret) -end -try - return parse(ret,Float64) -catch e - if isa(e, ArgumentError) - throw(ArgumentError("Received $ret from the bot, which is not a valid float.")) +function getz(bot::TCPSocket) + msg = "rz" + 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 - - end """ -gettheta(bot::TCPSocket) + getmaxspeed(bot::TCPSocket) -Returns the ``θ``-coordinate of the omnibot as `Float64`. +Returns the max servo set-point speed for the omnibot as `Int`. """ -function gettheta(bot::TCPSocket;) -msg = "rtheta" -print(bot,msg) -ret = readline(bot) -if msg[1] == 'e' - error(ret) -end -try - return parse(ret,Float64) -catch e - if isa(e, ArgumentError) - throw(ArgumentError("Received $ret from the bot, which is not a valid float.")) +function getmaxspeed(bot::TCPSocket) + msg = "rmaxspeed" + print(bot,msg) + ret = readline(bot) + if msg[1] == 'e' + error(ret) + end + try + return parse(Int,ret) + catch e + if isa(e, ArgumentError) + throw(ArgumentError("Received $ret from the bot, which is not a valid float.")) + end end -end - - end \ No newline at end of file diff --git a/src/setspeeds.jl b/src/setspeeds.jl index e1c8486..0ca1053 100644 --- a/src/setspeeds.jl +++ b/src/setspeeds.jl @@ -1,7 +1,5 @@ -using Sockets - """ -setspeed(bot::TCPSocket,i::Int,v::Int) + setspeed(bot::TCPSocket,i::Int,v::Int) sets the speed of servo `i` to `v`. @@ -22,7 +20,7 @@ return ret end """ -setspeeds(bot::TCPSocket,v::Vector{Int}) + setspeeds(bot::TCPSocket,v::Vector{Int}) Set the speed-setpoint of servos to the values in vector v. """ -- GitLab