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));
48 std::map<SbgEComMagCalibBandwidth, std::string> SbgDevice::g_mag_calib_bandwidth = {{
SBG_ECOM_MAG_CALIB_HIGH_BW,
"High Bandwidth"},
60 m_ref_node_(ref_node_handle),
61 m_mag_calibration_ongoing_(false),
62 m_mag_calibration_done_(false)
90 ROS_ERROR(
"SBG DRIVER - Unable to close the communication interface.");
147 throw ros::Exception(
"Invalid interface type for the SBG device.");
192 return std::string(version);
229 ref_ros_response.success =
true;
230 ref_ros_response.message =
"Magnetometer calibration is finished. See the output console to get calibration informations.";
234 ref_ros_response.success =
false;
235 ref_ros_response.message =
"Unable to end the calibration.";
245 ref_ros_response.success =
true;
246 ref_ros_response.message =
"Magnetometer calibration process started.";
250 ref_ros_response.success =
false;
251 ref_ros_response.message =
"Unable to start magnetometers calibration.";
257 return ref_ros_response.success;
266 ref_ros_response.success =
false;
267 ref_ros_response.message =
"Magnetometer calibration process is still ongoing, finish it before trying to save it.";
273 ref_ros_response.success =
true;
274 ref_ros_response.message =
"Magnetometer calibration has been uploaded to the device.";
278 ref_ros_response.success =
false;
279 ref_ros_response.message =
"Magnetometer calibration has not been uploaded to the device.";
284 ref_ros_response.success =
false;
285 ref_ros_response.message =
"No magnetometer calibration has been done.";
288 return ref_ros_response.success;
309 ROS_INFO(
"SBG DRIVER [Mag Calib] - Start calibration");
346 ROS_WARN(
"SBG DRIVER [Mag Calib] - Unable to set the magnetometers calibration data to the device : %s",
sbgErrorCodeToString(error_code));
351 ROS_INFO(
"SBG DRIVER [Mag Calib] - Saving data to the device");
359 ROS_ERROR(
"SBG DRIVER [Mag Calib] - The calibration was invalid, it can't be uploaded on the device.");
378 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough valid points. Maybe you are moving too fast");
382 ROS_WARN(
"SBG DRIVER [Mag Calib] - Unable to find a calibration solution. Maybe there are too much non static distortions");
386 ROS_WARN(
"SBG DRIVER [Mag Calib] - The magnetic calibration has troubles to correct the magnetometers and inertial frame alignment");
392 ROS_WARN(
"SBG DRIVER [Mag Calib] - Too much roll motion for a 2D magnetic calibration");
396 ROS_WARN(
"SBG DRIVER [Mag Calib] - Too much pitch motion for a 2D magnetic calibration");
403 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough roll motion for a 3D magnetic calibration");
407 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough pitch motion for a 3D magnetic calibration.");
412 ROS_WARN(
"SBG DRIVER [Mag Calib] - Not enough yaw motion to compute a valid magnetic calibration");
420 ostringstream mag_results_stream;
421 string output_filename;
426 mag_results_stream <<
"SBG DRIVER [Mag Calib]" << endl;
427 mag_results_stream <<
"======= Parameters =======" << endl;
428 mag_results_stream <<
"* CALIB_MODE = " <<
g_mag_calib_mode_[mag_calib_mode] << endl;
431 mag_results_stream <<
"======= Results =======" << endl;
434 mag_results_stream <<
"======= Infos =======" << endl;
436 mag_results_stream <<
"* Mean, Std, Max" << endl;
442 mag_results_stream <<
"* Matrix" << endl;
448 ofstream output_file(output_filename);
449 output_file << mag_results_stream.str();
452 ROS_INFO(
"%s", mag_results_stream.str().c_str());
453 ROS_INFO(
"SBG DRIVER [Mag Calib] - Magnetometers calibration results saved to file %s", output_filename.c_str());
488 ROS_INFO(
"SBG DRIVER [Init] - SBG device is initialized for magnetometers calibration.");
SbgEComMagCalibConfidence confidence
Helper methods and definitions used to handle version.
MessagePublisher m_message_publisher_
sbgIpAddress getIpAddress(void) const
uint8_t productCode[SBG_ECOM_INFO_PRODUCT_CODE_LENGTH]
ros::ServiceServer m_calib_save_service_
SBG_COMMON_LIB_API SbgErrorCode sbgVersionToStringEncoded(uint32_t version, char *pBuffer, uint32_t sizeOfBuffer)
bool processMagCalibration(std_srvs::Trigger::Request &ref_ros_request, std_srvs::Trigger::Response &ref_ros_response)
const std::string & getUartPortName(void) const
void displayMagCalibrationStatusResult(void) const
SbgEComMagCalibQuality quality
void periodicHandle(void)
void onLogReceived(SbgEComClass msg_class, SbgEComMsgId msg, const SbgBinaryLogData &ref_sbg_data)
static const char * sbgErrorCodeToString(SbgErrorCode errorCode)
enum _SbgEComMagCalibMode SbgEComMagCalibMode
SBG_COMMON_LIB_API SbgErrorCode sbgInterfaceSerialDestroy(SbgInterface *pHandle)
SbgErrorCode sbgEComCmdMagStartCalib(SbgEComHandle *pHandle, SbgEComMagCalibMode mode, SbgEComMagCalibBandwidth bandwidth)
bool uploadMagCalibrationToDevice(void)
const SbgEComMagCalibBandwidth & getMagnetometerCalibBandwidth(void) const
enum _SbgEComMagCalibBandwidth SbgEComMagCalibBandwidth
uint32_t getReadingRateFrequency(void) const
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
const SbgEComMagCalibMode & getMagnetometerCalibMode(void) const
#define SBG_ECOM_MAG_CALIB_Y_MOTION_ISSUE
ros::NodeHandle & m_ref_node_
bool checkConfigWithRos(void) const
std::string getVersionAsString(uint32 sbg_version_enc) const
SBG_INLINE float sbgRadToDegF(float angle)
SbgInterface m_sbg_interface_
static std::map< SbgEComMagCalibQuality, std::string > g_mag_calib_quality_
ConfigStore m_config_store_
void saveConfiguration(void)
#define SBG_ECOM_MAG_CALIB_TOO_MUCH_DISTORTIONS
SbgErrorCode sbgInterfaceUdpCreate(SbgInterface *pHandle, sbgIpAddress remoteAddr, uint32 remotePort, uint32 localPort)
uint32_t getBaudRate(void) const
ros::Time m_ros_processing_time_
SbgEComHandle m_com_handle_
void loadParameters(void)
SbgErrorCode sbgEComHandle(SbgEComHandle *pHandle)
uint32_t getInputPortAddress(void) const
uint32_t getUpdateFrequency(void) const
SBG_COMMON_LIB_API SbgErrorCode sbgInterfaceSerialCreate(SbgInterface *pHandle, const char *deviceName, uint32_t baudRate)
void readDeviceInfo(void)
void loadFromRosNodeHandle(const ros::NodeHandle &ref_node_handle)
bool startMagCalibration(void)
static std::map< SbgEComMagCalibConfidence, std::string > g_mag_calib_confidence_
SbgEComMagCalibResults m_magCalibResults
SbgErrorCode sbgEComSetReceiveLogCallback(SbgEComHandle *pHandle, SbgEComReceiveLogFunc pReceiveLogCallback, void *pUserArg)
static std::map< SbgEComMagCalibMode, std::string > g_mag_calib_mode_
#define SBG_ECOM_MAG_CALIB_NOT_ENOUGH_POINTS
uint32_t getOutputPortAddress(void) const
SbgErrorCode sbgEComCmdMagComputeCalib(SbgEComHandle *pHandle, SbgEComMagCalibResults *pCalibResults)
std::string timeToStr(ros::WallTime ros_t)
uint32_t m_rate_frequency_
bool endMagCalibration(void)
void applyConfiguration(const ConfigStore &ref_config_store)
bool isInterfaceUdp(void) const
#define SBG_ECOM_MAG_CALIB_X_MOTION_ISSUE
SbgErrorCode sbgEComCmdMagSetCalibData(SbgEComHandle *pHandle, const float offset[3], const float matrix[9])
#define SBG_UNUSED_PARAMETER(x)
bool isInterfaceSerial(void) const
static std::map< SbgEComMagCalibBandwidth, std::string > g_mag_calib_bandwidth
void initPublishers(ros::NodeHandle &ref_ros_node_handle, const ConfigStore &ref_config_store)
#define SBG_ECOM_MAG_CALIB_Z_MOTION_ISSUE
enum _SbgEComClass SbgEComClass
SbgErrorCode sbgEComCmdGetInfo(SbgEComHandle *pHandle, SbgEComDeviceInfo *pInfo)
Handle a connected SBG device.
bool saveMagCalibration(std_srvs::Trigger::Request &ref_ros_request, std_srvs::Trigger::Response &ref_ros_response)
bool m_mag_calibration_done_
#define SBG_ECOM_MAG_CALIB_ALIGNMENT_ISSUE
uint32_t getMaxOutputFrequency(void) const
void initDeviceForReceivingData(void)
void initDeviceForMagCalibration(void)
void publish(const ros::Time &ref_ros_time, SbgEComClass sbg_msg_class, SbgEComMsgId sbg_msg_id, const SbgBinaryLogData &ref_sbg_log)
bool m_mag_calibration_ongoing_
void initPublishers(void)
void exportMagCalibrationResults(void) const
SbgErrorCode sbgEComInit(SbgEComHandle *pHandle, SbgInterface *pInterface)
enum _SbgErrorCode SbgErrorCode
SbgErrorCode sbgEComClose(SbgEComHandle *pHandle)
SbgErrorCode sbgInterfaceUdpDestroy(SbgInterface *pHandle)
static SbgErrorCode onLogReceivedCallback(SbgEComHandle *p_handle, SbgEComClass msg_class, SbgEComMsgId msg, const SbgBinaryLogData *p_log_data, void *p_user_arg)
ros::ServiceServer m_calib_service_