dgps_ros_node.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <sensor_msgs/NavSatFix.h>
3 #include <sensor_msgs/NavSatStatus.h>
4 #include <thread>
5 #include <string>
6 #include "ntrip.h"
7 
8 
9 #define STATUS_NO_FIX -1
10 #define STATUS_FIX 0
11 #define STATUS_GBAS_FIX 2
12 #define SERVICE_GPS 1
13 #define COVARIANCE_TYPE_DIAGONAL_KNOWN 2
14 
15 double NMEA2float(std::string s)
16 {
17  double d = std::stod(s)/100.0;
18  d = floor(d) + (d - floor(d))*10/6;
19  return d;
20 }
21 
22 boost::array<double,9> covariance={1,0,0,
23  0,1,0,
24  0,0,1 };
25 
26 void fillSatMessage(sensor_msgs::NavSatFix& sat, Location& loc )
27 {
28  sat.header.frame_id="gps";
29  sat.header.stamp = ros::Time::now();
30 
31  if( loc.fix == "0" )
32  sat.status.status = STATUS_NO_FIX;
33  else if( loc.fix == "1" )
34  sat.status.status = STATUS_FIX;
35  else
36  sat.status.status = STATUS_GBAS_FIX;
37  sat.status.service = SERVICE_GPS;
38 
39  sat.latitude = NMEA2float(loc.lat);
40  sat.longitude = NMEA2float(loc.lon);
41  sat.altitude = std::stod(loc.alt);
42 
43  std::copy(covariance.begin(), covariance.end(),sat.position_covariance.begin());
44  sat.position_covariance[0] = std::stod(loc.hdop);
45  sat.position_covariance[4] = std::stod(loc.hdop);
46  sat.position_covariance[8] = 10;
47 
48 
49  sat.position_covariance_type = COVARIANCE_TYPE_DIAGONAL_KNOWN;
50 
51 }
52 
53 
54 int main(int argc, char **argv)
55 {
56  ros::init(argc, argv, "dgps_node");
57  ros::NodeHandle nh("~");
58 
59 
60  std::string serverName,userName,password,serverPort,serialPort;
61  nh.param<std::string>("server",serverName, "rtk.ntrip.qxwz.com");
62  nh.param<std::string>("port",serverPort, "8002");
63  nh.param<std::string>("username",userName, "user");
64  nh.param<std::string>("password",password, "password");
65  nh.param<std::string>("serialPort",serialPort, "");
66 
67 
68  struct Args args;
69  args.server = serverName.c_str();
70  args.port = "8002";
71  args.user = userName.c_str();
72  args.password = password.c_str();
73  args.nmea = "$GNGGA,034458.00,2810.79928,N,11256.54467,E,2,12,0.64,36.0,M,-12.7,M,1.0,0773*7D";
74  args.data = "RTCM32_GGB";
75  args.bitrate = 0;
76  args.proxyhost = 0;
77  args.proxyport = "2101";
78  args.mode = NTRIP1;
79  args.initudp = 0;
80  args.udpport = 0;
82  args.parity = SPAPARITY_NONE;
83  args.stopbits = SPASTOPBITS_1;
84  args.databits = SPADATABITS_8;
85  args.baud = SPABAUD_115200;
86  if( serialPort.empty())
87  args.serdevice = 0;//"/dev/ttyUSB0";
88  else
89  args.serdevice = serialPort.c_str();
90  args.serlogfile = 0;
91  args.stop = false;
92 
93 
94  ROS_INFO("Username= %s",args.user);
95  ROS_INFO("password= %s",args.password);
96 
97  const std::string topic = "dgps";
98  ros::Publisher pub = nh.advertise<sensor_msgs::NavSatFix>(topic,10);
99 
100 
101  std::thread ntrip_thread(ntrip_client,&args);
102  ros::Rate loop_rate(10);
103  while (ros::ok())
104  {
105  Location loc = getGNGGA();
106  if( loc.lat.empty() )
107  {
108  }
109  else
110  {
111  // cout<<s;
112  sensor_msgs::NavSatFix sat;
113  fillSatMessage(sat,loc);
114  pub.publish(sat);
115  ROS_INFO("Talker_____:GPS:x = %s",loc.nmea.c_str());
116  }
117  ros::spinOnce();
118  loop_rate.sleep();
119  }
120  args.stop = true;
121  ROS_INFO("Waiting to Quit");
122  ntrip_thread.join();
123 
124 }
125 
d
#define STATUS_NO_FIX
void ntrip_client(Args *const)
double NMEA2float(std::string s)
int udpport
Definition: ntrip.h:22
void publish(const boost::shared_ptr< M > &message) const
void fillSatMessage(sensor_msgs::NavSatFix &sat, Location &loc)
std::string hdop
Definition: ntrip.h:42
const char * proxyport
Definition: ntrip.h:15
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const char * data
Definition: ntrip.h:18
int mode
Definition: ntrip.h:20
boost::array< double, 9 > covariance
std::string lat
Definition: ntrip.h:39
std::string lon
Definition: ntrip.h:40
bool stop
Definition: ntrip.h:31
enum SerialProtocol protocol
Definition: ntrip.h:28
std::string nmea
Definition: ntrip.h:38
const char * serlogfile
Definition: ntrip.h:30
Definition: ntrip.h:9
#define SERVICE_GPS
Definition: ntrip.h:7
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
enum SerialDatabits databits
Definition: ntrip.h:25
ROSCPP_DECL bool ok()
#define COVARIANCE_TYPE_DIAGONAL_KNOWN
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
enum SerialBaud baud
Definition: ntrip.h:24
int bitrate
Definition: ntrip.h:19
#define STATUS_GBAS_FIX
bool sleep()
Location getGNGGA()
Definition: ntripclient.cpp:43
std::string fix
Definition: ntrip.h:44
const char * port
Definition: ntrip.h:12
const char * password
Definition: ntrip.h:16
enum SerialStopbits stopbits
Definition: ntrip.h:26
static Time now()
const char * proxyhost
Definition: ntrip.h:14
ROSCPP_DECL void spinOnce()
const char * nmea
Definition: ntrip.h:17
#define STATUS_FIX
const char * user
Definition: ntrip.h:13
std::string alt
Definition: ntrip.h:41
int initudp
Definition: ntrip.h:23
int main(int argc, char **argv)
const char * serdevice
Definition: ntrip.h:29
const char * server
Definition: ntrip.h:11
enum SerialParity parity
Definition: ntrip.h:27
Definition: ntrip.h:35


dgps_ros
Author(s):
autogenerated on Wed Jan 20 2021 03:38:34