Goby3  3.1.5a
2024.05.23
frontseat_gateway_plugin.h
Go to the documentation of this file.
1 // Copyright 2020-2021:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Goby Underwater Autonomy Project Libraries
9 // ("The Goby Libraries").
10 //
11 // The Goby Libraries are free software: you can redistribute them and/or modify
12 // them under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // The Goby Libraries are distributed in the hope that they will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef GOBY_MOOS_MIDDLEWARE_FRONTSEAT_FRONTSEAT_GATEWAY_PLUGIN_H
25 #define GOBY_MOOS_MIDDLEWARE_FRONTSEAT_FRONTSEAT_GATEWAY_PLUGIN_H
26 
27 #include <ostream> // for basic_ostream
28 #include <string> // for string, bas...
29 #include <vector> // for vector
30 
31 #include <MOOS/libMOOS/Comms/MOOSMsg.h> // for CMOOSMsg
32 #include <boost/algorithm/string/predicate.hpp> // for iequals
33 #include <boost/algorithm/string/trim.hpp> // for trim
34 
36 
37 #include "goby/middleware/application/multi_thread.h" // for SimpleThread
38 #include "goby/middleware/frontseat/groups.h" // for helm_state
39 #include "goby/middleware/marshalling/interface.h" // for Marshalling...
40 #include "goby/middleware/protobuf/frontseat.pb.h" // for HelmStateRe...
41 #include "goby/middleware/protobuf/frontseat_data.pb.h" // for NodeStatus
42 #include "goby/middleware/transport/interprocess.h" // for InterProces...
43 #include "goby/moos/frontseat/convert.h" // for convert_and...
44 #include "goby/moos/middleware/moos_plugin_translator.h" // for TranslatorB...
45 #include "goby/util/debug_logger/flex_ostream.h" // for operator<<
46 
47 namespace goby
48 {
49 namespace apps
50 {
51 namespace moos
52 {
53 namespace protobuf
54 {
55 class GobyMOOSGatewayConfig;
56 } // namespace protobuf
57 } // namespace moos
58 } // namespace apps
59 
60 namespace moos
61 {
63 {
64  public:
66  : goby::moos::Translator(cfg)
67  {
68  goby()
69  .interprocess()
74  glog.is_debug2() && glog << "Posting to MOOS: NAV: " << status.DebugString()
75  << std::endl;
77  });
78 
79  std::vector<std::string> desired_buffer_params(
80  {"SPEED", "HEADING", "DEPTH", "PITCH", "ROLL", "Z_RATE", "ALTITUDE"});
81  for (const auto& var : desired_buffer_params) moos().add_buffer("DESIRED_" + var);
82  moos().add_trigger("DESIRED_SPEED",
83  [this](const CMOOSMsg& /*msg*/) { convert_desired_setpoints(); });
84 
85  moos().add_trigger("IVPHELM_STATE", [this](const CMOOSMsg& msg) {
87  std::string sval = msg.GetString();
88  boost::trim(sval);
89  if (boost::iequals(sval, "drive"))
91  else if (boost::iequals(sval, "park"))
93  else
94  helm_state_report.set_state(
96  goby().interprocess().publish<goby::middleware::frontseat::groups::helm_state>(
97  helm_state_report);
98  });
99  }
100 
101  private:
102  void convert_desired_setpoints();
103 };
104 } // namespace moos
105 } // namespace goby
106 
107 #endif
goby::middleware::frontseat::protobuf::HELM_PARK
@ HELM_PARK
Definition: frontseat.pb.h:160
goby::middleware::frontseat::protobuf::NodeStatus
Definition: frontseat_data.pb.h:227
goby::moos::FrontSeatTranslation
Definition: frontseat_gateway_plugin.h:62
interface.h
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::frontseat::protobuf::HelmStateReport::set_state
void set_state(::goby::middleware::frontseat::protobuf::HelmState value)
Definition: frontseat.pb.h:1156
protobuf.h
goby::apps::moos::protobuf::GobyMOOSGatewayConfig
Definition: moos_gateway_config.pb.h:238
frontseat.pb.h
goby::middleware::frontseat::groups::helm_state
constexpr goby::middleware::Group helm_state
Definition: groups.h:52
goby::middleware::MarshallingScheme::PROTOBUF
@ PROTOBUF
Definition: interface.h:53
goby::util::FlexOstream::is_debug2
bool is_debug2()
Definition: flex_ostream.h:85
frontseat_data.pb.h
goby::moos::TranslatorBase::moos
MOOSInterface & moos()
Definition: moos_plugin_translator.h:127
CMOOSMsg
goby::middleware::acomms::groups::status
constexpr Group status
Definition: groups.h:43
goby::moos::FrontSeatTranslation::FrontSeatTranslation
FrontSeatTranslation(const goby::apps::moos::protobuf::GobyMOOSGatewayConfig &cfg)
Definition: frontseat_gateway_plugin.h:65
multi_thread.h
moos_plugin_translator.h
goby::moos::convert_and_publish_node_status
void convert_and_publish_node_status(const goby::middleware::frontseat::protobuf::NodeStatus &status, CMOOSCommClient &moos_comms)
convert.h
goby::middleware::frontseat::protobuf::HELM_NOT_RUNNING
@ HELM_NOT_RUNNING
Definition: frontseat.pb.h:158
goby::moos::BasicTranslator
Definition: moos_plugin_translator.h:136
goby::middleware::frontseat::protobuf::HelmStateReport
Definition: frontseat.pb.h:220
interprocess.h
groups.h
flex_ostream.h
goby::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:1327
goby::middleware::frontseat::groups::node_status
constexpr goby::middleware::Group node_status
Definition: groups.h:37
goby::moos::TranslatorBase::MOOSInterface::add_trigger
void add_trigger(const std::string &moos_var, const std::function< void(const CMOOSMsg &)> &func)
Definition: moos_plugin_translator.h:70
goby::middleware::frontseat::protobuf::HELM_DRIVE
@ HELM_DRIVE
Definition: frontseat.pb.h:159
httplib::detail::trim
std::pair< size_t, size_t > trim(const char *b, const char *e, size_t left, size_t right)
Definition: httplib.h:2472
goby::glog
util::FlexOstream glog
Access the Goby logger through this object.
goby::moos::BasicTranslator::goby
ThreadType< goby::apps::moos::protobuf::GobyMOOSGatewayConfig > & goby()
Definition: moos_plugin_translator.h:149
goby::moos::TranslatorBase::MOOSInterface::add_buffer
void add_buffer(const std::string &moos_var)
Definition: moos_plugin_translator.h:88