mti_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2010, ISR University of Coimbra.
6 * Copyright (c) 2011-2012, INRIA, CNRS, all rights reserved
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the ISR University of Coimbra nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Author: Gonçalo Cabrita on 08/11/2010
37 *
38 * Author: Nicolas Vignard on 2 MAY 2012
39 * Notes: Add the ability to control the Mti-G
40 *********************************************************************/
41 #include "MTi/MTi.h"
42 #include <ros/ros.h>
43 
44 
52 int main(int argc, char** argv)
53 {
54  ros::init(argc, argv, "mti_node");
55  ros::NodeHandle pn("~");
56 
57  // Params
58  std::string portname;
59  int baudrate;
60  std::string frame_id;
61  pn.param<std::string>("port", portname, "/dev/ttyUSB0");
62  pn.param("baudrate", baudrate, 115200);
63  pn.param<std::string>("frame_id", frame_id, Xsens::IMU_FRAME_ID);
64 
65  Xsens::MTi::outputMode outputMode;
66  pn.param<bool>("temperature", outputMode.temperatureData,false);
67  pn.param<bool>("calibrated", outputMode.calibratedData,true);
68  pn.param<bool>("orientation", outputMode.orientationData,true);
69  pn.param<bool>("auxiliary", outputMode.auxiliaryData,false);
70  pn.param<bool>("position", outputMode.positionData,false);
71  pn.param<bool>("velocity", outputMode.velocityData,false);
72  pn.param<bool>("status", outputMode.statusData,false);
73  pn.param<bool>("rawGPS", outputMode.rawGPSData,false);
74  pn.param<bool>("rawInertial", outputMode.rawInertialData,false);
75 
76  Xsens::MTi::outputSettings outputSettings;
77  pn.param<bool>("timeStamp", outputSettings.timeStamp,false);
78  int orientationMode;
79  pn.param<int>("orientationMode", orientationMode,Xsens::Quaternion);
80  outputSettings.orientationMode = (Xsens::MTOrientationMode)orientationMode;
81  pn.param<bool>("enableAcceleration", outputSettings.enableAcceleration,false);
82  pn.param<bool>("enableRateOfTurn", outputSettings.enableRateOfTurn,false);
83  pn.param<bool>("enableMagnetometer", outputSettings.enableMagnetometer,false);
84  pn.param<bool>("velocityModeNED", outputSettings.velocityModeNED,false);
85 
86  int scenarioAsInt;
87  pn.param<int>("scenario",scenarioAsInt,Xsens::Automotive);
88  Xsens::Scenario scenario = (Xsens::Scenario)scenarioAsInt;
89  double GPSLeverArm_X, GPSLeverArm_Y, GPSLeverArm_Z;
90  pn.param<double>("GPSLeverArm_X",GPSLeverArm_X,0.0);
91  pn.param<double>("GPSLeverArm_Y",GPSLeverArm_Y,0.0);//0.25
92  pn.param<double>("GPSLeverArm_Z",GPSLeverArm_Z,0.0);//0.70
93  Xsens::MTi::Position GPS_lever_arm;
94  GPS_lever_arm.x = GPSLeverArm_X;
95  GPS_lever_arm.y = GPSLeverArm_Y;
96  GPS_lever_arm.z = GPSLeverArm_Z;
97 
98  Xsens::MTi * mti = new Xsens::MTi();
99 
100  if(!mti->openPort((char*)portname.c_str(), baudrate))
101  {
102  ROS_FATAL("MTi -- Unable to connect to the MTi.");
103  ROS_BREAK();
104  }
105  ROS_INFO("MTi -- Successfully connected to the MTi!");
106 
107  std::string prefix = "";
108  pn.getParamCached("tf_prefix",prefix);
109  ROS_INFO("tf_prefix: %s",prefix.c_str());
110  if(!mti->setSettings(outputMode, outputSettings, scenario, prefix, frame_id, GPS_lever_arm, 1000))
111  {
112  ROS_FATAL("MTi -- Unable to set the output mode and settings.");
113  ROS_BREAK();
114  }
115  ROS_INFO("MTi -- Setup complete! Initiating data streaming...");
116 
117  ros::Publisher mti_pub = pn.advertise<sensor_msgs::Imu>("imu/data", 10);
118  ros::Publisher navsat_pub = pn.advertise<sensor_msgs::NavSatFix>("fix", 10);
119  ros::Publisher odomPub = pn.advertise<nav_msgs::Odometry>("odom",10);
120 
121  tf::TransformBroadcaster odom_broadcaster;
122  tf::TransformListener listener;
123 
124  ros::Rate r(20);
125  while(ros::ok())
126  {
127  ros::Time now = ros::Time::now();
128  sensor_msgs::Imu imu_msg = mti->fillImuMessage(now);
129  mti_pub.publish(imu_msg);
130 
131  sensor_msgs::NavSatFix nav_fix_msg = mti->fillNavFixMessage(now);
132  navsat_pub.publish(nav_fix_msg);
133 
134  nav_msgs::Odometry odom_msg = mti->fillOdometryMessage(listener, odom_broadcaster, now);
135  odomPub.publish(odom_msg);
136 
137  ros::spinOnce();
138  r.sleep();
139  }
140 
141  return(0);
142 }
143 
144 // EOF
145 
Definition: MTi.h:86
nav_msgs::Odometry fillOdometryMessage(const tf::TransformListener &listener, tf::TransformBroadcaster &odom_broadcaster, const ros::Time &now)
Fill ROS odometry message with the values come from the xsens.
Definition: MTi.cpp:948
MTOrientationMode orientationMode
Definition: MTi.h:109
enum Xsens::_MTOrientationMode MTOrientationMode
bool setSettings(outputMode mode, outputSettings settings, Scenario scenario, const std::string &rosNamespace, const std::string &frameID, const Position &GPSLeverArm, int timeout)
Set the configuration of the xsens:
Definition: MTi.cpp:186
enum Xsens::_Scenario Scenario
bool openPort(char *name, int baudrate)
Open serial port to communicate with the Xsens.
Definition: MTi.cpp:375
int main(int argc, char **argv)
Definition: mti_node.cpp:52
sensor_msgs::Imu fillImuMessage(const ros::Time &now)
Fill ROS IMU message with the values come from the xsens.
Definition: MTi.cpp:1059
sensor_msgs::NavSatFix fillNavFixMessage(const ros::Time &now)
Fill ROS NavSatFix message with the values come from the xsens.
Definition: MTi.cpp:1114
static const std::string IMU_FRAME_ID
Definition: MTi.h:65


lse_xsens_mti
Author(s): Gonçalo Cabrita, Nicolas Vignard
autogenerated on Mon Mar 2 2015 01:32:14