2 #include <gps_common/GPSFix.h> 3 #include <gps_common/GPSStatus.h> 4 #include <sensor_msgs/NavSatFix.h> 5 #include <sensor_msgs/NavSatStatus.h> 15 GPSDClient() : privnode(
"~"), gps(NULL), use_gps_time(true), check_fix_by_variance(true),
frame_id(
"gps") {}
18 gps_fix_pub = node.advertise<GPSFix>(
"extended_fix", 1);
19 navsat_fix_pub = node.advertise<NavSatFix>(
"fix", 1);
21 privnode.getParam(
"use_gps_time", use_gps_time);
22 privnode.getParam(
"check_fix_by_variance", check_fix_by_variance);
25 std::string host =
"localhost";
27 privnode.getParam(
"host", host);
28 privnode.getParam(
"port", port);
31 snprintf(port_s, 12,
"%d", port);
33 gps_data_t *resp = NULL;
35 #if GPSD_API_MAJOR_VERSION >= 5 36 gps =
new gpsmm(host.c_str(), port_s);
37 resp = gps->stream(WATCH_ENABLE);
38 #elif GPSD_API_MAJOR_VERSION == 4 40 gps->open(host.c_str(), port_s);
41 resp = gps->stream(WATCH_ENABLE);
44 resp = gps->open(host.c_str(), port_s);
58 #if GPSD_API_MAJOR_VERSION >= 5 59 if (!gps->waiting(1e6))
62 gps_data_t *p = gps->read();
64 gps_data_t *p = gps->poll();
88 #if GPSD_API_MAJOR_VERSION >= 9 89 if (!p->online.tv_sec && !p->online.tv_nsec) {
97 process_data_navsat(p);
101 #if GPSD_API_MAJOR_VERSION >= 4 102 #define SATS_VISIBLE p->satellites_visible 103 #elif GPSD_API_MAJOR_VERSION == 3 104 #define SATS_VISIBLE p->satellites 106 #error "gpsd_client only supports gpsd API versions 3+" 115 status.header.stamp = time;
116 fix.header.stamp = time;
117 fix.header.frame_id = frame_id;
119 status.satellites_used = p->satellites_used;
121 status.satellite_used_prn.resize(status.satellites_used);
122 for (
int i = 0; i < status.satellites_used; ++i) {
123 #if GPSD_API_MAJOR_VERSION > 5 124 status.satellite_used_prn[i] = p->skyview[i].used;
126 status.satellite_used_prn[i] = p->used[i];
130 status.satellites_visible = SATS_VISIBLE;
132 status.satellite_visible_prn.resize(status.satellites_visible);
133 status.satellite_visible_z.resize(status.satellites_visible);
134 status.satellite_visible_azimuth.resize(status.satellites_visible);
135 status.satellite_visible_snr.resize(status.satellites_visible);
137 for (
int i = 0; i < SATS_VISIBLE; ++i) {
138 #if GPSD_API_MAJOR_VERSION > 5 139 status.satellite_visible_prn[i] = p->skyview[i].PRN;
140 status.satellite_visible_z[i] = p->skyview[i].elevation;
141 status.satellite_visible_azimuth[i] = p->skyview[i].azimuth;
142 status.satellite_visible_snr[i] = p->skyview[i].ss;
144 status.satellite_visible_prn[i] = p->PRN[i];
145 status.satellite_visible_z[i] = p->elevation[i];
146 status.satellite_visible_azimuth[i] = p->azimuth[i];
147 status.satellite_visible_snr[i] = p->ss[i];
151 if ((p->status & STATUS_FIX) && !(check_fix_by_variance && std::isnan(p->fix.epx))) {
156 #if GPSD_API_MAJOR_VERSION != 6 157 if (p->status & STATUS_DGPS_FIX)
161 #if GPSD_API_MAJOR_VERSION >= 9 162 fix.time = (double)(p->fix.time.tv_sec) + (double)(p->fix.time.tv_nsec) / 1000000.;
164 fix.time = p->fix.time;
166 fix.latitude = p->fix.latitude;
167 fix.longitude = p->fix.longitude;
168 fix.altitude = p->fix.altitude;
169 fix.track = p->fix.track;
170 fix.speed = p->fix.speed;
171 fix.climb = p->fix.climb;
173 #if GPSD_API_MAJOR_VERSION > 3 174 fix.pdop = p->dop.pdop;
175 fix.hdop = p->dop.hdop;
176 fix.vdop = p->dop.vdop;
177 fix.tdop = p->dop.tdop;
178 fix.gdop = p->dop.gdop;
187 #if GPSD_API_MAJOR_VERSION < 8 190 fix.err = p->fix.eph;
192 fix.err_vert = p->fix.epv;
193 fix.err_track = p->fix.epd;
194 fix.err_speed = p->fix.eps;
195 fix.err_climb = p->fix.epc;
196 fix.err_time = p->fix.ept;
209 NavSatFixPtr fix(
new NavSatFix);
213 #if GPSD_API_MAJOR_VERSION >= 9 214 if (use_gps_time && (p->online.tv_sec || p->online.tv_nsec)) {
215 fix->header.stamp =
ros::Time(p->fix.time.tv_sec, p->fix.time.tv_nsec);
217 if (use_gps_time && !std::isnan(p->fix.time)) {
218 fix->header.stamp =
ros::Time(p->fix.time);
225 fix->header.frame_id = frame_id;
233 fix->status.status = -1;
236 fix->status.status = 0;
239 #if GPSD_API_MAJOR_VERSION != 6 240 case STATUS_DGPS_FIX:
241 fix->status.status = 2;
246 fix->status.service = NavSatStatus::SERVICE_GPS;
248 fix->latitude = p->fix.latitude;
249 fix->longitude = p->fix.longitude;
250 fix->altitude = p->fix.altitude;
256 if (std::isnan(p->fix.epx) && check_fix_by_variance) {
260 fix->position_covariance[0] = p->fix.epx;
261 fix->position_covariance[4] = p->fix.epy;
262 fix->position_covariance[8] = p->fix.epv;
264 fix->position_covariance_type = NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN;
270 int main(
int argc,
char ** argv) {
void publish(const boost::shared_ptr< M > &message) const
void process_data_navsat(struct gps_data_t *p)
ros::Publisher gps_fix_pub
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool check_fix_by_variance
void process_data_gps(struct gps_data_t *p)
int main(int argc, char **argv)
ROSCPP_DECL void spinOnce()
ros::Publisher navsat_fix_pub
void process_data(struct gps_data_t *p)