@@ -40,15 +40,6 @@ void RosVector3FromVnVector3(geometry_msgs::Vector3& ros_vec3,
4040void RosQuaternionFromVnVector4 (geometry_msgs::Quaternion& ros_quat,
4141 const vn::math::vec4f& vn_vec4);
4242
43- /* *
44- * @brief FillImuMessage
45- * @param imu_msg
46- * @param p
47- * @param binary_output
48- */
49- void FillImuMessage (sensor_msgs::Imu& imu_msg, vn::protocol::uart::Packet& p,
50- bool binary_output);
51-
5243/* *
5344 * @brief asciiOrBinaryAsyncMessageReceived
5445 * @param userData
@@ -112,7 +103,6 @@ ImuVn100::ImuVn100(const ros::NodeHandle& pnh)
112103 baudrate_(921600 ),
113104 frame_id_(std::string(" imu" )) {
114105 Initialize ();
115- // TODO pointer hack
116106}
117107
118108ImuVn100::~ImuVn100 () { Disconnect (); }
@@ -145,6 +135,12 @@ void ImuVn100::LoadParameters() {
145135 pnh_.param (" sync_pulse_width_us" , sync_info_.pulse_width_us , 1000 );
146136
147137 pnh_.param (" binary_output" , binary_output_, true );
138+
139+ if (!binary_output_ && (enable_pres_ | enable_temp_)) {
140+ ROS_ERROR (" VN: Ascii mode cannot support mag, pressure and temp." );
141+ enable_pres_ = enable_temp_ = false ;
142+ }
143+
148144 int vn_serial_output_tmp = 4 ; // init on invalid number
149145 pnh_.param (" vn_serial_output" , vn_serial_output_tmp, 1 );
150146 switch (vn_serial_output_tmp) {
@@ -277,7 +273,7 @@ void ImuVn100::Stream(bool async) {
277273 imu_.writeBinaryOutput1 (bor, true );
278274 } else {
279275 // Set the ASCII output data type and data rate
280- imu_.writeAsyncDataOutputType (VNIMU , true );
276+ imu_.writeAsyncDataOutputType (VNQMR , true );
281277 }
282278
283279 // add a callback function for new data event
@@ -310,13 +306,41 @@ void ImuVn100::PublishData(vn::protocol::uart::Packet& p) {
310306 imu_msg.header .stamp = ros::Time::now ();
311307 imu_msg.header .frame_id = frame_id_;
312308
313- FillImuMessage (imu_msg, p, binary_output_);
309+ vn::math::vec4f quaternion;
310+ vn::math::vec3f linear_accel;
311+ vn::math::vec3f angular_rate;
312+ vn::math::vec3f magnetometer;
313+ if (binary_output_) {
314+ // Note: With this library, we are responsible for extracting the data
315+ // in the appropriate order! Need to refer to manual and to how we
316+ // configured the common output group
317+ quaternion = p.extractVec4f (); // COMMONGROUP_QUATERNION
318+ // NOTE: The IMU angular velocity and linear acceleration outputs are
319+ // swapped. And also why are they different?
320+ linear_accel = p.extractVec3f (); // COMMONGROUP_IMU
321+ angular_rate = p.extractVec3f (); // COMMONGROUP_IMU
322+
323+ } else {
324+ // ascii format
325+ if (p.type () != vn::protocol::uart::Packet::TYPE_ASCII) return ;
326+
327+ if (p.determineAsciiAsyncType () != vn::protocol::uart::VNQMR) return ;
328+
329+ // TODO check if angular rate and linear acceleration are also swapped
330+ // in ascii mode
331+ p.parseVNQMR (&quaternion, &magnetometer, &linear_accel, &angular_rate);
332+ }
333+
334+ RosQuaternionFromVnVector4 (imu_msg.orientation , quaternion);
335+ RosVector3FromVnVector3 (imu_msg.angular_velocity , angular_rate);
336+ RosVector3FromVnVector3 (imu_msg.linear_acceleration , linear_accel);
337+
314338 pd_imu_.Publish (imu_msg);
315339
316340 if (enable_mag_) {
317341 sensor_msgs::MagneticField mag_msg;
318342 mag_msg.header = imu_msg.header ;
319- vn::math::vec3f magnetometer = p.extractVec3f (); // COMMONGROUP_MAGPRES
343+ magnetometer = p.extractVec3f (); // COMMONGROUP_MAGPRES
320344 RosVector3FromVnVector3 (mag_msg.magnetic_field , magnetometer);
321345 pd_mag_.Publish (mag_msg);
322346 }
@@ -358,26 +382,6 @@ void RosQuaternionFromVnVector4(geometry_msgs::Quaternion& ros_quat,
358382 ros_quat.w = vn_vec4[3 ];
359383}
360384
361- void FillImuMessage (sensor_msgs::Imu& imu_msg, vn::protocol::uart::Packet& p,
362- bool binary_output) {
363- if (binary_output) {
364- // Note: With this library, we are responsible for extracting the data
365- // in the appropriate order! Need to refer to manual and to how we
366- // configured the common output group
367- vn::math::vec4f quaternion = p.extractVec4f (); // COMMONGROUP_QUATERNION
368- // NOTE: The IMU angular velocity and linear acceleration outputs are
369- // swapped. And also why are they different?
370- vn::math::vec3f linear_accel = p.extractVec3f (); // COMMONGROUP_IMU
371- vn::math::vec3f angular_rate = p.extractVec3f (); // COMMONGROUP_IMU
372-
373- RosQuaternionFromVnVector4 (imu_msg.orientation , quaternion);
374- RosVector3FromVnVector3 (imu_msg.angular_velocity , angular_rate);
375- RosVector3FromVnVector3 (imu_msg.linear_acceleration , linear_accel);
376- } else {
377- // TODO
378- }
379- }
380-
381385void asciiOrBinaryAsyncMessageReceived (void * userData,
382386 vn::protocol::uart::Packet& p,
383387 size_t index) {
0 commit comments