compass_converter.h
Go to the documentation of this file.
1 #pragma once
2 
3 // SPDX-License-Identifier: BSD-3-Clause
4 // SPDX-FileCopyrightText: Czech Technical University in Prague
5 
12 #include <memory>
13 #include <string>
14 #include <utility>
15 
16 #include <compass_msgs/Azimuth.h>
21 #include <geometry_msgs/Quaternion.h>
22 #include <geometry_msgs/QuaternionStamped.h>
23 #include <geometry_msgs/PoseWithCovarianceStamped.h>
24 #include <ros/message_event.h>
25 #include <ros/time.h>
26 #include <sensor_msgs/Imu.h>
27 #include <sensor_msgs/NavSatFix.h>
28 #include <std_msgs/Header.h>
30 
32 {
33 
34 struct CompassConverterPrivate;
35 
44 {
45 public:
53  virtual ~CompassConverter();
54 
75  void configFromParams(const cras::BoundParamHelper& params);
76 
81  virtual void forceMagneticDeclination(const cras::optional<double>& declination);
82 
87  virtual void forceUTMGridConvergence(const cras::optional<double>& convergence);
88 
96  virtual void setMagneticModelPath(const cras::optional<std::string>& modelPath);
97 
102  virtual void forceMagneticModelName(const std::string& model);
103 
108  virtual void setKeepUTMZone(bool keep);
109 
118  virtual void setNavSatPos(const sensor_msgs::NavSatFix& fix);
119 
126  virtual cras::expected<double, std::string> getMagneticDeclination(const ros::Time& stamp) const;
127 
135  virtual cras::expected<double, std::string> computeMagneticDeclination(
136  const sensor_msgs::NavSatFix& fix, const ros::Time& stamp) const;
137 
146  virtual cras::expected<double, std::string> getUTMGridConvergence() const;
147 
153  virtual cras::expected<int, std::string> getUTMZone() const;
154 
160  virtual void forceUTMZone(const cras::optional<int>& zone);
161 
169  virtual cras::expected<std::pair<double, int>, std::string> computeUTMGridConvergenceAndZone(
170  const sensor_msgs::NavSatFix& fix, const cras::optional<int>& utmZone) const;
171 
184  virtual cras::expected<compass_msgs::Azimuth, std::string> convertAzimuth(
185  const compass_msgs::Azimuth& azimuth,
186  decltype(compass_msgs::Azimuth::unit) unit,
187  decltype(compass_msgs::Azimuth::orientation) orientation,
188  decltype(compass_msgs::Azimuth::reference) reference) const;
189 
201  virtual cras::expected<compass_msgs::Azimuth, std::string> convertQuaternion(
202  const geometry_msgs::QuaternionStamped& quat,
203  decltype(compass_msgs::Azimuth::variance) variance,
204  decltype(compass_msgs::Azimuth::unit) unit,
205  decltype(compass_msgs::Azimuth::orientation) orientation,
206  decltype(compass_msgs::Azimuth::reference) reference) const;
207 
220  virtual cras::expected<compass_msgs::Azimuth, std::string> convertQuaternion(
221  const geometry_msgs::Quaternion& quat,
222  const std_msgs::Header& header,
223  decltype(compass_msgs::Azimuth::variance) variance,
224  decltype(compass_msgs::Azimuth::unit) unit,
225  decltype(compass_msgs::Azimuth::orientation) orientation,
226  decltype(compass_msgs::Azimuth::reference) reference) const;
227 
239  cras::expected<compass_msgs::Azimuth, std::string> convertQuaternionMsgEvent(
241  decltype(compass_msgs::Azimuth::variance) variance = 0,
242  decltype(compass_msgs::Azimuth::unit) unit = compass_msgs::Azimuth::UNIT_RAD,
243  const cras::optional<decltype(compass_msgs::Azimuth::orientation)>& orientation = {},
244  const cras::optional<decltype(compass_msgs::Azimuth::reference)>& reference = {}) const;
245 
256  cras::expected<compass_msgs::Azimuth, std::string> convertPoseMsgEvent(
258  decltype(compass_msgs::Azimuth::unit) unit = compass_msgs::Azimuth::UNIT_RAD,
259  const cras::optional<decltype(compass_msgs::Azimuth::orientation)>& orientation = {},
260  const cras::optional<decltype(compass_msgs::Azimuth::reference)>& reference = {}) const;
261 
272  cras::expected<compass_msgs::Azimuth, std::string> convertImuMsgEvent(
274  decltype(compass_msgs::Azimuth::unit) unit = compass_msgs::Azimuth::UNIT_RAD,
275  const cras::optional<decltype(compass_msgs::Azimuth::orientation)>& orientation = {},
276  const cras::optional<decltype(compass_msgs::Azimuth::reference)>& reference = {}) const;
277 
291  cras::expected<compass_msgs::Azimuth, std::string> convertUniversalMsgEvent(
293  decltype(compass_msgs::Azimuth::variance) variance = 0,
294  decltype(compass_msgs::Azimuth::unit) unit = compass_msgs::Azimuth::UNIT_RAD,
295  const cras::optional<decltype(compass_msgs::Azimuth::orientation)>& orientation = {},
296  const cras::optional<decltype(compass_msgs::Azimuth::reference)>& reference = {}) const;
297 
304  virtual cras::expected<geometry_msgs::QuaternionStamped, std::string> convertToQuaternion(
305  const compass_msgs::Azimuth& azimuth) const;
306 
313  virtual cras::expected<geometry_msgs::PoseWithCovarianceStamped, std::string> convertToPose(
314  const compass_msgs::Azimuth& azimuth) const;
315 
322  virtual cras::expected<sensor_msgs::Imu, std::string> convertToImu(const compass_msgs::Azimuth& azimuth) const;
323 
324 protected:
326  cras::optional<double> lastUTMGridConvergence;
327 
329  cras::optional<int> lastUTMZone;
330 
332  cras::optional<double> forcedMagneticDeclination;
333 
335  cras::optional<double> forcedUTMGridConvergence;
336 
338  cras::optional<int> forcedUTMZone;
339 
341  bool keepUTMZone {true};
342 
344  std::string forcedMagneticModelName{};
345 
347  bool strict {true};
348 
350  cras::optional<sensor_msgs::NavSatFix> lastFix;
351 
353  std::unique_ptr<CompassConverterPrivate> data;
354 };
355 
356 }
optional.hpp
compass_conversions::CompassConverter::lastUTMZone
cras::optional< int > lastUTMZone
Last determined UTM zone. If empty, no zone has been determined yet.
Definition: compass_converter.h:329
compass_conversions::CompassConverter::getMagneticDeclination
virtual cras::expected< double, std::string > getMagneticDeclination(const ros::Time &stamp) const
Get the value of magnetic declination for the last location received by setNatSatPos().
compass_conversions::CompassConverter::forcedUTMZone
cras::optional< int > forcedUTMZone
The user-forced UTM zone (if set, do not compute it).
Definition: compass_converter.h:338
compass_conversions::CompassConverter::forcedUTMGridConvergence
cras::optional< double > forcedUTMGridConvergence
The user-forced UTM grid convergence (if set, do not compute it).
Definition: compass_converter.h:335
compass_conversions::CompassConverter::strict
bool strict
If true, convertAzimuth() will fail when the magnetic model is used outside its bounds.
Definition: compass_converter.h:347
compass_conversions::CompassConverter::computeMagneticDeclination
virtual cras::expected< double, std::string > computeMagneticDeclination(const sensor_msgs::NavSatFix &fix, const ros::Time &stamp) const
Compute magnetic declination for the given position and time.
compass_conversions
Definition: compass_converter.h:31
compass_conversions::CompassConverter::forceMagneticDeclination
virtual void forceMagneticDeclination(const cras::optional< double > &declination)
Force magnetic declination instead of computing it.
compass_conversions::CompassConverter::CompassConverter
CompassConverter(const cras::LogHelperPtr &log, bool strict)
Create the compass converter.
time.h
compass_conversions::CompassConverter::setKeepUTMZone
virtual void setKeepUTMZone(bool keep)
Set whether UTM zone should be kept after it is first computed.
compass_conversions::CompassConverter::convertPoseMsgEvent
cras::expected< compass_msgs::Azimuth, std::string > convertPoseMsgEvent(const ros::MessageEvent< geometry_msgs::PoseWithCovarianceStamped const > &poseEvent, decltype(compass_msgs::Azimuth::unit) unit=compass_msgs::Azimuth::UNIT_RAD, const cras::optional< decltype(compass_msgs::Azimuth::orientation)> &orientation={}, const cras::optional< decltype(compass_msgs::Azimuth::reference)> &reference={}) const
Convert a received geometry_msgs::PoseWithCovarianceStamped message to Azimuth. If needed,...
cras::HasLogger
compass_conversions::CompassConverter
Convert between various compass representations.
Definition: compass_converter.h:43
compass_conversions::CompassConverter::getUTMZone
virtual cras::expected< int, std::string > getUTMZone() const
Get the UTM zone of the last location received by setNatSatPos().
compass_conversions::CompassConverter::convertQuaternion
virtual cras::expected< compass_msgs::Azimuth, std::string > convertQuaternion(const geometry_msgs::QuaternionStamped &quat, decltype(compass_msgs::Azimuth::variance) variance, decltype(compass_msgs::Azimuth::unit) unit, decltype(compass_msgs::Azimuth::orientation) orientation, decltype(compass_msgs::Azimuth::reference) reference) const
Convert the given geometry_msgs::QuaternionStamped message to Azimuth parametrized by the given unit,...
compass_conversions::CompassConverter::forceMagneticModelName
virtual void forceMagneticModelName(const std::string &model)
Force using the given magnetic model instead of automatically selecting the best one.
cras::BoundParamHelper
log_utils.h
compass_conversions::CompassConverter::lastUTMGridConvergence
cras::optional< double > lastUTMGridConvergence
UTM convergence of the last received navsat position (or the forced one).
Definition: compass_converter.h:326
compass_conversions::CompassConverter::convertQuaternionMsgEvent
cras::expected< compass_msgs::Azimuth, std::string > convertQuaternionMsgEvent(const ros::MessageEvent< geometry_msgs::QuaternionStamped const > &quatEvent, decltype(compass_msgs::Azimuth::variance) variance=0, decltype(compass_msgs::Azimuth::unit) unit=compass_msgs::Azimuth::UNIT_RAD, const cras::optional< decltype(compass_msgs::Azimuth::orientation)> &orientation={}, const cras::optional< decltype(compass_msgs::Azimuth::reference)> &reference={}) const
Convert a received geometry_msgs::QuaternionStamped message to Azimuth. If needed,...
compass_conversions::CompassConverter::keepUTMZone
bool keepUTMZone
If true, the first determined UTM zone will be kept for all future queries.
Definition: compass_converter.h:341
compass_conversions::CompassConverter::forceUTMZone
virtual void forceUTMZone(const cras::optional< int > &zone)
Set the UTM zone that will be used for all future UTM operations.
compass_conversions::CompassConverter::convertToPose
virtual cras::expected< geometry_msgs::PoseWithCovarianceStamped, std::string > convertToPose(const compass_msgs::Azimuth &azimuth) const
Convert the given Azimuth message to geometry_msgs::PoseWithCovarianceStamped in the same parametriza...
compass_conversions::CompassConverter::forcedMagneticModelName
std::string forcedMagneticModelName
If the user forces a magnetic model, this is its name.
Definition: compass_converter.h:344
compass_conversions::CompassConverter::configFromParams
void configFromParams(const cras::BoundParamHelper &params)
Configure the compass converter from the given ROS parameters.
bound_param_helper.hpp
compass_conversions::CompassConverter::~CompassConverter
virtual ~CompassConverter()
compass_conversions::CompassConverter::convertToImu
virtual cras::expected< sensor_msgs::Imu, std::string > convertToImu(const compass_msgs::Azimuth &azimuth) const
Convert the given Azimuth message to sensor_msgs::Imu in the same parametrization.
compass_conversions::CompassConverter::computeUTMGridConvergenceAndZone
virtual cras::expected< std::pair< double, int >, std::string > computeUTMGridConvergenceAndZone(const sensor_msgs::NavSatFix &fix, const cras::optional< int > &utmZone) const
Get the value of UTM grid convergence and UTM zone for the provided place.
shape_shifter.h
expected.hpp
cras::LogHelperPtr
::cras::LogHelper::Ptr LogHelperPtr
ros::Time
compass_conversions::CompassConverter::convertToQuaternion
virtual cras::expected< geometry_msgs::QuaternionStamped, std::string > convertToQuaternion(const compass_msgs::Azimuth &azimuth) const
Convert the given Azimuth message to geometry_msgs::QuaternionStamped in the same parametrization.
compass_conversions::CompassConverter::lastFix
cras::optional< sensor_msgs::NavSatFix > lastFix
Last received GNSS fix. Used for determining magnetic declination and UTM grid convergence.
Definition: compass_converter.h:350
compass_conversions::CompassConverter::convertImuMsgEvent
cras::expected< compass_msgs::Azimuth, std::string > convertImuMsgEvent(const ros::MessageEvent< sensor_msgs::Imu const > &imuEvent, decltype(compass_msgs::Azimuth::unit) unit=compass_msgs::Azimuth::UNIT_RAD, const cras::optional< decltype(compass_msgs::Azimuth::orientation)> &orientation={}, const cras::optional< decltype(compass_msgs::Azimuth::reference)> &reference={}) const
Convert a received sensor_msgs::Imu message to Azimuth. If needed, extract the orientation and refere...
compass_conversions::CompassConverter::convertUniversalMsgEvent
cras::expected< compass_msgs::Azimuth, std::string > convertUniversalMsgEvent(const ros::MessageEvent< topic_tools::ShapeShifter const > &event, decltype(compass_msgs::Azimuth::variance) variance=0, decltype(compass_msgs::Azimuth::unit) unit=compass_msgs::Azimuth::UNIT_RAD, const cras::optional< decltype(compass_msgs::Azimuth::orientation)> &orientation={}, const cras::optional< decltype(compass_msgs::Azimuth::reference)> &reference={}) const
Convert a received message to Azimuth. If needed, extract the orientation and reference from the topi...
cras::HasLogger::log
::cras::LogHelperPtr log
compass_conversions::CompassConverter::getUTMGridConvergence
virtual cras::expected< double, std::string > getUTMGridConvergence() const
Get the value of UTM grid convergence for the last location received by setNatSatPos().
compass_conversions::CompassConverter::forceUTMGridConvergence
virtual void forceUTMGridConvergence(const cras::optional< double > &convergence)
Force UTM grid convergence instead of computing it.
compass_conversions::CompassConverter::data
std::unique_ptr< CompassConverterPrivate > data
PIMPL data.
Definition: compass_converter.h:353
header
const std::string header
message_event.h
compass_conversions::CompassConverter::convertAzimuth
virtual cras::expected< compass_msgs::Azimuth, std::string > convertAzimuth(const compass_msgs::Azimuth &azimuth, decltype(compass_msgs::Azimuth::unit) unit, decltype(compass_msgs::Azimuth::orientation) orientation, decltype(compass_msgs::Azimuth::reference) reference) const
Convert the given compass_msgs::Azimuth message parametrized by the given unit, orientation and refer...
compass_conversions::CompassConverter::setMagneticModelPath
virtual void setMagneticModelPath(const cras::optional< std::string > &modelPath)
Set the path where magnetic models are stored.
compass_conversions::CompassConverter::forcedMagneticDeclination
cras::optional< double > forcedMagneticDeclination
The user-forced magnetic declination (if set, do not compute it).
Definition: compass_converter.h:332
compass_conversions::CompassConverter::setNavSatPos
virtual void setNavSatPos(const sensor_msgs::NavSatFix &fix)
Callback for GNSS fix (so that the converter can compute UTM grid convergence and store the pose).
ros::MessageEvent


compass_conversions
Author(s): Martin Pecka
autogenerated on Mon Dec 23 2024 04:03:21