36 std::cout <<
"Opening serial port: " <<
device_.c_str() <<
" \n";
38 std::cout <<
"Couldn't open serial port... \n";
41 opts = opts & (O_NONBLOCK);
51 std::cout <<
"Couldn't get the current state.\n";
53 }
while (diag == -1 && errno == EINTR);
57 std::cout <<
"Couldnt set the desired baud rate \n";
68 defaults_.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
69 defaults_.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG );
77 std::cout <<
"Failed to set attributes to the serial port.\n";
84 unsigned char buff[3] = {0};
91 perror(
"Stop stream");
96 perror(
"Stop stream");
115 perror(
"Start stream");
120 perror(
"Start stream");
123 std::cout <<
"Started reading data from sensor...\n";
130 unsigned char buff[68] = {0};
135 perror(
"Partial Package Received.");
140 int16_t computed_checksum = 0;
142 int16_t int16buff[34] = {0};
146 for (
int i = 0; i < 66; i += 2)
149 computed_checksum += int16buff[i / 2];
152 computed_checksum = ~computed_checksum + 0x0001;
156 if (checksum == computed_checksum)
160 std::cout <<
"Package is corrupt...\n";
161 std::cout <<
"Checksum: " << checksum <<
"\n";
162 std::cout <<
"Computed Checksum: " << computed_checksum <<
"\n";
168 std::cout <<
"Dropped package\n";
184 }
while (diag == -1);
186 std::cout <<
"Serial Port got closed.";
193 unsigned char buff[2] = {data[1], data[0]};
194 return *
reinterpret_cast<int16_t *
>(buff);
199 int16_t buff[2] = {data[1], data[0]};
200 return *
reinterpret_cast<float *
>(buff);
void closePort()
Close the device.
ros::Publisher imu_publisher_
void publish(const boost::shared_ptr< M > &message) const
int openPort()
Open device.
void doParsing(int16_t *int16buff)
Gets the raw data and converts them to standard ROS IMU message.
int16_t big_endian_to_short(unsigned char *data)
change big endian 2 byte into short
float short_to_float(int16_t *data)
change big endian short into float
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Publisher dmu_raw_publisher_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
sensor_msgs::Imu imu_raw_
bool getParam(const std::string &key, std::string &s) const
DMU11(ros::NodeHandle &nh)
Constructor.
dmu_ros::DMURaw raw_package_
void update()
Read the data received on serial port.