Go to the documentation of this file.
16 #include <compass_msgs/Azimuth.h>
21 #include <geometry_msgs/Quaternion.h>
22 #include <geometry_msgs/QuaternionStamped.h>
23 #include <geometry_msgs/PoseWithCovarianceStamped.h>
26 #include <sensor_msgs/Imu.h>
27 #include <sensor_msgs/NavSatFix.h>
28 #include <std_msgs/Header.h>
34 struct CompassConverterPrivate;
118 virtual void setNavSatPos(
const sensor_msgs::NavSatFix& fix);
136 const sensor_msgs::NavSatFix& fix,
const ros::Time& stamp)
const;
153 virtual cras::expected<int, std::string>
getUTMZone()
const;
160 virtual void forceUTMZone(
const cras::optional<int>& zone);
170 const sensor_msgs::NavSatFix& fix,
const cras::optional<int>& utmZone)
const;
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;
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;
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;
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;
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;
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;
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;
305 const compass_msgs::Azimuth& azimuth)
const;
313 virtual cras::expected<geometry_msgs::PoseWithCovarianceStamped, std::string>
convertToPose(
314 const compass_msgs::Azimuth& azimuth)
const;
322 virtual cras::expected<sensor_msgs::Imu, std::string>
convertToImu(
const compass_msgs::Azimuth& azimuth)
const;
350 cras::optional<sensor_msgs::NavSatFix>
lastFix;
353 std::unique_ptr<CompassConverterPrivate>
data;
cras::optional< int > lastUTMZone
Last determined UTM zone. If empty, no zone has been determined yet.
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().
cras::optional< int > forcedUTMZone
The user-forced UTM zone (if set, do not compute it).
cras::optional< double > forcedUTMGridConvergence
The user-forced UTM grid convergence (if set, do not compute it).
bool strict
If true, convertAzimuth() will fail when the magnetic model is used outside its bounds.
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.
virtual void forceMagneticDeclination(const cras::optional< double > &declination)
Force magnetic declination instead of computing it.
CompassConverter(const cras::LogHelperPtr &log, bool strict)
Create the compass converter.
virtual void setKeepUTMZone(bool keep)
Set whether UTM zone should be kept after it is first computed.
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,...
Convert between various compass representations.
virtual cras::expected< int, std::string > getUTMZone() const
Get the UTM zone of the last location received by setNatSatPos().
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,...
virtual void forceMagneticModelName(const std::string &model)
Force using the given magnetic model instead of automatically selecting the best one.
cras::optional< double > lastUTMGridConvergence
UTM convergence of the last received navsat position (or the forced one).
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,...
bool keepUTMZone
If true, the first determined UTM zone will be kept for all future queries.
virtual void forceUTMZone(const cras::optional< int > &zone)
Set the UTM zone that will be used for all future UTM operations.
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...
std::string forcedMagneticModelName
If the user forces a magnetic model, this is its name.
void configFromParams(const cras::BoundParamHelper ¶ms)
Configure the compass converter from the given ROS parameters.
virtual ~CompassConverter()
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.
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.
::cras::LogHelper::Ptr LogHelperPtr
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.
cras::optional< sensor_msgs::NavSatFix > lastFix
Last received GNSS fix. Used for determining magnetic declination and UTM grid convergence.
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...
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...
virtual cras::expected< double, std::string > getUTMGridConvergence() const
Get the value of UTM grid convergence for the last location received by setNatSatPos().
virtual void forceUTMGridConvergence(const cras::optional< double > &convergence)
Force UTM grid convergence instead of computing it.
std::unique_ptr< CompassConverterPrivate > data
PIMPL data.
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...
virtual void setMagneticModelPath(const cras::optional< std::string > &modelPath)
Set the path where magnetic models are stored.
cras::optional< double > forcedMagneticDeclination
The user-forced magnetic declination (if set, do not compute it).
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).