diff --git a/src/Omnibot.jl b/src/Omnibot.jl index 92b42294bc334fa62a633dba18eee40e4862ecbc..7c45a5060c2dc4862f2f342ef020e2a65e059d9b 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 9c27ea8961f4a39dce0b8c257b086dfd956a05d9..723e2fe4984f301f103ff945c187a40212492ed9 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 83d15c28ee7256d28dd33cd93055b858034631bd..153c4f4a22b42b5c7a97c5477f6a5ace5f6b01fb 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 e1c848637ff71c6596adf1100aee5141ae69b716..0ca1053676441a7e2eb85ffbd27c2f9cafb23912 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. """