8 #include <sensor_msgs/Imu.h> 24 ROS_INFO(
"Initializing HCL layer...");
26 ROS_ERROR(
"Error: could not initialize the Seiko Epson HCL layer. Exiting...");
30 ROS_INFO(
"Initializing GPIO interface...");
32 ROS_ERROR(
"Error: could not initialize the GPIO layer. Exiting...");
36 ROS_INFO(
"Initializing UART interface...");
39 ROS_ERROR(
"Error: could not initialize UART interface. Exiting...");
43 ROS_INFO(
"Checking sensor NOT_READY status...");
45 ROS_ERROR(
"Error: failed to power on Sensor. Exiting...");
53 ROS_ERROR(
"Error: could not initialize Epson Sensor. Exiting...");
58 ROS_INFO(
"...Epson IMU initialized.");
87 MAX_COUNT = 1397861550;
88 ALMOST_ROLLOVER = 1300000000;
89 ONE_SEC_NSEC = 1000000000;
90 HALF_SEC_NSEC = 500000000;
97 time_nsec_current = 0;
98 count_corrected_old = 0;
100 flag_imu_lead =
false;
108 count_diff = count - count_old;
109 if(count > ALMOST_ROLLOVER){
112 else if(count_diff<0){
114 count_diff = count + (MAX_COUNT - count_old);
119 std::cout.precision(20);
124 count_corrected = (count_corrected + count_diff) % ONE_SEC_NSEC;
125 if(time_current != time_old && count_corrected > HALF_SEC_NSEC){
126 time_current = time_current - 1;
128 else if((count_corrected-count_corrected_old) < 0 && time_nsec_current > HALF_SEC_NSEC){
129 time_current = time_current + 1;
132 else if(flag_imu_lead && time_nsec_current > HALF_SEC_NSEC){
133 time_current = time_current + 1;
140 time.
nsec = count_corrected;
141 time.
sec = time_current;
142 time_old=time_current;
144 count_corrected_old = count_corrected;
152 int main(
int argc,
char** argv){
153 ros::init(argc, argv,
"epson_imu_driver_node");
160 int time_correction = 0;
217 np.
param(
"time_correction", time_correction, 1);
230 sensor_msgs::Imu imu_msg;
231 for(
int i = 0; i < 9; i++){
232 imu_msg.orientation_covariance[i] = 0;
233 imu_msg.angular_velocity_covariance[i] = 0;
234 imu_msg.linear_acceleration_covariance[i] = 0;
236 imu_msg.orientation_covariance[0] = -1;
242 imu_msg.header.frame_id =
"epson";
246 imu_msg.header.stamp = tc.get_stamp(epson_data.
count);
247 imu_msg.angular_velocity.x = epson_data.
gyro_x;
248 imu_msg.angular_velocity.y = epson_data.
gyro_y;
249 imu_msg.angular_velocity.z = epson_data.
gyro_z;
250 imu_msg.linear_acceleration.x = epson_data.
accel_x;
251 imu_msg.linear_acceleration.y = epson_data.
accel_y;
252 imu_msg.linear_acceleration.z = epson_data.
accel_z;
int32_t time_nsec_current
void publish(const boost::shared_ptr< M > &message) const
int sensorDataReadBurstNOptions(struct EpsonOptions, struct EpsonData *)
bool init(struct EpsonOptions options)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int sensorInitOptions(struct EpsonOptions)
int uartInit(const char *comPortPath, int baudRate)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int uartRelease(ComPortHandle comPort)
int main(int argc, char **argv)
int32_t count_corrected_old