pf_draw.c
Go to the documentation of this file.
1 //this package is based on amcl and has been modified to fit gmcl
2 /*
3  * Author: Mhd Ali Alshikh Khalil
4  * Date: 20 June 2021
5  *
6 */
7 
8 //amcl author clarification
9 /*
10  * Player - One Hell of a Robot Server
11  * Copyright (C) 2000 Brian Gerkey & Kasper Stoy
12  * gerkey@usc.edu kaspers@robotics.usc.edu
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  *
28  */
29 /**************************************************************************
30  * Desc: Particle filter; drawing routines
31  * Author: Andrew Howard
32  * Date: 10 Dec 2002
33  * CVS: $Id: pf_draw.c 7057 2008-10-02 00:44:06Z gbiggs $
34  *************************************************************************/
35 
36 #ifdef INCLUDE_RTKGUI
37 
38 #include <assert.h>
39 #include <math.h>
40 #include <stdlib.h>
41 
42 
43 #include "rtk.h"
44 
45 #include "pf.h"
46 #include "pf_pdf.h"
47 #include "pf_kdtree.h"
48 
49 
50 // Draw the statistics
51 void pf_draw_statistics(pf_t *pf, rtk_fig_t *fig);
52 
53 
54 // Draw the sample set
55 void pf_draw_samples(pf_t *pf, rtk_fig_t *fig, int max_samples)
56 {
57  int i;
58  double px, py, pa;
60  pf_sample_t *sample;
61 
62  set = pf->sets + pf->current_set;
63  max_samples = MIN(max_samples, set->sample_count);
64 
65  for (i = 0; i < max_samples; i++)
66  {
67  sample = set->samples + i;
68 
69  px = sample->pose.v[0];
70  py = sample->pose.v[1];
71  pa = sample->pose.v[2];
72 
73  //printf("%f %f\n", px, py);
74 
75  rtk_fig_point(fig, px, py);
76  rtk_fig_arrow(fig, px, py, pa, 0.1, 0.02);
77  //rtk_fig_rectangle(fig, px, py, 0, 0.1, 0.1, 0);
78  }
79 
80  return;
81 }
82 
83 
84 // Draw the hitogram (kd tree)
85 void pf_draw_hist(pf_t *pf, rtk_fig_t *fig)
86 {
88 
89  set = pf->sets + pf->current_set;
90 
91  rtk_fig_color(fig, 0.0, 0.0, 1.0);
92  pf_kdtree_draw(set->kdtree, fig);
93 
94  return;
95 }
96 
97 
98 // Draw the CEP statistics
99 void pf_draw_cep_stats(pf_t *pf, rtk_fig_t *fig)
100 {
101  pf_vector_t mean;
102  double var;
103 
104  pf_get_cep_stats(pf, &mean, &var);
105  var = sqrt(var);
106 
107  rtk_fig_color(fig, 0, 0, 1);
108  rtk_fig_ellipse(fig, mean.v[0], mean.v[1], mean.v[2], 3 * var, 3 * var, 0);
109 
110  return;
111 }
112 
113 
114 // Draw the cluster statistics
115 void pf_draw_cluster_stats(pf_t *pf, rtk_fig_t *fig)
116 {
117  int i;
118  pf_cluster_t *cluster;
120  pf_vector_t mean;
121  pf_matrix_t cov;
122  pf_matrix_t r, d;
123  double weight, o, d1, d2;
124 
125  set = pf->sets + pf->current_set;
126 
127  for (i = 0; i < set->cluster_count; i++)
128  {
129  cluster = set->clusters + i;
130 
131  weight = cluster->weight;
132  mean = cluster->mean;
133  cov = cluster->cov;
134 
135  // Compute unitary representation S = R D R^T
136  pf_matrix_unitary(&r, &d, cov);
137 
138  /* Debugging
139  printf("mean = \n");
140  pf_vector_fprintf(mean, stdout, "%e");
141  printf("cov = \n");
142  pf_matrix_fprintf(cov, stdout, "%e");
143  printf("r = \n");
144  pf_matrix_fprintf(r, stdout, "%e");
145  printf("d = \n");
146  pf_matrix_fprintf(d, stdout, "%e");
147  */
148 
149  // Compute the orientation of the error ellipse (first eigenvector)
150  o = atan2(r.m[1][0], r.m[0][0]);
151  d1 = 6 * sqrt(d.m[0][0]);
152  d2 = 6 * sqrt(d.m[1][1]);
153 
154  if (d1 > 1e-3 && d2 > 1e-3)
155  {
156  // Draw the error ellipse
157  rtk_fig_ellipse(fig, mean.v[0], mean.v[1], o, d1, d2, 0);
158  rtk_fig_line_ex(fig, mean.v[0], mean.v[1], o, d1);
159  rtk_fig_line_ex(fig, mean.v[0], mean.v[1], o + M_PI / 2, d2);
160  }
161 
162  // Draw a direction indicator
163  rtk_fig_arrow(fig, mean.v[0], mean.v[1], mean.v[2], 0.50, 0.10);
164  rtk_fig_arrow(fig, mean.v[0], mean.v[1], mean.v[2] + 3 * sqrt(cov.m[2][2]), 0.50, 0.10);
165  rtk_fig_arrow(fig, mean.v[0], mean.v[1], mean.v[2] - 3 * sqrt(cov.m[2][2]), 0.50, 0.10);
166  }
167 
168  return;
169 }
170 
171 #endif
pf_kdtree.h
pf.h
pf_vector_t
Definition: pf_vector.h:46
_pf_sample_set_t
Definition: pf.h:107
pf_matrix_t::m
double m[3][3]
Definition: pf_vector.h:55
_pf_t
Definition: pf.h:150
_pf_t::sets
pf_sample_set_t sets[2]
Definition: pf.h:166
pf_cluster_t::mean
pf_vector_t mean
Definition: pf.h:98
pf_draw_cluster_stats
void pf_draw_cluster_stats(pf_t *pf, struct _rtk_fig_t *fig)
pf_get_cep_stats
void pf_get_cep_stats(pf_t *pf, pf_vector_t *mean, double *var)
Definition: pf.c:1078
pf_matrix_unitary
void pf_matrix_unitary(pf_matrix_t *r, pf_matrix_t *d, pf_matrix_t a)
Definition: pf_vector.c:230
d
d
pf_draw_cep_stats
void pf_draw_cep_stats(pf_t *pf, struct _rtk_fig_t *fig)
pf_pdf.h
pf_sample_t
Definition: pf.h:72
set
ROSCPP_DECL void set(const std::string &key, bool b)
pf_sample_t::pose
pf_vector_t pose
Definition: pf.h:75
pf_cluster_t
Definition: pf.h:89
pf_draw_hist
void pf_draw_hist(pf_t *pf, struct _rtk_fig_t *fig)
pf_cluster_t::weight
double weight
Definition: pf.h:95
pf_matrix_t
Definition: pf_vector.h:53
assert.h
pf_cluster_t::cov
pf_matrix_t cov
Definition: pf.h:99
_pf_t::current_set
int current_set
Definition: pf.h:165
pf_vector_t::v
double v[3]
Definition: pf_vector.h:53
pf_draw_samples
void pf_draw_samples(pf_t *pf, struct _rtk_fig_t *fig, int max_samples)


gmcl
Author(s): Mhd Ali Alshikh Khalil, adler1994@gmail.com
autogenerated on Wed Mar 2 2022 00:20:14