ROSaic
rosaic_node.hpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // © Copyright 2020, Septentrio NV/SA.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // 3. Neither the name of the copyright holder nor the names of its
14 // contributors may be used to endorse or promote products derived
15 // from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 // *****************************************************************************
30 
31 // *****************************************************************************
32 //
33 // Boost Software License - Version 1.0 - August 17th, 2003
34 //
35 // Permission is hereby granted, free of charge, to any person or organization
36 // obtaining a copy of the software and accompanying documentation covered by
37 // this license (the "Software") to use, reproduce, display, distribute,
38 // execute, and transmit the Software, and to prepare derivative works of the
39 // Software, and to permit third-parties to whom the Software is furnished to
40 // do so, all subject to the following:
41 
42 // The copyright notices in the Software and this entire statement, including
43 // the above license grant, this restriction and the following disclaimer,
44 // must be included in all copies of the Software, in whole or in part, and
45 // all derivative works of the Software, unless such copies or derivative
46 // works are solely in the form of machine-executable object code generated by
47 // a source language processor.
48 //
49 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
52 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
53 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
54 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
55 // DEALINGS IN THE SOFTWARE.
56 //
57 // *****************************************************************************
58 
59 #ifndef ROSAIC_NODE_HPP
60 #define ROSAIC_NODE_HPP
61 
68 // ROS includes
69 #include <ros/console.h>
70 // Boost includes
71 #include <boost/regex.hpp>
72 // ROSaic includes
74 
75 extern bool g_publish_gpgga;
76 extern bool g_publish_pvtcartesian;
77 extern bool g_publish_pvtgeodetic;
78 extern bool g_publish_poscovgeodetic;
79 extern bool g_publish_poscovcartesian;
80 extern bool g_publish_atteuler;
81 extern bool g_publish_attcoveuler;
82 extern bool g_publish_gpst;
83 extern bool g_publish_navsatfix;
84 extern ros::Timer g_reconnect_timer_;
85 extern boost::shared_ptr<ros::NodeHandle> g_nh;
86 extern const uint32_t g_ROS_QUEUE_SIZE;
87 
93 namespace rosaic_node
94 {
97 
106  template <typename V, typename T>
107  void checkRange(V val, T min, T max, std::string name)
108  {
109  if(val < min || val > max)
110  {
111  std::stringstream ss;
112  ss << "Invalid settings: " << name << " must be in range [" << min << ", " << max << "].";
113  throw std::runtime_error(ss.str());
114  }
115  }
116 
124  template <typename V, typename T>
125  void checkRange(std::vector<V> val, T min, T max, std::string name)
126  {
127  for(size_t i = 0; i < val.size(); i++)
128  {
129  std::stringstream ss;
130  ss << name << "[" << i << "]";
131  checkRange(val[i], min, max, ss.str());
132  }
133  }
134 
142  template <typename U>
143  bool getROSInt(const std::string& key, U &u) {
144  int param;
145  if (!g_nh->getParam(key, param)) return false;
146  U min = std::numeric_limits<U>::lowest();
147  U max = std::numeric_limits<U>::max();
148  try
149  {
150  checkRange((U) param, min, max, key);
151  }
152  catch (std::runtime_error& e)
153  {
154  std::ostringstream ss;
155  ss << e.what();
156  ROS_INFO("%s", ss.str().c_str());
157  }
158  u = (U) param;
159  return true;
160  }
161 
170  template <typename U>
171  void getROSInt(const std::string& key, U &u, U default_val)
172  {
173  if(!getROSInt(key, u))
174  u = default_val;
175  }
176 
184  template <typename U>
185  bool getROSInt(const std::string& key, std::vector<U> &u)
186  {
187  std::vector<int> param;
188  if (!g_nh->getParam(key, param)) return false;
189  U min = std::numeric_limits<U>::lowest();
190  U max = std::numeric_limits<U>::max();
191  checkRange(param, min, max, key);
192  u.insert(u.begin(), param.begin(), param.end());
193  return true;
194  }
195 
201  {
202  public:
203 
206  ROSaicNode();
207 
213  void getROSParams();
214 
218  void defineMessages();
219 
223  void configureRx();
224 
228  void initializeIO();
229 
233  void reconnect(const ros::TimerEvent& event);
234 
238  void connect();
239 
240 
241 
242  private:
244  std::string device_;
246  uint32_t baudrate_;
248  std::string hw_flow_control_;
250  std::string rx_serial_port_;
254  std::string datum_;
262  float delta_e_;
264  float delta_n_;
266  float delta_u_;
268  std::string ant_type_;
270  std::string ant_serial_nr_;
272  std::string mode_;
274  std::string caster_;
276  uint32_t caster_port_;
278  std::string username_;
280  std::string password_;
282  std::string mountpoint_;
284  std::string ntrip_version_;
288  std::string rtcm_version_;
294  ros::Timer reconnect_timer_;
296  std::string send_gga_;
319  boost::mutex connection_mutex_;
322  boost::condition_variable connection_condition_;
324  std::string tcp_host_;
326  std::string tcp_port_;
328  bool serial_;
329  };
330 }
331 
332 #endif // for ROSAIC_NODE_HPP
std::string rtcm_version_
RTCM version for NTRIP service (if Rx does not have internet)
uint32_t polling_period_pvt_
Polling period for PVT-related SBF blocks.
std::string password_
Password for NTRIP service.
bool publish_attcoveuler_
Whether or not to publish the rosaic::AttCovEuler message.
boost::mutex connection_mutex_
bool publish_gprmc_
Whether or not to publish the RMC message.
bool serial_
Whether yet-to-be-established connection to Rx will be serial or TCP.
uint32_t polling_period_rest_
Polling period for all other SBF blocks and NMEA messages.
bool rx_has_internet_
Whether Rx has internet or not.
bool publish_pvtcartesian_
Whether or not to publish the rosaic::PVTCartesian message.
bool g_publish_navsatfix
Whether or not to publish the sensor_msgs::NavSatFix message.
bool g_publish_poscovgeodetic
bool g_publish_gpgga
bool publish_poscovcartesian_
Whether or not to publish the rosaic::PosCovCartesian message.
Highest-Level view on communication services.
bool g_publish_atteuler
std::string ant_type_
Antenna type, from the list returned by the command "lstAntennaInfo, Overview".
ros::Timer g_reconnect_timer_
std::string rx_serial_port_
In case of serial communication to Rx, rx_serial_port_ specifies Rx&#39;s serial port connected to...
void connect()
Calles the reconnect() method.
void getROSParams()
Gets the node parameters from the ROS Parameter Server, parts of which are specified in a YAML file...
bool g_publish_pvtgeodetic
uint32_t rx_input_corrections_tcp_
Rx TCP port number, e.g. 28785, on which Rx receives the corrections (can&#39;t be the same as main conne...
bool publish_poscovgeodetic_
Whether or not to publish the rosaic::PosCovGeodetic message.
bool publish_atteuler_
Whether or not to publish the rosaic::AttEuler message.
float delta_n_
Marker-to-ARP offset in the northward direction.
bool publish_pvtgeodetic_
Whether or not to publish the rosaic::PVTGeodetic message.
void defineMessages()
Defines which Rx messages to read and which ROS messages to publish.
void initializeIO()
Initializes the I/O handling.
bool publish_gpgsv_
Whether or not to publish the GSV message.
uint32_t caster_port_
IP port number of NTRIP caster to connect to.
std::string tcp_port_
TCP port number.
boost::condition_variable connection_condition_
Handles communication with and configuration of the mosaic (and beyond) receiver(s) ...
std::string ant_serial_nr_
Serial number of your particular antenna.
boost::shared_ptr< ros::NodeHandle > g_nh
void reconnect(const ros::TimerEvent &event)
Attempts to (re)connect every reconnect_delay_s_ seconds.
bool g_publish_pvtcartesian
uint32_t baudrate_
Baudrate.
std::string username_
Username for NTRIP service.
std::string mountpoint_
Mountpoint for NTRIP service.
const uint32_t g_ROS_QUEUE_SIZE
Queue size for ROS publishers.
bool publish_gpgga_
Whether or not to publish the GGA message.
bool getROSInt(const std::string &key, U &u)
Gets an integer or unsigned integer value from the parameter server.
float reconnect_delay_s_
Delay in seconds between reconnection attempts to the connection type specified in the parameter conn...
std::string tcp_host_
Host name of TCP server.
std::string mode_
Type of NTRIP connection.
std::string send_gga_
Whether (and at which rate) or not to send GGA to the NTRIP caster.
bool connected_
Whether connecting to Rx was successful.
void checkRange(V val, T min, T max, std::string name)
Checks whether the parameter is in the given range.
bool g_publish_poscovcartesian
bool g_publish_attcoveuler
void configureRx()
Configures Rx: Which SBF/NMEA messages it should output and later correction settings.
Definition: rosaic_node.cpp:70
float delta_e_
Marker-to-ARP offset in the eastward direction.
std::string device_
Device port.
std::string rx_input_corrections_serial_
Rx serial port, e.g. USB2, on which Rx receives the corrections (can&#39;t be the same as main connection...
bool publish_gpgsa_
Whether or not to publish the GSA message.
std::string datum_
Datum to be used.
std::string caster_
Hostname or IP address of the NTRIP caster to connect to.
bool g_publish_gpst
Whether or not to publish the sensor_msgs::TimeReference message with GPST.
ros::Timer reconnect_timer_
Our ROS timer governing the reconnection.
std::string ntrip_version_
NTRIP version for NTRIP service.
This class represents the ROsaic node, to be extended..
io_comm_rx::Comm_IO IO
Handles communication with the Rx.
Definition: rosaic_node.hpp:96
float delta_u_
Marker-to-ARP offset in the upward direction.
std::string hw_flow_control_
HW flow control.