3 #include <std_msgs/String.h> 4 #include <sensor_msgs/Imu.h> 5 #include <sensor_msgs/MagneticField.h> 17 int main(
int argc,
char **argv)
23 std::string imu_topic;
24 std::string mag_topic;
25 std::string imu_frame;
34 nh_private.
param<std::string>(
"port", port,
"ttyS0");
35 port =
"/dev/" + port;
36 nh_private.
param<
int>(
"baudrate", baudrate, 9600);
37 nh_private.
param<
int>(
"publish_rate", pub_rate, 20);
38 nh_private.
param<
bool>(
"publish_mag", pub_mag,
true);
39 nh_private.
param<std::string>(
"imu_topic", imu_topic,
"imu_data");
40 nh_private.
param<std::string>(
"mag_topic", mag_topic,
"mag_data");
41 nh_private.
param<std::string>(
"imu_frame", imu_frame,
"imu_link");
44 ROS_INFO_STREAM(
"baudrate : " << baudrate);
45 ROS_INFO_STREAM(
"publish_rate : " << pub_rate);
46 ROS_INFO_STREAM(
"publish_mag : " << (pub_mag ?
"true" :
"false"));
47 ROS_INFO_STREAM(
"imu_topic : " << imu_topic);
48 ROS_INFO_STREAM(
"mag_topic : " << mag_topic);
49 ROS_INFO_STREAM(
"imu_frame : " << imu_frame);
73 ROS_INFO_STREAM(
"Serial Port initialized");
99 unsigned char read_buf[count];
100 num = ser.
read(read_buf, count);
107 imu.FetchData((
char *)read_buf, num);
109 sensor_msgs::Imu imu_data;
112 imu_data.header.frame_id = imu_frame;
114 imu_data.linear_acceleration.x = imu.acc.x;
115 imu_data.linear_acceleration.y = imu.acc.y;
116 imu_data.linear_acceleration.z = imu.acc.z;
117 imu_data.linear_acceleration_covariance = {1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6};
119 imu_data.angular_velocity.x = imu.gyro.x;
120 imu_data.angular_velocity.y = imu.gyro.y;
121 imu_data.angular_velocity.z = imu.gyro.z;
122 imu_data.linear_acceleration_covariance = {1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6};
124 imu_data.orientation.x = imu.quat.x;
125 imu_data.orientation.y = imu.quat.y;
126 imu_data.orientation.z = imu.quat.z;
127 imu_data.orientation.w = imu.quat.w;
128 imu_data.orientation_covariance = {1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6};
134 sensor_msgs::MagneticField mag_data;
136 mag_data.header.stamp = imu_data.header.stamp;
137 mag_data.header.frame_id = imu_data.header.frame_id;
139 mag_data.magnetic_field.x = imu.mag.x;
140 mag_data.magnetic_field.y = imu.mag.y;
141 mag_data.magnetic_field.z = imu.mag.z;
142 mag_data.magnetic_field_covariance = {1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6};
144 mag_pub.publish(mag_data);
void publish(const boost::shared_ptr< M > &message) const
#define ROS_INFO_ONCE(...)
void setTimeout(Timeout &timeout)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setBaudrate(uint32_t baudrate)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int main(int argc, char **argv)
static Timeout simpleTimeout(uint32_t timeout)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void setPort(const std::string &port)
#define ROS_INFO_STREAM(args)
size_t read(uint8_t *buffer, size_t size)
#define ROS_ERROR_STREAM(args)