Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast forward testing #174

Merged
merged 39 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1cfcc18
first runthrough from zmq graff
dehann Oct 11, 2018
26811e8
new models
dehann Oct 12, 2018
618106c
Refactoring and robustifying server
GearsAD Oct 13, 2018
ae99194
Start of tests and robust server. Added mockserver option
GearsAD Oct 13, 2018
e3a4287
Discussion on function callback required
GearsAD Oct 14, 2018
be4a24e
Adding callback bodies
GearsAD Oct 14, 2018
df11038
Whoops
GearsAD Oct 14, 2018
4686585
First version of addVariable. Added placeholders for ls and getVert
GearsAD Oct 14, 2018
b1a1a18
ls implemented
GearsAD Oct 14, 2018
0e81324
Mini update
GearsAD Oct 14, 2018
7ef045a
ZMQ ls updated, internal unit tests developed, batchSolve included. W…
GearsAD Oct 15, 2018
2d6a11d
WIP on factor serialization/deserialization
GearsAD Oct 15, 2018
9e9cd28
Factors are working!
GearsAD Oct 16, 2018
a7217c5
Working Hexagonal example
GearsAD Oct 17, 2018
015faa7
Working getNode and placeholders for plotting and import/export
GearsAD Oct 17, 2018
f30dca4
Modularization
GearsAD Oct 17, 2018
d158dc1
Added callback tests and folded in integration test
GearsAD Oct 17, 2018
a40584b
Unit+integration+end-to-end tests wired in. Server start command also…
GearsAD Oct 18, 2018
647d14d
Need Distributions
GearsAD Oct 18, 2018
fb06637
Unit is testing me
GearsAD Oct 18, 2018
946bf0c
Unit is testing me v2.0
GearsAD Oct 18, 2018
83e6330
Plotting endpoints WIP, and aliasing sampler included in distributions
GearsAD Oct 19, 2018
1eb2949
Updating to quantile
GearsAD Oct 19, 2018
35fffd6
Merge branch 'master' of https://github.com/JuliaRobotics/Caesar.jl i…
GearsAD Oct 19, 2018
ed55809
Refactored a bit
GearsAD Oct 20, 2018
2dd2286
Small fix on the converter for Pose2Pose2
GearsAD Oct 20, 2018
28239bd
Error handling on missing factor
GearsAD Oct 20, 2018
a2aa186
Working session building out converters
GearsAD Oct 21, 2018
ec39b44
Working session building out converters
GearsAD Oct 21, 2018
c4a13ff
Merge branch 'feature/multilangzmq' of https://github.com/JuliaRoboti…
GearsAD Oct 23, 2018
5cb18d3
Upgrading for 0.7
GearsAD Oct 24, 2018
e60230f
Working except for strange error in end-to-end server, still investig…
GearsAD Oct 24, 2018
b15fe0a
WIP on updates
GearsAD Oct 25, 2018
eca0dd5
Tests working again
GearsAD Oct 26, 2018
9aa278e
Merge pull request #172 from JuliaRobotics/feature/multilangzmq_07
GearsAD Oct 26, 2018
ea69f70
Merge branch 'master' into feature/multilangzmq
dehann Oct 28, 2018
ae0a10e
evalType required in IIF v0.4.3
dehann Oct 28, 2018
71609a1
compatible with Julia 1.0
dehann Oct 28, 2018
0079295
Merge pull request #162 from JuliaRobotics/feature/multilangzmq
dehann Oct 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
julia 0.7 1.1
RoME 0.2.0
IncrementalInference 0.4.2
IncrementalInference 0.4.3
Graphs 0.10.1
KernelDensityEstimate 0.4.1
Distributions 0.16.0
Expand All @@ -21,3 +21,5 @@ Reexport 0.2.0
CloudGraphs 0.1.1
Neo4j 2.0.0
Mongoc 0.1.2
Unmarshal 0.2.1
ZMQ 1.0.0
55 changes: 0 additions & 55 deletions examples/multilanguage/zmq2caesar.jl

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/zmqServer.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"enablePlottingEndpoints": "HeckYeah!"
}
6 changes: 6 additions & 0 deletions scripts/zmqServer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Caesar;
using Caesar.ZmqCaesar;
fg = Caesar.initfg();
config = Dict{String, String}();
zmqConfig = ZmqServer(fg, config, true, "tcp://*:5555");
start(zmqConfig)
1 change: 1 addition & 0 deletions scripts/zmqServer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
julia -p 4 zmqServer.jl
10 changes: 6 additions & 4 deletions src/Caesar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ using
ImageMagick,
ImageCore,
DocStringExtensions,
CloudGraphs, # TODO: will be movedd to DFG
Neo4j, # TODO: will be movedd to DFG
Mongoc # TODO: will be movedd to DFG

CloudGraphs,
Neo4j,
Mongoc,
Unmarshal

export
GenericInSituSystem, # insitu components
Expand Down Expand Up @@ -135,4 +135,6 @@ include("cloudgraphs/slamindb.jl")
include("cloudgraphs/MultisessionUtils.jl")
include("cloudgraphs/FoveationUtils.jl")

# ZMQ server and endpoints
include("zmq/ZmqCaesar.jl")
end
3 changes: 2 additions & 1 deletion src/cloudgraphs/SolverStatus.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dates
using UUIDs

export SolverStatus

Expand All @@ -19,6 +20,6 @@ mutable struct SolverStatus
detachedSessionTimestamp::String
lastUpdatedTimestamp::String
lastIterationDurationSeconds::Float64
SolverStatus() = new(string(Base.Random.uuid4()), "", false, "", "", "", 0, "", string(unix2datetime(time())), "", "", "", 0)
SolverStatus() = new(string(uuid4()), "", false, "", "", "", 0, "", string(unix2datetime(time())), "", "", "", 0)
SolverStatus(id::String, host::String, isAttached::Bool, userId::String, robotId::String, sessionId::String, iteration::Int64, currentStep::String, startedUpTimestamp::String, attachedSessionTimestamp::String, detachedSessionTimestamp::String, lastUpdatedTimestamp::String, lastIterationDurationSeconds::Float64) = new(id, host, isAttached, userId, robotId, sessionId, iteration, currentStep, startedUpTimestamp, attachedSessionTimestamp, detachedSessionTimestamp, lastUpdatedTimestamp, lastIterationDurationSeconds)
end
22 changes: 22 additions & 0 deletions src/endpoints/Models.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# http://juliastats.github.io/StatsBase.jl/stable/weights.html
mutable struct Packed_AliasingScalarSampler
samples::Vector{Float64}
weights::Vector{Float64}
end

## avert your eyes, C++ below
# class MvNormal : public Distribution {
# std::vector<double> mean_;
# std::vector<std::vector<double>> cov_;
#
# public:
# MvNormal(const std::vector<double> &mean,
# const std::vector<std::vector<double>> &cov)
# : mean_(mean), cov_(cov) {}
# json ToJson(void) const {
# json j;
# j["mean"] = mean_;
# j["cov"] = cov_;
# return (j);
# }
# };
19 changes: 19 additions & 0 deletions src/zmq/ZmqCaesar.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module ZmqCaesar
using ZMQ, JSON
using Distributions, IncrementalInference, Caesar
using Unmarshal
using Dates

include("models/distributions.jl")
include("models/factors.jl")
include("models/config.jl")
include("models/session.jl")
include("models/plotting.jl")
include("models/ZmqServer.jl")
include("services/factors/distributionSerialization.jl")
include("services/factors/factorSerialization.jl")
include("services/config.jl")
include("services/session.jl")
include("services/plotting.jl")
include("services/ZmqServer.jl")
end
9 changes: 9 additions & 0 deletions src/zmq/models/ZmqServer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export
ZmqServer

mutable struct ZmqServer
fg::IncrementalInference.FactorGraph
config::Dict{String, Any}
isServerActive::Bool
binding::String
end
Empty file added src/zmq/models/config.jl
Empty file.
23 changes: 23 additions & 0 deletions src/zmq/models/distributions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export
Packed_Normal,
Packed_MvNormal,
Packed_AliasingScalarSampler

mutable struct Packed_Normal
mean::Float64
std::Float64
distType::String
end

mutable struct Packed_MvNormal
mean::Vector{Float64}
cov::Vector{Float64}
distType::String
end

mutable struct Packed_AliasingScalarSampler
samples::Vector{Float64}
weights::Vector{Float64}
quantile::Union{Float64, Nothing}
distType::String # AliasingScalarSampler
end
7 changes: 7 additions & 0 deletions src/zmq/models/factors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export
Packed_Factor

mutable struct Packed_Factor
measurement::Vector{Dict{String, Any}}
distType::String
end
8 changes: 8 additions & 0 deletions src/zmq/models/plotting.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export
PlotRequest

struct PlotRequest
widthPx::Int
heightPx::Int
encoding::String
end
32 changes: 32 additions & 0 deletions src/zmq/models/session.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import Base: convert

export
VariableRequest,
FactorRequest,
lsRequest,
SetReadyRequest

struct VariableRequest
label::String
variableType::String
N::Union{Int64, Nothing}
labels::Vector{String}
end

mutable struct FactorRequest
# factorType::String # This is now in the factor itself.
variables::Vector{String}
factorType::String
factor::Dict{String, Any}
end

struct lsRequest
variables::String
factors::String
end

struct SetReadyRequest
variables::Union{Vector{String}, Nothing}
isReady::Int
end
130 changes: 130 additions & 0 deletions src/zmq/services/ZmqServer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using ZMQ
using Caesar, Caesar.ZmqCaesar

export
start

import Base: start

global systemverbs = Symbol[
:shutdown
]
global configverbs = Symbol[
:initDfg;
:toggleMockServer;
:registerRobot;
:registerSession;
]

global sessionverbs = [
:addVariable;
:addFactor;
:addOdometry2D;
:addLandmark2D;
:addFactorBearingRangeNormal;
:ls;
:getNode;
:setReady;
:batchSolve;
# per variable
:setVarKDE; # needed for workaround on bad autoinit -- sorry
:getVarMAPKDE; # marginal belief points (KDE)
:getVarMAPMean;
# fancy future stuff
:getVarMAPMax; # Future, how many maxes should you get?
:getVarMAPFit; # default=Normal
]

plottingVerbs = [];
try
# Test - if passed, declare verbs
getfield(Main, :RoMEPlotting)
global plottingVerbs = [
:plotKDE;
:plotPose;
:drawPoses;
:drawPosesLandms
];
catch ex
@info "[ZMQ Server] Plotting is disabled!"
end

function shutdown(zmqServer, request)::Dict{String, Any}
@info "Shutting down ZMQ server on request..."
zmqServer.isServerActive = false
return Dict{String, Any}("status" => "OK")
end

function Base.isopen(socket::Socket)
return getfield(socket, :data) != C_NULL
end

function start(zmqServer::ZmqServer)
# set up a context for zmq
ctx=Context()
s1=Socket(ctx, REP)
ZMQ.bind(s1, "tcp://*:5555")

try
while zmqServer.isServerActive
println("waiting to receive...")
msg = ZMQ.recv(s1)
out = ZMQ.convert(IOStream, msg)
str = String(take!(out))
request = JSON.parse(str)

cmdtype = haskey(request, "request") ? Symbol(request["request"]) : :ERROR_NOCOMMANDPROVIDED
@info "[ZMQ Server] REQUEST: Received request '$cmdtype' in payload '$str'..."
if cmdtype in union(configverbs, sessionverbs)
resp = Dict{String, Any}()
try
# Mocking server
if haskey(zmqServer.config, "isMockServer") && zmqServer.config["isMockServer"] == "true" && cmdtype != :toggleMockServer
@warn "[ZMQ Server] MOCKING ENABLED - Ignoring request!"
else
# Otherwise actually perform the command
@show cmd = getfield(Caesar.ZmqCaesar, cmdtype)
resp = cmd(zmqServer.config, zmqServer.fg, request)
end
if !haskey(resp, "status")
resp["status"] = "OK"
end
catch ex
io = IOBuffer()
showerror(io, ex, catch_backtrace())
err = String(take!(io))
@warn "[ZMQ Server] Exception: $err"
resp["status"] = "ERROR"
resp["error"] = err
end
@info "[ZMQ Server] RESPONSE: $(JSON.json(resp))"
ZMQ.send(s1, JSON.json(resp))
elseif cmdtype in systemverbs
if cmdtype == :shutdown
#TODO: Call shutdown from here.
@info "Shutting down ZMQ server on request..."
zmqServer.isServerActive = false
resp = Dict{String, Any}("status" => "OK")
# Send response before shutting down.
ZMQ.send(s1, JSON.json(resp))
end
else
@warn "[ZMQ Server] Received invalid command $cmdtype"
d = Dict{String, String}("status" => "ERROR", "error" => "Command '$cmdtype' not a valid command.")
oks = json(d)
ZMQ.send(s1, oks)
end
end
catch ex
@warn "[ZMQ Server] Something in the zmq/json/rest pipeline broke"
showerror(stderr, ex, catch_backtrace())
finally
@warn "[ZMQ Server] Shutting down server"
# TODO: Figure out why I can't use Base.isopen here...
if Base.isopen(s1)
ZMQ.close(s1)
end
ZMQ.close(ctx)
@warn "[ZMQ Server] Shut down!"
end
end
Loading