Skip to content

Commit

Permalink
feat: plot nav improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
strasdat committed Oct 20, 2023
1 parent bc9a04a commit 940a5fb
Show file tree
Hide file tree
Showing 17 changed files with 643 additions and 191 deletions.
19 changes: 7 additions & 12 deletions cpp/farm_ng/core/plotting/remote_plot_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ int main(int argc, char* argv[]) {
pool->start(8);

plotting::Vec3Curve trig_graph;
trig_graph.bounds = {
.x_bounds = {.len = 5.0 * M_PI},
.y_bounds = {.height = 2.0, .offset = 0.0}};
trig_graph.path = "trig/ {sin,cos,tan}";
trig_graph.color = {
sophus::Color::neonRed(),
sophus::Color::neonGreen(),
sophus::Color::neonBlue()};

plotting::Curve sawtooth;
sawtooth.bounds = {
.x_bounds = {.len = 5.0 * M_PI},
.y_bounds = {.height = 2.0, .offset = 0.0}};
sawtooth.path = "trig1/sawtooth";
sawtooth.color = sophus::Color::blue();

Expand All @@ -44,14 +50,8 @@ int main(int argc, char* argv[]) {

double x = 0.0;

auto x_range0 =
plotting::XRange{.range = {-2.0 * M_PI, 0.0}, .path = "trig0"};
auto x_range1 =
plotting::XRange{.range = {-2.0 * M_PI, 0.0}, .path = "trig1"};

std::vector<plotting::Message> messages;
messages.push_back(plotting::YRange{.range = {-1.0, 1.0}, .path = "trig0"});
messages.push_back(plotting::YRange{.range = {-1.0, 1.0}, .path = "trig1"});

plotting->inMessages().send(messages);
int counter = 0;
while (true) {
Expand All @@ -74,9 +74,6 @@ int main(int argc, char* argv[]) {
messages.push_back(trig_graph);
messages.push_back(sawtooth);

x_range0.range = {x - 2.0 * M_PI, x};
x_range1.range = {x - 2.0 * M_PI, x};

++counter;

if (counter >= 10) {
Expand All @@ -88,8 +85,6 @@ int main(int argc, char* argv[]) {
messages.push_back(timestamps);
}

messages.push_back(x_range0);
messages.push_back(x_range1);
plotting->inMessages().send(messages);

x += 0.01;
Expand Down
42 changes: 22 additions & 20 deletions cpp/farm_ng/core/plotting/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@ struct CurveResetPredicate {
std::optional<double> clear_x_smaller_than = std::nullopt;
};

FARM_STRUCT(
XCoordinateBounds,
((std::optional<double>, max_x, {std::nullopt}), (double, len, {100.0})));

FARM_STRUCT(
YCoordinateBounds,
((std::optional<double>, height, {std::nullopt}), (double, offset, {0.0})));

FARM_STRUCT(
Bounds,
((XCoordinateBounds, x_bounds, {}), (YCoordinateBounds, y_bounds, {})));

// Append to an existing curve in a given plot (or add new one if it does not
// exist already), with path being "plot_name/curve_name".
FARM_STRUCT(
Curve,
((sophus::Color, color, {}),
((Bounds, bounds, {}),
(sophus::Color, color, {}),
(LineType, line_type, {LineType::line_strip}),
(std::filesystem::path, path, {}),
(CurveResetPredicate, reset, {}),
Expand All @@ -74,7 +87,8 @@ ColorArray3 constexpr kDefaultConfColorArray3 = {
// for each curve, and the remaining components are the y coordinates.
FARM_STRUCT(
Vec3Curve,
((ColorArray3, color, {kDefaultColorArray3}),
((Bounds, bounds, {}),
(ColorArray3, color, {kDefaultColorArray3}),
(LineType, line_type, {LineType::line_strip}),
(std::filesystem::path, path, {}),
(CurveResetPredicate, reset, {}),
Expand All @@ -87,7 +101,8 @@ using Vec7d = Eigen::Matrix<double, 7, 1>;
// standard deviation).
FARM_STRUCT(
Vec3CurveWithConfInterval,
((ColorArray3, color, {kDefaultColorArray3}),
((Bounds, bounds, {}),
(ColorArray3, color, {kDefaultColorArray3}),
(ColorArray3, conf_color, {kDefaultConfColorArray3}),
(LineType, line_type, {LineType::line_strip}),
(std::filesystem::path, path, {}),
Expand Down Expand Up @@ -133,26 +148,13 @@ struct ColoredRect {

FARM_STRUCT(
RectPlot,
((std::filesystem::path, path, {}),
((Bounds, bounds, {}),
(std::deque<ColoredRect>, colored_rects, {}),
(std::filesystem::path, path, {}),
(CurveResetPredicate, reset, {})));

FARM_STRUCT(
XRange,
((sophus::RegionF64, range, {sophus::RegionF64::empty()}),
(std::filesystem::path, path, {})));
FARM_STRUCT(
YRange,
((sophus::RegionF64, range, {sophus::RegionF64::empty()}),
(std::filesystem::path, path, {})));

using Message = std::variant<
RectPlot,
Curve,
Vec3Curve,
Vec3CurveWithConfInterval,
XRange,
YRange>;
using Message =
std::variant<RectPlot, Curve, Vec3Curve, Vec3CurveWithConfInterval>;

} // namespace plotting

Expand Down
34 changes: 15 additions & 19 deletions cpp/farm_ng/core/proto_conv/plotting/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ FARM_CONV_IMPL_REPEATED(
FARM_PROTO_CONV_IMPL(
plotting::RectPlot,
core::plotting::proto::RectPlot,
(path, colored_rects, reset));
(bounds, colored_rects, path, reset));

FARM_PROTO_CONV_IMPL(
plotting::Curve,
core::plotting::proto::Curve,
(color, line_type, path, reset, x_y_pairs));
(bounds, color, line_type, path, reset, x_y_pairs));

FARM_PROTO_CONV_IMPL_FN(
plotting::Vec3Curve,
core::plotting::proto::Vec3Curve,
((color, SKIP), line_type, path, reset, x_vec_pairs),
(bounds, (color, SKIP), line_type, path, reset, x_vec_pairs),
[](plotting::Vec3Curve&& s, core::plotting::proto::Vec3Curve const& proto)
-> Expected<plotting::Vec3Curve> {
if (proto.color_size() != 3) {
Expand All @@ -183,7 +183,8 @@ FARM_PROTO_CONV_IMPL_FN(
FARM_PROTO_CONV_IMPL_FN(
plotting::Vec3CurveWithConfInterval,
core::plotting::proto::Vec3CurveWithConfInterval,
((color, SKIP),
(bounds,
(color, SKIP),
(conf_color, SKIP),
line_type,
path,
Expand Down Expand Up @@ -219,10 +220,17 @@ FARM_PROTO_CONV_IMPL_FN(
});

FARM_PROTO_CONV_IMPL(
plotting::XRange, core::plotting::proto::XRange, (range, path));
plotting::XCoordinateBounds,
core::plotting::proto::XCoordinateBounds,
(max_x, len));

FARM_PROTO_CONV_IMPL(
plotting::YRange, core::plotting::proto::YRange, (range, path));
plotting::YCoordinateBounds,
core::plotting::proto::YCoordinateBounds,
(height, offset));

FARM_PROTO_CONV_IMPL(
plotting::Bounds, core::plotting::proto::Bounds, (x_bounds, y_bounds));

template <>
auto fromProt<core::plotting::proto::Message>(
Expand All @@ -249,16 +257,6 @@ auto fromProt<core::plotting::proto::Message>(
msg = m;
return msg;
}
if (proto.has_x_range()) {
FARM_TRY(auto, m, fromProt(proto.x_range()));
msg = m;
return msg;
}
if (proto.has_y_range()) {
FARM_TRY(auto, m, fromProt(proto.y_range()));
msg = m;
return msg;
}
return msg;
}

Expand All @@ -275,9 +273,7 @@ auto toProt<plotting::Message>(plotting::Message const& v)
},
[&](plotting::Vec3CurveWithConfInterval const& v) {
*proto.mutable_vec3_conf_curve() = toProt(v);
},
[&](plotting::XRange const& v) { *proto.mutable_x_range() = toProt(v); },
[&](plotting::YRange const& v) { *proto.mutable_y_range() = toProt(v); });
});
return proto;
}

Expand Down
8 changes: 6 additions & 2 deletions cpp/farm_ng/core/proto_conv/plotting/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ FARM_PROTO_CONV_TRAIT(plotting::Vec3Curve, core::plotting::proto::Vec3Curve);
FARM_PROTO_CONV_TRAIT(
plotting::Vec3CurveWithConfInterval,
core::plotting::proto::Vec3CurveWithConfInterval);
FARM_PROTO_CONV_TRAIT(plotting::XRange, core::plotting::proto::XRange);
FARM_PROTO_CONV_TRAIT(plotting::YRange, core::plotting::proto::YRange);

FARM_PROTO_CONV_TRAIT(
plotting::XCoordinateBounds, core::plotting::proto::XCoordinateBounds);
FARM_PROTO_CONV_TRAIT(
plotting::YCoordinateBounds, core::plotting::proto::YCoordinateBounds);
FARM_PROTO_CONV_TRAIT(plotting::Bounds, core::plotting::proto::Bounds);
FARM_PROTO_CONV_TRAIT(plotting::Message, core::plotting::proto::Message);
FARM_PROTO_CONV_TRAIT(
std::vector<plotting::Message>, core::plotting::proto::Messages);
Expand Down
68 changes: 38 additions & 30 deletions protos/farm_ng/core/plotting/plotting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,50 @@ message XVecConvTupleF64 {
int64 num_tuples = 2;
}

message XCoordinateBounds {
core.proto.OptionalG0Double max_x = 1;
double len = 2;
}


message YCoordinateBounds {
core.proto.OptionalG0Double height = 1;
double offset = 2;
}

message Bounds {
XCoordinateBounds x_bounds = 1;
YCoordinateBounds y_bounds = 2;
}

message LineType { string variant_name = 1; }

message Curve {
core.proto.Color color = 1;
LineType line_type = 2;
core.proto.FileSystemPath path = 3;
CurveResetPredicate reset = 4;
XyPairsF64 x_y_pairs = 5;
Bounds bounds = 1;
core.proto.Color color = 2;
LineType line_type = 3;
core.proto.FileSystemPath path = 4;
CurveResetPredicate reset = 5;
XyPairsF64 x_y_pairs = 6;
};

message Vec3Curve {
repeated core.proto.Color color = 1;
LineType line_type = 2;
core.proto.FileSystemPath path = 3;
CurveResetPredicate reset = 4;
XVecTupleF64 x_vec_pairs = 5;
};

message Vec3CurveWithConfInterval {
repeated core.proto.Color color = 1;
repeated core.proto.Color conf_color = 2;
Bounds bounds = 1;
repeated core.proto.Color color = 2;
LineType line_type = 3;
core.proto.FileSystemPath path = 4;
CurveResetPredicate reset = 5;
XVecConvTupleF64 x_vec_conf_tuples = 6;
XVecTupleF64 x_vec_pairs = 6;
};

message Vec3CurveWithConfInterval {
Bounds bounds = 1;
repeated core.proto.Color color = 2;
repeated core.proto.Color conf_color = 3;
LineType line_type = 4;
core.proto.FileSystemPath path = 5;
CurveResetPredicate reset = 6;
XVecConvTupleF64 x_vec_conf_tuples = 7;
};

message ColoredRect {
Expand All @@ -81,19 +100,10 @@ message ColoredRect {
message RepeatedG0ColoredRect { repeated ColoredRect value = 1; }

message RectPlot {
core.proto.FileSystemPath path = 1;
Bounds bounds = 1;
RepeatedG0ColoredRect colored_rects = 2;
CurveResetPredicate reset = 3;
}

message XRange {
core.proto.FileSystemPath path = 1;
core.proto.RegionF64 range = 2;
}

message YRange {
core.proto.FileSystemPath path = 1;
core.proto.RegionF64 range = 2;
core.proto.FileSystemPath path = 3;
CurveResetPredicate reset = 4;
}

message Message {
Expand All @@ -102,8 +112,6 @@ message Message {
Vec3Curve vec3_curve = 2;
Vec3CurveWithConfInterval vec3_conf_curve = 3;
RectPlot rects = 4;
XRange x_range = 5;
YRange y_range = 6;
}
}

Expand Down
3 changes: 2 additions & 1 deletion rs/plotting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4", features = ["derive"] }
eframe = "0.22"
eframe = "0.23"
egui_plot = "0.23"
prost = "0.12"
tokio = { version = "1", features = ["full"] }
tonic = "0.10.2"
Expand Down
6 changes: 4 additions & 2 deletions rs/plotting/src/actors/grpc_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ impl ActorNode for ActiveGrpcSourceNodeImpl {
.add_service(PlottingWidgetServer::new(server))
.serve(address.parse().unwrap());
match server_future.await {
Ok(_) =>{}
Err(e) =>{panic!("{}", e);}
Ok(_) => {}
Err(e) => {
panic!("{}", e);
}
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions rs/plotting/src/actors/plotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ use hollywood::core::*;
use hollywood::macros::actor_inputs;
use tokio::select;

#[derive(Clone, Debug)]
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct PlotterProp {}



/// Inbound message for the Plotter actor.
#[derive(Clone, Debug)]
#[actor_inputs(PlotterInbound, {PlotterProp, PlotterState, NullOutbound})]
Expand Down
Loading

0 comments on commit 940a5fb

Please sign in to comment.