1 #include <boost/make_shared.hpp> 9 nh_private_(nh_private),
13 target_publish_freq_(0.0)
34 bool has_compass_params =
56 "imu/is_calibrated", 5);
88 for (
int i = 0; i < 3; ++i)
89 for (
int j = 0; j < 3; ++j)
95 imu_msg_.angular_velocity_covariance[idx] = ang_vel_var;
96 imu_msg_.linear_acceleration_covariance[idx] = lin_acc_var;
100 imu_msg_.angular_velocity_covariance[idx] = 0.0;
101 imu_msg_.linear_acceleration_covariance[idx] = 0.0;
113 for (
int i = 0; i < 3; ++i)
114 for (
int j = 0; j < 3; ++j)
120 mag_msg_.magnetic_field_covariance[idx] = mag_field_var;
124 mag_msg_.magnetic_field_covariance[idx] = 0.0;
134 if (has_compass_params)
142 CPhidget_getErrorDescription(result, &err);
143 ROS_ERROR(
"Problem while trying to set compass correction params: '%s'.", err);
148 ROS_INFO(
"No compass correction params found.");
158 ROS_INFO(
"Waiting for IMU to be attached...");
166 CPhidget_getErrorDescription(result, &err);
167 ROS_FATAL(
"Problem waiting for IMU attachment: %s Make sure the USB cable is connected and you have executed the phidgets_api/share/setup-udev.sh script.", err);
180 std_srvs::Empty::Response &res)
195 std_msgs::Bool is_calibrated_msg;
196 is_calibrated_msg.data =
true;
204 data[i]->timestamp.microseconds * 1e-6);
211 ROS_WARN(
"IMU time lags behind by %f seconds, resetting IMU time offset!", timediff);
229 boost::make_shared<ImuMsg>(
imu_msg_);
231 imu_msg->header.stamp = time_now;
234 imu_msg->linear_acceleration.x = - data[i]->acceleration[0] *
G;
235 imu_msg->linear_acceleration.y = - data[i]->acceleration[1] *
G;
236 imu_msg->linear_acceleration.z = - data[i]->acceleration[2] *
G;
239 imu_msg->angular_velocity.x = data[i]->angularRate[0] * (M_PI / 180.0);
240 imu_msg->angular_velocity.y = data[i]->angularRate[1] * (M_PI / 180.0);
241 imu_msg->angular_velocity.z = data[i]->angularRate[2] * (M_PI / 180.0);
249 boost::make_shared<MagMsg>(
mag_msg_);
251 mag_msg->header.stamp = time_now;
253 if (data[i]->magneticField[0] != PUNK_DBL)
256 mag_msg->magnetic_field.x = data[i]->magneticField[0] * 1e-4;
257 mag_msg->magnetic_field.y = data[i]->magneticField[1] * 1e-4;
258 mag_msg->magnetic_field.z = data[i]->magneticField[2] * 1e-4;
262 double nan = std::numeric_limits<double>::quiet_NaN();
264 mag_msg->magnetic_field.x = nan;
265 mag_msg->magnetic_field.y = nan;
266 mag_msg->magnetic_field.z = nan;
279 for(
int i = 0; i < count; i++)
313 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"The Phidget is connected.");
320 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"The Phidget is not connected. Check the USB.");
325 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"The Phidget reports error.");
ros::ServiceServer cal_srv_
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)
int open(int serial_number)
double target_publish_freq_
ros::Publisher imu_publisher_
double linear_acceleration_stdev_
int waitForAttachment(int timeout)
static std::string getErrorDescription(int errorCode)
boost::shared_ptr< diagnostic_updater::TopicDiagnostic > imu_publisher_diag_ptr_
virtual void errorHandler(int error)
#define ROS_WARN_THROTTLE(period,...)
sensor_msgs::MagneticField MagMsg
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void processImuData(CPhidgetSpatial_SpatialEventDataHandle *data, int i)
virtual void attachHandler()
std::string getDeviceType()
void errorHandler(int error)
bool calibrateService(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Time last_published_time_
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,...)
CPhidgetSpatialHandle imu_handle_
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 dataHandler(CPhidgetSpatial_SpatialEventDataHandle *data, int count)
std::string getDeviceName()