8 nh_private_(nh_private),
11 target_publish_freq_(0.0),
53 bool has_compass_params =
83 std::make_shared<diagnostic_updater::TopicDiagnostic>(
86 &target_publish_freq_, &target_publish_freq_, 0.1, 5),
106 for (
int i = 0; i < 3; ++i)
108 for (
int j = 0; j < 3; ++j)
114 imu_msg_.angular_velocity_covariance[idx] = ang_vel_var;
115 imu_msg_.linear_acceleration_covariance[idx] = lin_acc_var;
118 imu_msg_.angular_velocity_covariance[idx] = 0.0;
119 imu_msg_.linear_acceleration_covariance[idx] = 0.0;
132 for (
int i = 0; i < 3; ++i)
134 for (
int j = 0; j < 3; ++j)
140 mag_msg_.magnetic_field_covariance[idx] = mag_field_var;
143 mag_msg_.magnetic_field_covariance[idx] = 0.0;
156 if (has_compass_params)
166 "Problem while trying to set compass correction params: '%s'.",
171 ROS_INFO(
"No compass correction params found.");
179 ROS_INFO(
"Waiting for IMU to be attached...");
189 "Problem waiting for IMU attachment: %s Make sure the USB cable is " 190 "connected and you have executed the " 191 "phidgets_api/share/setup-udev.sh script.",
204 std_srvs::Empty::Response &res)
215 "Calibrating IMU, this takes around 2 seconds to finish. " 216 "Make sure that the device is not moved during this time.");
226 std_msgs::Bool is_calibrated_msg;
227 is_calibrated_msg.data =
true;
232 const double angularRate[3],
233 const double magneticField[3],
double timestamp)
246 "IMU time lags behind by %f seconds, resetting IMU time " 267 std::shared_ptr<ImuMsg> imu_msg = std::make_shared<ImuMsg>(
imu_msg_);
269 imu_msg->header.stamp = time_now;
272 imu_msg->linear_acceleration.x = -acceleration[0] *
G;
273 imu_msg->linear_acceleration.y = -acceleration[1] *
G;
274 imu_msg->linear_acceleration.z = -acceleration[2] *
G;
277 imu_msg->angular_velocity.x = angularRate[0] * (M_PI / 180.0);
278 imu_msg->angular_velocity.y = angularRate[1] * (M_PI / 180.0);
279 imu_msg->angular_velocity.z = angularRate[2] * (M_PI / 180.0);
286 std::shared_ptr<MagMsg> mag_msg = std::make_shared<MagMsg>(
mag_msg_);
288 mag_msg->header.stamp = time_now;
290 if (magneticField[0] != PUNK_DBL)
293 mag_msg->magnetic_field.x = magneticField[0] * 1e-4;
294 mag_msg->magnetic_field.y = magneticField[1] * 1e-4;
295 mag_msg->magnetic_field.z = magneticField[2] * 1e-4;
298 double nan = std::numeric_limits<double>::quiet_NaN();
300 mag_msg->magnetic_field.x = nan;
301 mag_msg->magnetic_field.y = nan;
302 mag_msg->magnetic_field.z = nan;
348 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
349 "The Phidget is connected.");
355 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
356 "The Phidget is not connected. Check the USB.");
361 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
362 "The Phidget reports error.");
int openAndWaitForAttachment(int serial_number, int timeout)
ros::ServiceServer cal_srv_
#define ROS_WARN_THROTTLE(rate,...)
void publish(const boost::shared_ptr< M > &message) const
void setDataRate(int rate)
void summary(unsigned char lvl, const std::string s)
void setHardwareID(const std::string &hwid)
const float MAX_TIMEDIFF_SECONDS
ImuRosI(ros::NodeHandle nh, ros::NodeHandle nh_private)
void add(const std::string &name, TaskFunction f)
int getDeviceSerialNumber()
virtual void detachHandler()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
double target_publish_freq_
ros::Publisher imu_publisher_
double linear_acceleration_stdev_
static std::string getErrorDescription(int errorCode)
int setCompassCorrectionParameters(double cc_mag_field, double cc_offset0, double cc_offset1, double cc_offset2, double cc_gain0, double cc_gain1, double cc_gain2, double cc_T0, double cc_T1, double cc_T2, double cc_T3, double cc_T4, double cc_T5)
virtual void errorHandler(int error)
sensor_msgs::MagneticField MagMsg
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void attachHandler() override
virtual void attachHandler()
std::string getDeviceType()
bool calibrateService(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
void errorHandler(int error) override
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Time last_published_time_
std::shared_ptr< diagnostic_updater::TopicDiagnostic > imu_publisher_diag_ptr_
double magnetic_field_stdev_
double angular_velocity_stdev_
void phidgetsDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
Main diagnostic method that takes care of collecting diagnostic data.
ros::NodeHandle nh_private_
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
ros::Publisher cal_publisher_
void add(const std::string &key, const T &val)
void setHardwareIDf(const char *format,...)
ros::Publisher mag_publisher_
diagnostic_updater::Updater diag_updater_
updater object of class Update. Used to add diagnostic tasks, set ID etc. refer package API...
void detachHandler() override
void dataHandler(const double acceleration[3], const double angularRate[3], const double magneticField[3], double timestamp) override
std::string getDeviceName()