JaiaBot 2.0.0
JaiaBot micro-AUV software
 
Loading...
Searching...
No Matches
jaiabot_gateway_plugin.h
Go to the documentation of this file.
1#ifndef JAIABOT_LIB_MOOS_GATEWAY_H
2#define JAIABOT_LIB_MOOS_GATEWAY_H
3
4#include <goby/moos/middleware/moos_plugin_translator.h>
5#include <goby/moos/protobuf/moos_gateway_config.pb.h>
6
7#include "jaiabot/groups.h"
10
11#include "jaiabot_gateway_config.pb.h"
12namespace jaiabot
13{
14namespace moos
15{
16class IvPHelmTranslation : public goby::moos::Translator
17{
18 public:
19 IvPHelmTranslation(const goby::apps::moos::protobuf::GobyMOOSGatewayConfig& cfg)
20 : goby::moos::Translator(cfg)
21 {
22 // once get a datum update, wait until the next NAV_X (published from NodeStatus)
23 // before we send any new IvPBehaviorUpdate messages. If not, we can get a race condition where
24 // the Helm completes a Transit if the current position (in X,Y) is the same as the recovery position (in X,Y).
25 goby().interprocess().subscribe<goby::middleware::groups::datum_update>(
26 [this](const goby::middleware::protobuf::DatumUpdate& datum_update) {
27 goby::glog.is_debug1() && goby::glog << "Datum update received." << std::endl;
28 pending_datum_update_ = true;
29 });
30 // use NAV_X as a proxy for a new full NAV_* update (via goby::moos::FrontSeatTranslation from NodeStatus)
31 // once received, flush any pending update
32 moos().add_trigger("NAV_X", [this](const CMOOSMsg&) {
33 pending_datum_update_ = false;
34 if (pending_bhv_update_)
35 {
36 goby::glog.is_debug1() &&
37 goby::glog << "NAV_X received, flushing pending IvPBehaviorUpdate" << std::endl;
38
39 publish_bhv_update(*pending_bhv_update_);
40 pending_bhv_update_.reset();
41 }
42 });
43
44 goby().interprocess().subscribe<jaiabot::groups::mission_ivp_behavior_update>(
45 [this](const protobuf::IvPBehaviorUpdate& update) { publish_bhv_update(update); });
46
47 goby().interprocess().subscribe<jaiabot::groups::mission_report>(
48 [this](const protobuf::MissionReport& report) {
49 moos().comms().Notify("JAIABOT_MISSION_STATE",
51 });
52 moos().add_trigger("JAIABOT_TRANSIT_COMPLETE", [this](const CMOOSMsg& msg) {
53 if (msg.GetString() == "true")
54 {
55 protobuf::IvPBehaviorReport report;
56 report.mutable_transit()->set_waypoint_reached(true);
57 goby().interprocess().publish<jaiabot::groups::mission_ivp_behavior_report>(report);
58 }
59 });
60 }
61
62 private:
63 void publish_bhv_update(const protobuf::IvPBehaviorUpdate& update);
64
65 private:
66 bool pending_datum_update_{false};
67 std::unique_ptr<protobuf::IvPBehaviorUpdate> pending_bhv_update_;
68
69}; // namespace moos
70
71class AllMessagesForLoggingTranslation : public goby::moos::Translator
72{
73 public:
74 AllMessagesForLoggingTranslation(const goby::apps::moos::protobuf::GobyMOOSGatewayConfig& cfg)
75 : goby::moos::Translator(cfg),
76 jaiabot_cfg_(cfg.GetExtension(jaiabot::protobuf::jaiabot_gateway_config)),
77 omit_var_(jaiabot_cfg_.logging_omit_var_regex()),
78 omit_app_(jaiabot_cfg_.logging_omit_app_regex())
79 {
80 moos().add_wildcard_trigger(
81 "*", "*",
82 [this](const CMOOSMsg& msg)
83 {
84 if (jaiabot_cfg_.has_logging_omit_var_regex() &&
85 std::regex_match(msg.m_sKey, omit_var_))
86 return;
87 if (jaiabot_cfg_.has_logging_omit_app_regex() &&
88 std::regex_match(msg.m_sSrc, omit_app_))
89 return;
90
92 pb_msg.set_type(static_cast<protobuf::MOOSMessage::Type>(msg.m_cDataType));
93 pb_msg.set_key(msg.m_sKey);
94 switch (pb_msg.type())
95 {
96 case protobuf::MOOSMessage::TYPE_DOUBLE: pb_msg.set_dvalue(msg.m_dfVal); break;
97 case protobuf::MOOSMessage::TYPE_STRING: pb_msg.set_svalue(msg.m_sVal); break;
99 pb_msg.set_bvalue(msg.m_sVal);
100 break;
101 }
102 pb_msg.set_unixtime(msg.m_dfTime);
103 pb_msg.set_id(msg.m_nID);
104 pb_msg.set_source(msg.m_sSrc);
105 pb_msg.set_source_aux(msg.m_sSrcAux);
106 pb_msg.set_community(msg.m_sOriginatingCommunity);
107 interprocess().publish<jaiabot::groups::moos>(pb_msg);
108 });
109 }
110
111 private:
112 const jaiabot::protobuf::MOOSGatewayConfig jaiabot_cfg_;
113 std::regex omit_var_;
114 std::regex omit_app_;
115};
116
117} // namespace moos
118} // namespace jaiabot
119
120#endif
AllMessagesForLoggingTranslation(const goby::apps::moos::protobuf::GobyMOOSGatewayConfig &cfg)
IvPHelmTranslation(const goby::apps::moos::protobuf::GobyMOOSGatewayConfig &cfg)
void set_source_aux(ArgT0 &&arg0, ArgT... args)
void set_unixtime(double value)
Definition moos.pb.h:793
void set_svalue(ArgT0 &&arg0, ArgT... args)
Definition moos.pb.h:599
void set_type(::jaiabot::protobuf::MOOSMessage_Type value)
Definition moos.pb.h:505
static constexpr Type TYPE_BINARY_STRING
Definition moos.pb.h:228
void set_id(int32_t value)
Definition moos.pb.h:821
void set_source(ArgT0 &&arg0, ArgT... args)
static constexpr Type TYPE_STRING
Definition moos.pb.h:226
void set_community(ArgT0 &&arg0, ArgT... args)
::jaiabot::protobuf::MOOSMessage_Type type() const
Definition moos.pb.h:496
void set_dvalue(double value)
Definition moos.pb.h:688
void set_key(ArgT0 &&arg0, ArgT... args)
static constexpr Type TYPE_DOUBLE
Definition moos.pb.h:224
void set_bvalue(ArgT0 &&arg0, ArgT... args)
Definition moos.pb.h:714
constexpr goby::middleware::Group mission_ivp_behavior_update
Definition groups.h:69
constexpr goby::middleware::Group mission_report
Definition groups.h:68
constexpr goby::middleware::Group moos
Definition groups.h:117
const std::string & MissionState_Name(T enum_t_value)
Definition mission.pb.h:275