00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033
00034 #include "devicetable.h"
00035 #include "amcl_gps.h"
00036
00037
00039
00040 AMCLGps::AMCLGps()
00041 {
00042 this->device = NULL;
00043 this->model = NULL;
00044
00045 return;
00046 }
00047
00048
00050
00051 int AMCLGps::Load(ConfigFile* cf, int section)
00052 {
00053
00054 this->gps_index = cf->ReadInt(section, "gps_index", -1);
00055
00056
00057 this->model = gps_alloc();
00058 this->model->utm_base_e = cf->ReadTupleFloat(section, "utm_base", 0, -1);
00059 this->model->utm_base_n = cf->ReadTupleFloat(section, "utm_base", 1, -1);
00060
00061 return 0;
00062 }
00063
00064
00066
00067 int AMCLGps::Unload(void)
00068 {
00069 gps_free(this->model);
00070 this->model = NULL;
00071
00072 return 0;
00073 }
00074
00075
00077
00078 int AMCLGps::Setup(void)
00079 {
00080 player_device_id_t id;
00081
00082
00083 id.code = PLAYER_GPS_CODE;
00084 id.index = this->gps_index;
00085
00086 this->device = deviceTable->GetDriver(id);
00087 if (!this->device)
00088 {
00089 PLAYER_ERROR("unable to locate suitable gps device");
00090 return -1;
00091 }
00092 if (this->device->Subscribe(this) != 0)
00093 {
00094 PLAYER_ERROR("unable to subscribe to gps device");
00095 return -1;
00096 }
00097
00098 return 0;
00099 }
00100
00101
00103
00104 int AMCLGps::Shutdown(void)
00105 {
00106 this->device->Unsubscribe(this);
00107 this->device = NULL;
00108
00109 return 0;
00110 }
00111
00112
00114
00115 bool AMCLGps::GetData()
00116 {
00117 size_t size;
00118 player_gps_data_t data;
00119 uint32_t tsec, tusec;
00120
00121
00122 size = this->device->GetData(this, (uint8_t*) &data, sizeof(data), &tsec, &tusec);
00123 if (size < sizeof(data))
00124 return false;
00125
00126 if (tsec == this->tsec && tusec == this->tusec)
00127 return false;
00128
00129 this->tsec = tsec;
00130 this->tusec = tusec;
00131
00132 this->utm_e = ((int32_t) ntohl(data.utm_e)) / 100.0;
00133 this->utm_n = ((int32_t) ntohl(data.utm_n)) / 100.0;
00134 this->err_horz = ((int32_t) ntohl(data.err_horz)) / 1000.0;
00135
00136 return true;
00137 }
00138
00139
00141
00142 bool AMCLGps::InitSensor(pf_t *pf, pf_vector_t mean, pf_matrix_t cov)
00143 {
00144
00145 if (!this->GetData())
00146 return false;
00147
00148 printf("init gps %f %f %f\n",
00149 this->utm_e, this->utm_n, this->err_horz);
00150
00151
00152 if (this->model->utm_base_e < 0 || this->model->utm_base_n < 0)
00153 {
00154 this->model->utm_base_e = this->utm_e;
00155 this->model->utm_base_n = this->utm_n;
00156 PLAYER_WARN2("UTM base coord not set; defaulting to [%.3f %.3f]",
00157 this->model->utm_base_e, this->model->utm_base_n);
00158 }
00159
00160
00161 gps_set_utm(this->model, this->utm_e, this->utm_n, this->err_horz);
00162
00163
00164 gps_init_init(this->model);
00165
00166
00167 pf_init(pf, (pf_init_model_fn_t) gps_init_model, this->model);
00168
00169 gps_init_term(this->model);
00170
00171 return true;
00172 }
00173
00174
00176
00177 bool AMCLGps::UpdateSensor(pf_t *pf)
00178 {
00179
00180 if (!this->GetData())
00181 return false;
00182
00183 printf("update gps %f %f %f\n",
00184 this->utm_e, this->utm_n, this->err_horz);
00185
00186
00187 gps_set_utm(this->model, this->utm_e, this->utm_n, this->err_horz);
00188
00189
00190 pf_update_sensor(pf, (pf_sensor_model_fn_t) gps_sensor_model, this->model);
00191
00192 return true;
00193 }
00194
00195 #ifdef INCLUDE_RTKGUI
00196
00198
00199 void AMCLGps::SetupGUI(rtk_canvas_t *canvas, rtk_fig_t *robot_fig)
00200 {
00201 this->fig = rtk_fig_create(canvas, NULL, 0);
00202
00203 return;
00204 }
00205
00206
00208
00209 void AMCLGps::ShutdownGUI(rtk_canvas_t *canvas, rtk_fig_t *robot_fig)
00210 {
00211 rtk_fig_destroy(this->fig);
00212 this->fig = NULL;
00213
00214 return;
00215 }
00216
00218
00219 void AMCLGps::UpdateGUI(rtk_canvas_t *canvas, rtk_fig_t *robot_fig)
00220 {
00221 rtk_fig_clear(this->fig);
00222 rtk_fig_color_rgb32(this->fig, 0xFF00FF);
00223
00224 rtk_fig_ellipse(this->fig,
00225 this->utm_e - this->model->utm_base_e,
00226 this->utm_n - this->model->utm_base_n, 0,
00227 this->err_horz, this->err_horz, 0);
00228
00229 return;
00230 }
00231
00232 #endif