Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ One way to think of this project is as a generator for the equivalent of the MOO

`init.sh` installs the Ubuntu packages needed to build IvPico:

- [openocean-messages](https://github.com/openocean-software/openocean-messages), for the `Navigation` and `ControlSetpoint` messages, and MOOS-IvP's helm libraries built without MOOS ([GobySoft's `ivp-without-moos`](https://github.com/GobySoft/moos-ivp/tree/ivp-without-moos)), for the IvP solver and behaviors. Both come from [Open Ocean Software](https://github.com/openocean-software/openocean-build)'s continuous builds (apt.oceansoft.org), added if apt doesn't already have them.
- Goby3, for the Goby app, adding [packages.gobysoft.org](http://packages.gobysoft.org)'s continuous builds if apt doesn't already have it. `init.sh --no-goby` leaves Goby3 out, and `build.sh` then skips the Goby app.
- [openocean-messages](https://github.com/openocean-software/openocean-messages), for the `Navigation` and `ControlSetpoint` messages, and MOOS-IvP's helm libraries built without MOOS ([GobySoft's `ivp-without-moos`](https://github.com/GobySoft/moos-ivp/tree/ivp-without-moos)), for the IvP solver and behaviors.
- Goby3, for the Goby app. `init.sh --no-goby` leaves Goby3 out, and `build.sh` then skips the Goby app.

All of these come from [Open Ocean Software](https://github.com/openocean-software/openocean-build)'s continuous builds, with its releases for what they depend on (DCCL, MOOS, ...), at apt.oceansoft.org. `init.sh` adds both if apt can't install the packages already.

`build.sh` then builds IvPico in `build/` and installs it into `build/usr`.

Expand Down
70 changes: 34 additions & 36 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,43 @@ apt_install "${packages[@]}"

. /etc/os-release

# openocean-messages and MOOS-IvP's helm libraries (built without MOOS), from Open Ocean
# Software's continuous builds (apt.oceansoft.org) if apt doesn't have them yet
oo_policy=$(apt-cache policy libivp-helm-dev)
if ! grep -q "Candidate: [^(]" <<< "${oo_policy}"; then
apt_install curl gpg
keyring=/usr/share/keyrings/openocean-continuous.asc
fingerprint=DAF08DD7788E6C84C6F8E8D3E59E1A81FECDB228
key=$(curl -fsSL https://raw.githubusercontent.com/openocean-software/openocean-build/main/keys/continuous.asc)
packages=(libopenocean-messages-dev libivp-helm-dev)
if ${goby}; then
# libgoby3-dev only recommends libais-dev and dccl5-compiler, but goby's CMake package
# links libais.so, and goby_add_app() runs protoc-gen-dccl. MOOS-IvP's apps
# (pMarineViewer for the Goby launches) need libmoos-ivp but don't depend on it
packages+=(libgoby3-dev goby3-apps libais-dev dccl5-compiler
libgoby3-moos-dev goby3-moos moos10-mit-db moos-ivp-apps moos-ivp-gui libmoos-ivp)
fi

# Adds an apt.oceansoft.org channel to openocean_sources, checking its key's fingerprint
openocean_sources=""
add_openocean() {
local channel=$1 fingerprint=$2 key
local keyring=/usr/share/keyrings/openocean-${channel}.asc
key=$(curl -fsSL "https://raw.githubusercontent.com/openocean-software/openocean-build/main/keys/${channel}.asc")
if ! gpg --show-keys --with-colons <<< "${key}" | grep -q "^fpr:*${fingerprint}:"; then
echo "The Open Ocean Software continuous key's fingerprint isn't ${fingerprint}" >&2
echo "The Open Ocean Software ${channel} key's fingerprint isn't ${fingerprint}" >&2
exit 1
fi
$SUDO tee "${keyring}" <<< "${key}" > /dev/null
printf "Types: deb\nURIs: https://apt.oceansoft.org/continuous/%s-%s\nSuites: %s\nComponents: main\nSigned-By: %s\n" \
"${ID}" "${VERSION_CODENAME}" "${VERSION_CODENAME}" "${keyring}" |
$SUDO tee /etc/apt/sources.list.d/openocean.sources > /dev/null
$SUDO apt-get update
fi
apt_install libopenocean-messages-dev libivp-helm-dev
openocean_sources+="Types: deb
URIs: https://apt.oceansoft.org/${channel}/${ID}-${VERSION_CODENAME}
Suites: ${VERSION_CODENAME}
Components: main
Signed-By: ${keyring}

if ${goby}; then
# Goby3, for src/bin/goby. If apt doesn't have it yet, add packages.gobysoft.org's
# continuous builds, which have 'goby test' (newer than 3.6.1)
goby_policy=$(apt-cache policy libgoby3-dev)
if ! grep -q "Candidate: [^(]" <<< "${goby_policy}"; then
apt_install curl gpg
keyring=/usr/share/keyrings/gobysoft-archive-keyring.gpg
if [ ! -f "${keyring}" ]; then
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x19478082E2F8D3FE" |
gpg --dearmor | $SUDO tee "${keyring}" > /dev/null
fi
echo "deb [signed-by=${keyring}] http://packages.gobysoft.org/${ID}/continuous/ ${VERSION_CODENAME}/" |
$SUDO tee /etc/apt/sources.list.d/gobysoft_continuous.list > /dev/null
$SUDO apt-get update
fi
# libgoby3-dev only recommends these, but goby's CMake package links libais.so,
# and goby_add_app() runs protoc-gen-dccl
apt_install libgoby3-dev goby3-apps libais-dev dccl5-compiler
# pMarineViewer for the Goby launches (viewer.launch), through goby_moos_gateway;
# MOOS-IvP's apps need libmoos-ivp but don't depend on it
apt_install libgoby3-moos-dev goby3-moos moosdb10 moos-ivp-apps moos-ivp-gui libmoos-ivp
"
}

# If apt can't install them yet, add Open Ocean Software's continuous builds (for
# openocean-messages, MOOS-IvP's helm libraries built without MOOS, and Goby3 with
# 'goby test') and its releases, which have what those depend on (DCCL, MOOS, ...)
if ! apt-get -s install "${packages[@]}" > /dev/null 2>&1; then
apt_install curl gpg
add_openocean continuous DAF08DD7788E6C84C6F8E8D3E59E1A81FECDB228
add_openocean release EAD278F6A25644C2C559DBB6D28A2EAB14D2A9E5
$SUDO tee /etc/apt/sources.list.d/openocean.sources <<< "${openocean_sources}" > /dev/null
$SUDO apt-get update
fi
apt_install "${packages[@]}"
2 changes: 1 addition & 1 deletion src/bin/goby/moos_gateway/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ goby_add_library(TARGET ivpico_moos_gateway_plugin
PROTOS moos_gateway_config.proto
PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto
PROTO_IMPORT_DIRS ${PROJECT_SOURCE_DIR}/src/lib ${openocean_messages_PROTO_DIR}
LINK_LIBRARIES goby_moos ivpico_helm)
LINK_LIBRARIES goby_moos ivpico_helm IVP::contacts IVP::geometry IVP::mbutil)
target_include_directories(ivpico_moos_gateway_plugin PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
install(TARGETS ivpico_moos_gateway_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
15 changes: 13 additions & 2 deletions src/bin/goby/moos_gateway/moos_gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// along with IvPico. If not, see <https://www.gnu.org/licenses/>.

// goby_moos_gateway plugin that gives a MOOS community what pHelmIvP and its
// navigation would post (NAV_*, the helm's postings, IVPHELM_*), so MOOS-IvP
// tools such as pNodeReporter and pMarineViewer work with goby_helm_ivp.
// navigation would post (NAV_*, the helm's postings, VIEW_*, NODE_MESSAGE_LOCAL,
// IVPHELM_*), so MOOS-IvP tools such as pNodeReporter and pMarineViewer work
// with goby_helm_ivp.

#include <goby/middleware/marshalling/protobuf.h>

Expand All @@ -28,6 +29,7 @@
#include <goby/zeromq/application/multi_thread.h>

#include "groups.h"
#include "helm/conversions.h"
#include "helm/status_strings.h"
#include "interface/ivp.pb.h"
#include "moos_gateway_config.pb.h"
Expand All @@ -53,6 +55,15 @@ class MOOSGatewayTranslation : public ::goby::moos::Translator
[this](const ivp::interface::Posting& posting) { post(posting); });
goby().interprocess().subscribe<groups::status>([this](const ivp::interface::Status& status)
{ post(status); });
goby().interprocess().subscribe<groups::visualization>(
[this](const ivp::interface::Visualization& vis)
{
const auto [var, spec] = helm::view_posting(vis);
moos().comms().Notify(var, spec);
});
goby().interprocess().subscribe<groups::offboard_message>(
[this](const ivp::interface::OffboardMessage& msg)
{ moos().comms().Notify("NODE_MESSAGE_LOCAL", helm::node_message_spec(msg)); });

for (const auto& var : cfg_.to_helm())
moos().add_trigger(var, [this](const CMOOSMsg& msg) { to_helm(msg); });
Expand Down
197 changes: 197 additions & 0 deletions src/lib/helm/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include <cmath>

#include "MBUtils.h"
#include "NodeMessage.h"
#include "NodeMessageUtils.h"
#include "XYFormatUtilsPoint.h"
#include "XYFormatUtilsPoly.h"
#include "XYFormatUtilsSegl.h"
#include "XYFormatUtilsSeglr.h"

namespace ivpico
{
Expand All @@ -29,6 +35,66 @@ namespace
{
constexpr double degrees(double radians) { return radians * 180.0 / M_PI; }
constexpr double radians(double degrees) { return degrees * M_PI / 180.0; }

void set_object_fields(ivp::interface::Visualization& v, const XYObject& object)
{
v.set_label(object.get_label());
v.set_active(object.active());
v.set_id(object.get_id());
v.set_message(object.get_msg());
if (object.duration_set())
v.set_duration(object.get_duration());
if (object.color_set("vertex"))
v.set_vertex_color(object.get_color_str("vertex"));
if (object.color_set("edge"))
v.set_edge_color(object.get_color_str("edge"));
if (object.color_set("label"))
v.set_label_color(object.get_color_str("label"));
if (object.color_set("fill"))
v.set_fill_color(object.get_color_str("fill"));
if (object.vertex_size_set())
v.set_vertex_size(object.get_vertex_size());
if (object.edge_size_set())
v.set_edge_size(object.get_edge_size());
if (object.transparency_set())
v.set_transparency(object.get_transparency());
}

void get_object_fields(const ivp::interface::Visualization& v, XYObject& object)
{
object.set_label(v.label());
object.set_active(v.active());
object.set_id(v.id());
object.set_msg(v.message());
if (v.time() != 0)
object.set_time(static_cast<double>(v.time()) * 1e-6);
if (v.has_duration())
object.set_duration(v.duration());
if (!v.vertex_color().empty())
object.set_color("vertex", v.vertex_color());
if (!v.edge_color().empty())
object.set_color("edge", v.edge_color());
if (!v.label_color().empty())
object.set_color("label", v.label_color());
if (!v.fill_color().empty())
object.set_color("fill", v.fill_color());
if (v.has_vertex_size())
object.set_vertex_size(v.vertex_size());
if (v.has_edge_size())
object.set_edge_size(v.edge_size());
if (v.has_transparency())
object.set_transparency(v.transparency());
}

template <typename Shape> void add_vertices(Shape& shape, const XYSegList& segl)
{
for (unsigned i = 0; i < segl.size(); ++i)
{
auto& vertex = *shape.add_vertex();
vertex.set_x(segl.get_vx(i));
vertex.set_y(segl.get_vy(i));
}
}
} // namespace

double heading_degrees(double radians)
Expand Down Expand Up @@ -128,5 +194,136 @@ void set_desired(openocean::ControlSetpoint& desired, const std::string& domain_
}
}

std::optional<ivp::interface::Visualization> visualization(const std::string& var,
const std::string& spec)
{
ivp::interface::Visualization v;
if (var == "VIEW_POINT")
{
const XYPoint point = string2Point(spec);
if (!point.valid())
return std::nullopt;
set_object_fields(v, point);
v.mutable_point()->set_x(point.x());
v.mutable_point()->set_y(point.y());
if (point.z() != 0)
v.mutable_point()->set_z(point.z());
}
else if (var == "VIEW_SEGLIST")
{
const XYSegList segl = string2SegList(spec);
if (!segl.valid())
return std::nullopt;
set_object_fields(v, segl);
add_vertices(*v.mutable_seglist(), segl);
}
else if (var == "VIEW_POLYGON")
{
const XYPolygon poly = string2Poly(spec);
if (!poly.valid())
return std::nullopt;
set_object_fields(v, poly);
add_vertices(*v.mutable_polygon(), poly);
}
else if (var == "VIEW_SEGLR")
{
const XYSeglr seglr = string2Seglr(spec);
if (!seglr.valid())
return std::nullopt;
set_object_fields(v, seglr);
auto& out = *v.mutable_seglr();
for (unsigned i = 0; i < seglr.size(); ++i)
{
auto& vertex = *out.add_vertex();
vertex.set_x(seglr.getVX(i));
vertex.set_y(seglr.getVY(i));
}
out.set_ray_angle(seglr.getRayAngle());
out.set_ray_length(seglr.getRayLen());
out.set_head_size(seglr.getHeadSize());
}
else
return std::nullopt;
return v;
}

std::optional<ivp::interface::OffboardMessage> offboard_message(const std::string& spec)
{
const NodeMessage msg = string2NodeMessage(spec);
if (!msg.valid())
return std::nullopt;

ivp::interface::OffboardMessage out;
out.set_source_node(msg.getSourceNode());
out.set_destination_node(msg.getDestNode());
out.set_destination_group(msg.getDestGroup());
out.set_key(msg.getVarName());
if (tokStringParse(spec, "double_val", ',', '=').empty())
out.set_sval(msg.getStringVal());
else
out.set_dval(msg.getDoubleVal());
out.set_source_app(msg.getSourceApp());
out.set_source_behavior(msg.getSourceBehavior());
out.set_color(msg.getColor());
out.set_message_id(msg.getMessageID());
out.set_ack_requested(msg.getAckRequested());
return out;
}

std::pair<std::string, std::string> view_posting(const ivp::interface::Visualization& vis)
{
if (vis.has_point())
{
XYPoint point(vis.point().x(), vis.point().y(), vis.point().z());
get_object_fields(vis, point);
return {"VIEW_POINT", point.get_spec()};
}
if (vis.has_polygon())
{
XYPolygon poly;
for (const auto& v : vis.polygon().vertex()) poly.add_vertex(v.x(), v.y(), false);
poly.determine_convexity();
get_object_fields(vis, poly);
return {"VIEW_POLYGON", poly.get_spec()};
}
if (vis.has_seglr())
{
XYSeglr seglr;
for (const auto& v : vis.seglr().vertex()) seglr.addVertex(v.x(), v.y());
seglr.setRayAngle(vis.seglr().ray_angle());
if (vis.seglr().has_ray_length())
seglr.setRayLen(vis.seglr().ray_length());
if (vis.seglr().has_head_size())
seglr.setHeadSize(vis.seglr().head_size());
get_object_fields(vis, seglr);
return {"VIEW_SEGLR", seglr.get_spec()};
}
XYSegList segl;
for (const auto& v : vis.seglist().vertex()) segl.add_vertex(v.x(), v.y());
get_object_fields(vis, segl);
return {"VIEW_SEGLIST", segl.get_spec()};
}

std::string node_message_spec(const ivp::interface::OffboardMessage& msg)
{
NodeMessage out;
out.setSourceNode(msg.source_node());
out.setDestNode(msg.destination_node());
out.setDestGroup(msg.destination_group());
out.setVarName(msg.key());
if (msg.value_case() == ivp::interface::OffboardMessage::kDval)
out.setDoubleVal(msg.dval());
else
out.setStringVal(msg.sval());
out.setSourceApp(msg.source_app());
out.setSourceBehavior(msg.source_behavior());
if (!msg.color().empty())
out.setColor(msg.color());
out.setMessageID(msg.message_id());
if (msg.ack_requested())
out.setAckRequested();
return out.getSpec();
}

} // namespace helm
} // namespace ivpico
15 changes: 15 additions & 0 deletions src/lib/helm/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <optional>
#include <string>
#include <utility>

#include "NodeRecord.h"

Expand All @@ -44,6 +45,20 @@ std::string able_filter_string(const ivp::interface::Command::AbleFilter& filter
// Sets the setpoint field for the decision on a helm domain variable
void set_desired(openocean::ControlSetpoint& desired, const std::string& domain_var, double value);

// A VIEW_POINT, VIEW_SEGLIST, VIEW_POLYGON or VIEW_SEGLR posting as a
// Visualization, or nothing for another variable or a spec that doesn't parse
std::optional<ivp::interface::Visualization> visualization(const std::string& var,
const std::string& spec);

// A NODE_MESSAGE_LOCAL posting as an OffboardMessage, or nothing if it doesn't parse
std::optional<ivp::interface::OffboardMessage> offboard_message(const std::string& spec);

// The variable (VIEW_POINT, etc.) and spec that pHelmIvP would post for a Visualization
std::pair<std::string, std::string> view_posting(const ivp::interface::Visualization& vis);

// The NODE_MESSAGE_LOCAL spec for an OffboardMessage
std::string node_message_spec(const ivp::interface::OffboardMessage& msg);

} // namespace helm
} // namespace ivpico

Expand Down
Loading