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();
92 process_data_navsat(p);
96 #if GPSD_API_MAJOR_VERSION >= 4 97 #define SATS_VISIBLE p->satellites_visible 98 #elif GPSD_API_MAJOR_VERSION == 3 99 #define SATS_VISIBLE p->satellites 101 #error "gpsd_client only supports gpsd API versions 3+" 110 status.header.stamp = time;
111 fix.header.stamp = time;
112 fix.header.frame_id = frame_id;
114 status.satellites_used = p->satellites_used;
116 status.satellite_used_prn.resize(status.satellites_used);
117 for (
int i = 0; i < status.satellites_used; ++i) {
118 #if GPSD_API_MAJOR_VERSION > 5 119 status.satellite_used_prn[i] = p->skyview[i].used;
121 status.satellite_used_prn[i] = p->used[i];
125 status.satellites_visible = SATS_VISIBLE;
127 status.satellite_visible_prn.resize(status.satellites_visible);
128 status.satellite_visible_z.resize(status.satellites_visible);
129 status.satellite_visible_azimuth.resize(status.satellites_visible);
130 status.satellite_visible_snr.resize(status.satellites_visible);
132 for (
int i = 0; i < SATS_VISIBLE; ++i) {
133 #if GPSD_API_MAJOR_VERSION > 5 134 status.satellite_visible_prn[i] = p->skyview[i].PRN;
135 status.satellite_visible_z[i] = p->skyview[i].elevation;
136 status.satellite_visible_azimuth[i] = p->skyview[i].azimuth;
137 status.satellite_visible_snr[i] = p->skyview[i].ss;
139 status.satellite_visible_prn[i] = p->PRN[i];
140 status.satellite_visible_z[i] = p->elevation[i];
141 status.satellite_visible_azimuth[i] = p->azimuth[i];
142 status.satellite_visible_snr[i] = p->ss[i];
146 if ((p->status & STATUS_FIX) && !(check_fix_by_variance && std::isnan(p->fix.epx))) {
151 #if GPSD_API_MAJOR_VERSION != 6 152 if (p->status & STATUS_DGPS_FIX)
156 fix.time = p->fix.time;
157 fix.latitude = p->fix.latitude;
158 fix.longitude = p->fix.longitude;
159 fix.altitude = p->fix.altitude;
160 fix.track = p->fix.track;
161 fix.speed = p->fix.speed;
162 fix.climb = p->fix.climb;
164 #if GPSD_API_MAJOR_VERSION > 3 165 fix.pdop = p->dop.pdop;
166 fix.hdop = p->dop.hdop;
167 fix.vdop = p->dop.vdop;
168 fix.tdop = p->dop.tdop;
169 fix.gdop = p->dop.gdop;
179 fix.err_vert = p->fix.epv;
180 fix.err_track = p->fix.epd;
181 fix.err_speed = p->fix.eps;
182 fix.err_climb = p->fix.epc;
183 fix.err_time = p->fix.ept;
196 NavSatFixPtr fix(
new NavSatFix);
200 if (use_gps_time && !std::isnan(p->fix.time))
201 fix->header.stamp =
ros::Time(p->fix.time);
205 fix->header.frame_id = frame_id;
213 fix->status.status = -1;
216 fix->status.status = 0;
219 #if GPSD_API_MAJOR_VERSION != 6 220 case STATUS_DGPS_FIX:
221 fix->status.status = 2;
226 fix->status.service = NavSatStatus::SERVICE_GPS;
228 fix->latitude = p->fix.latitude;
229 fix->longitude = p->fix.longitude;
230 fix->altitude = p->fix.altitude;
236 if (std::isnan(p->fix.epx) && check_fix_by_variance) {
240 fix->position_covariance[0] = p->fix.epx;
241 fix->position_covariance[4] = p->fix.epy;
242 fix->position_covariance[8] = p->fix.epv;
244 fix->position_covariance_type = NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN;
250 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)