watson_ins_node.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of https://github.com/AutonomousVehicleLaboratory/watson_ins.git
3  * Copyright 2019 AVL
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Please contact AVL <avl@eng.ucsd.edu> for any inquiries.
18  */
19 #include "watson_ins_driver.h"
20 #include "sensor_msgs/NavSatFix.h"
21 #include <ros/console.h>
22 #include <ros/ros.h>
23 #include <stdio.h>
24 #include <string>
25 
26 #define LOOP_RATE 5
27 #define QUEUE_LENGTH 20
28 
29 int main(int argc, char* argv[])
30 {
31  std::string path;
32  int baud;
33  int timeout_ms;
34 
35  ros::init(argc, argv, "watson_ins");
36 
38 
39  // Host Params
40  n.param("SerialPath", path, std::string("/dev/ttyUSB0"));
41  n.param("SerialBaud", baud, 9600);
42  n.param("SerialTimeout", timeout_ms, 1000);
43 
44  WatsonINSDriver INSDrv(path, baud, timeout_ms);
45 
46  ros::Publisher imu_pub = n.advertise<sensor_msgs::Imu>("/imu_raw", QUEUE_LENGTH);
47  ros::Publisher nav_pub = n.advertise<sensor_msgs::NavSatFix>("/fix", QUEUE_LENGTH);
48  ros::Rate loop_rate(LOOP_RATE);
49 
50  while (ros::ok()) {
51  try {
52  bool validIMU, validGPS;
53  sensor_msgs::Imu imu_msg;
54  sensor_msgs::NavSatFix gps_msg;
55  INSDrv.read(imu_msg, gps_msg, validIMU, validGPS);
56  if (validIMU) {
57  ROS_INFO("Publishing valid IMU message");
58  imu_pub.publish(imu_msg);
59  }
60  if (validGPS) {
61  ROS_INFO("Publishing valid GPS message");
62  nav_pub.publish(gps_msg);
63  }
64  } catch (const std::exception& e) {
65  ROS_ERROR("Reading from INS driver failed");
66  }
67 
68  // I don't think this is needed?
69  ros::spinOnce();
70  loop_rate.sleep();
71  }
72 
73  return 0;
74 }
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define QUEUE_LENGTH
#define LOOP_RATE
void read(sensor_msgs::Imu &imuMsg, sensor_msgs::NavSatFix &fixMsg, bool &validImu, bool &validFix)
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char *argv[])
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)


watson_ins
Author(s): David Paz , Nathan Chan
autogenerated on Sat Jan 11 2020 03:23:08