Go to the documentation of this file.
10 #include <boost/lexical_cast.hpp>
11 #include <boost/regex.hpp>
12 #include <boost/thread/xtime.hpp>
13 #include <boost/date_time/local_time/local_time.hpp>
25 std::stringstream msg;
26 const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
27 boost::posix_time::time_facet *
const f =
new boost::posix_time::time_facet(
"%Y-%m-%d-%H-%M-%S");
28 msg.imbue(std::locale(msg.getloc(),
f));
49 std::map<SbgEComMagCalibBandwidth, std::string> SbgDevice::g_mag_calib_bandwidth_ = {{
SBG_ECOM_MAG_CALIB_HIGH_BW,
"High Bandwidth"},
61 ref_node_(ref_node_handle),
62 mag_calibration_ongoing_(false),
63 mag_calibration_done_(false)
91 ROS_ERROR(
"SBG DRIVER - Unable to close the communication interface.");
152 throw ros::Exception(
"Invalid interface type for the SBG device.");
199 return std::string(version);
213 auto rtcm_cb = [&](
const rtcm_msgs::Message::ConstPtr& msg) ->
void {
238 ref_ros_response.success =
true;
239 ref_ros_response.message =
"Magnetometer calibration is finished. See the output console to get calibration informations.";
243 ref_ros_response.success =
false;
244 ref_ros_response.message =
"Unable to end the calibration.";
254 ref_ros_response.success =
true;
255 ref_ros_response.message =
"Magnetometer calibration process started.";
259 ref_ros_response.success =
false;
260 ref_ros_response.message =
"Unable to start magnetometers calibration.";
266 return ref_ros_response.success;
275 ref_ros_response.success =
false;
276 ref_ros_response.message =
"Magnetometer calibration process is still ongoing, finish it before trying to save it.";
282 ref_ros_response.success =
true;
283 ref_ros_response.message =
"Magnetometer calibration has been uploaded to the device.";
287 ref_ros_response.success =
false;
288 ref_ros_response.message =
"Magnetometer calibration has not been uploaded to the device.";
293 ref_ros_response.success =
false;
294 ref_ros_response.message =
"No magnetometer calibration has been done.";
297 return ref_ros_response.success;
318 ROS_INFO(
"SBG DRIVER [Mag Calib] - Start calibration");
355 ROS_WARN(
"SBG DRIVER [Mag Calib] - Unable to set the magnetometers calibration data to the device : %s",
sbgErrorCodeToString(error_code));
360 ROS_INFO(
"SBG DRIVER [Mag Calib] - Saving data to the device");
368 ROS_ERROR(
"SBG DRIVER [Mag Calib] - The calibration was invalid, it can't be uploaded on the device.");
387 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough valid points. Maybe you are moving too fast");
391 ROS_WARN(
"SBG DRIVER [Mag Calib] - Unable to find a calibration solution. Maybe there are too much non static distortions");
395 ROS_WARN(
"SBG DRIVER [Mag Calib] - The magnetic calibration has troubles to correct the magnetometers and inertial frame alignment");
401 ROS_WARN(
"SBG DRIVER [Mag Calib] - Too much roll motion for a 2D magnetic calibration");
405 ROS_WARN(
"SBG DRIVER [Mag Calib] - Too much pitch motion for a 2D magnetic calibration");
412 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough roll motion for a 3D magnetic calibration");
416 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough pitch motion for a 3D magnetic calibration.");
421 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough yaw motion to compute a valid magnetic calibration");
429 ostringstream mag_results_stream;
430 string output_filename;
435 mag_results_stream <<
"SBG DRIVER [Mag Calib]" << endl;
436 mag_results_stream <<
"======= Parameters =======" << endl;
437 mag_results_stream <<
"* CALIB_MODE = " <<
g_mag_calib_mode_[mag_calib_mode] << endl;
440 mag_results_stream <<
"======= Results =======" << endl;
443 mag_results_stream <<
"======= Infos =======" << endl;
445 mag_results_stream <<
"* Mean, Std, Max" << endl;
451 mag_results_stream <<
"* Matrix" << endl;
457 ofstream output_file(output_filename);
458 output_file << mag_results_stream.str();
461 ROS_INFO(
"%s", mag_results_stream.str().c_str());
462 ROS_INFO(
"SBG DRIVER [Mag Calib] - Magnetometers calibration results saved to file %s", output_filename.c_str());
467 auto rtcm_data = msg->message;
513 ROS_INFO(
"SBG DRIVER [Init] - SBG device is initialized for magnetometers calibration.");
@ SBG_ECOM_MAG_CALIB_HIGH_BW
#define SBG_ECOM_MAG_CALIB_NOT_ENOUGH_POINTS
@ SBG_ECOM_MAG_CALIB_TRUST_LOW
SbgInterface sbg_interface_
#define SBG_ECOM_MAG_CALIB_Z_MOTION_ISSUE
sbgIpAddress getIpAddress() const
static const char * sbgErrorCodeToString(SbgErrorCode errorCode)
ros::NodeHandle & ref_node_
@ SBG_ECOM_MAG_CALIB_QUAL_GOOD
void exportMagCalibrationResults() const
SbgErrorCode sbgEComInit(SbgEComHandle *pHandle, SbgInterface *pInterface)
@ SBG_ECOM_MAG_CALIB_MODE_3D
SbgErrorCode sbgEComCmdMagStartCalib(SbgEComHandle *pHandle, SbgEComMagCalibMode mode, SbgEComMagCalibBandwidth bandwidth)
@ SBG_ECOM_MAG_CALIB_QUAL_OPTIMAL
static SbgErrorCode onLogReceivedCallback(SbgEComHandle *p_handle, SbgEComClass msg_class, SbgEComMsgId msg, const SbgBinaryLogData *p_log_data, void *p_user_arg)
SBG_COMMON_LIB_API SbgErrorCode sbgInterfaceSerialDestroy(SbgInterface *pHandle)
void initDeviceForReceivingData()
std::string timeToStr(ros::WallTime ros_t)
@ SBG_ECOM_MAG_CALIB_LOW_BW
#define SBG_ECOM_MAG_CALIB_ALIGNMENT_ISSUE
SbgErrorCode sbgInterfaceUdpDestroy(SbgInterface *pHandle)
static std::map< SbgEComMagCalibQuality, std::string > g_mag_calib_quality_
void displayMagCalibrationStatusResult() const
SbgErrorCode sbgEComSetReceiveLogCallback(SbgEComHandle *pHandle, SbgEComReceiveLogFunc pReceiveLogCallback, void *pUserArg)
SbgEComMagCalibResults mag_calib_results_
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
uint32_t getReadingRateFrequency() const
SBG_INLINE float sbgRadToDegF(float angle)
@ SBG_ECOM_MAG_CALIB_QUAL_POOR
void onLogReceived(SbgEComClass msg_class, SbgEComMsgId msg, const SbgBinaryLogData &ref_sbg_data)
ros::ServiceServer calib_save_service_
ros::Subscriber rtcm_sub_
void sbgEComErrorToString(SbgErrorCode errorCode, char errorMsg[256])
#define SBG_UNUSED_PARAMETER(x)
uint8_t productCode[SBG_ECOM_INFO_PRODUCT_CODE_LENGTH]
bool uploadMagCalibrationToDevice()
bool saveMagCalibration(std_srvs::Trigger::Request &ref_ros_request, std_srvs::Trigger::Response &ref_ros_response)
void publish(SbgEComClass sbg_msg_class, SbgEComMsgId sbg_msg_id, const SbgBinaryLogData &ref_sbg_log)
const std::string & getRtcmFullTopic() const
uint32_t getUpdateFrequency() const
SbgEComMagCalibConfidence confidence
void initDeviceForMagCalibration()
bool checkConfigWithRos() const
enum _SbgEComClass SbgEComClass
SBG_COMMON_LIB_API void sbgNetworkIpToString(sbgIpAddress ipAddr, char *pBuffer, size_t maxSize)
ConfigStore config_store_
SbgErrorCode sbgEComCmdMagComputeCalib(SbgEComHandle *pHandle, SbgEComMagCalibResults *pCalibResults)
uint32_t getOutputPortAddress() const
MessagePublisher message_publisher_
static std::map< SbgEComMagCalibBandwidth, std::string > g_mag_calib_bandwidth_
This file is used to parse received binary logs.
SbgEComHandle com_handle_
bool mag_calibration_ongoing_
bool mag_calibration_done_
bool isInterfaceSerial() const
#define SBG_LOG_ERROR(format,...)
SbgErrorCode sbgEComClose(SbgEComHandle *pHandle)
#define SBG_ECOM_MAG_CALIB_X_MOTION_ISSUE
@ SBG_ECOM_MAG_CALIB_MODE_2D
static std::map< SbgEComMagCalibConfidence, std::string > g_mag_calib_confidence_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
std::string getVersionAsString(uint32 sbg_version_enc) const
static std::map< SbgEComMagCalibMode, std::string > g_mag_calib_mode_
void applyConfiguration(const ConfigStore &ref_config_store)
uint32_t getInputPortAddress() const
#define SBG_ECOM_MAG_CALIB_TOO_MUCH_DISTORTIONS
SBG_COMMON_LIB_API SbgErrorCode sbgInterfaceSerialCreate(SbgInterface *pHandle, const char *deviceName, uint32_t baudRate)
SbgErrorCode sbgEComCmdGetInfo(SbgEComHandle *pHandle, SbgEComDeviceInfo *pInfo)
@ SBG_ECOM_MAG_CALIB_QUAL_INVALID
bool startMagCalibration()
void writeRtcmMessageToDevice(const rtcm_msgs::Message::ConstPtr &msg)
enum _SbgEComMagCalibMode SbgEComMagCalibMode
This file implements SbgECom commands related to Magnetometer module.
bool isInterfaceUdp() const
SbgEComMagCalibQuality quality
@ SBG_ECOM_MAG_CALIB_TRUST_HIGH
SbgErrorCode sbgEComHandle(SbgEComHandle *pHandle)
bool shouldSubscribeToRtcm() const
@ SBG_ECOM_MAG_CALIB_MEDIUM_BW
const SbgEComMagCalibBandwidth & getMagnetometerCalibBandwidth() const
void loadFromRosNodeHandle(const ros::NodeHandle &ref_node_handle)
enum _SbgErrorCode SbgErrorCode
Header file that defines all error codes for SBG Systems libraries.
SbgErrorCode sbgInterfaceUdpCreate(SbgInterface *pHandle, sbgIpAddress remoteAddr, uint32 remotePort, uint32 localPort)
const std::string & getUartPortName() const
void initPublishers(ros::NodeHandle &ref_ros_node_handle, const ConfigStore &ref_config_store)
SbgErrorCode sbgEComCmdMagSetCalibData(SbgEComHandle *pHandle, const float offset[3], const float matrix[9])
#define SBG_ECOM_MAG_CALIB_Y_MOTION_ISSUE
SBG_COMMON_LIB_API SbgErrorCode sbgVersionToStringEncoded(uint32_t version, char *pBuffer, uint32_t sizeOfBuffer)
const SbgEComMagCalibMode & getMagnetometerCalibMode() const
@ SBG_ECOM_MAG_CALIB_TRUST_MEDIUM
uint32_t getBaudRate() const
ros::ServiceServer calib_service_
enum _SbgEComMagCalibBandwidth SbgEComMagCalibBandwidth
bool processMagCalibration(std_srvs::Trigger::Request &ref_ros_request, std_srvs::Trigger::Response &ref_ros_response)
Implement device connection / parsing.
sbg_driver
Author(s): SBG Systems
autogenerated on Fri Oct 11 2024 02:13:40