Paparazzi UAS
v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
pprz_circfit_float.c
Go to the documentation of this file.
1
/*
2
* This file is part of paparazzi
3
*
4
* paparazzi is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
7
* any later version.
8
*
9
* paparazzi is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with paparazzi; see the file COPYING. If not, see
16
* <http://www.gnu.org/licenses/>.
17
*/
18
19
#include "
math/pprz_circfit_float.h
"
20
#include <math.h>
21
22
#ifndef PPRZ_CIRCFIT_EPSILON
23
#define PPRZ_CIRCFIT_EPSILON 1e-3f
24
#endif
25
26
#ifndef PPRZ_CIRCFIT_ITER_MAX
27
#define PPRZ_CIRCFIT_ITER_MAX 250
28
#endif
29
30
#ifndef PPRZ_CIRCFIT_NORM_CUTOFF
31
#define PPRZ_CIRCFIT_NORM_CUTOFF 1e-6f
32
#endif
33
34
enum
CircFitStatus_t
pprz_circfit_wei_float
(
struct
circle_t
*c,
const
float
*x,
const
float
*y,
uint16_t
n,
struct
circle_t
*
g
) {
35
36
// Check if initial guess is provided
37
if
(
g
!=
NULL
) {
38
c->
r
=
g
->r;
39
c->
x
=
g
->x;
40
c->
y
=
g
->y;
41
}
else
{
42
c->
x
= 0.0f;
43
c->
y
= 0.0f;
44
c->
r
= 1.0f;
45
}
46
47
float
norm
[n];
48
float
x_prev
= 0;
49
float
y_prev
= 0;
50
float
r_prev
= -1;
51
uint16_t
iteration
= 0;
52
53
while
(
fabsf
(c->
r
-
r_prev
) >
PPRZ_CIRCFIT_EPSILON
||
fabsf
(c->
x
-
x_prev
) >
PPRZ_CIRCFIT_EPSILON
||
fabsf
(c->
y
-
y_prev
) >
PPRZ_CIRCFIT_EPSILON
) {
54
55
float
sum_norm
= 0.0f;
56
x_prev
= c->
x
;
57
y_prev
= c->
y
;
58
r_prev
= c->
r
;
59
60
// Prepare ||x - c||
61
for
(
int
i = 0; i < n; i++) {
62
norm
[i] =
sqrtf
((x[i] -
x_prev
) * (x[i] -
x_prev
) + (y[i] -
y_prev
) * (y[i] -
y_prev
));
63
sum_norm
+=
norm
[i];
64
}
65
66
c->
r
=
sum_norm
/ n;
67
68
for
(
int
i = 0; i < n; i++) {
69
if
(
norm
[i] <
PPRZ_CIRCFIT_NORM_CUTOFF
)
70
{
71
return
CIRC_FIT_NORM_ERROR
;
// Norm error, too small distance
72
}
73
c->
x
+= x[i] + c->
r
* (
x_prev
- x[i]) /
norm
[i];
74
c->
y
+= y[i] + c->
r
* (
y_prev
- y[i]) /
norm
[i];
75
}
76
77
c->
x
/= n;
78
c->
y
/= n;
79
80
iteration
++;
81
82
if
(
iteration
>=
PPRZ_CIRCFIT_ITER_MAX
) {
83
return
CIRC_FIT_ITERATION_LIMIT
;
// Reached iteration limit
84
}
85
86
}
87
88
return
CIRC_FIT_OK
;
// Circle fit successful
89
90
}
foo
uint16_t foo
Definition
main_demo5.c:58
g
static float g
Definition
oneloop_andi.c:340
PPRZ_CIRCFIT_ITER_MAX
#define PPRZ_CIRCFIT_ITER_MAX
Definition
pprz_circfit_float.c:27
pprz_circfit_wei_float
enum CircFitStatus_t pprz_circfit_wei_float(struct circle_t *c, const float *x, const float *y, uint16_t n, struct circle_t *g)
Definition
pprz_circfit_float.c:34
PPRZ_CIRCFIT_EPSILON
#define PPRZ_CIRCFIT_EPSILON
Definition
pprz_circfit_float.c:23
PPRZ_CIRCFIT_NORM_CUTOFF
#define PPRZ_CIRCFIT_NORM_CUTOFF
Definition
pprz_circfit_float.c:31
pprz_circfit_float.h
circle_t::y
float y
Definition
pprz_circfit_float.h:33
circle_t::x
float x
Definition
pprz_circfit_float.h:32
CircFitStatus_t
CircFitStatus_t
Definition
pprz_circfit_float.h:24
CIRC_FIT_NORM_ERROR
@ CIRC_FIT_NORM_ERROR
Definition
pprz_circfit_float.h:28
CIRC_FIT_OK
@ CIRC_FIT_OK
Definition
pprz_circfit_float.h:25
CIRC_FIT_ITERATION_LIMIT
@ CIRC_FIT_ITERATION_LIMIT
Definition
pprz_circfit_float.h:27
circle_t::r
float r
Definition
pprz_circfit_float.h:34
circle_t
Definition
pprz_circfit_float.h:31
uint16_t
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition
vl53l1_types.h:88
sw
airborne
math
pprz_circfit_float.c
Generated on Tue Sep 2 2025 15:53:31 for Paparazzi UAS by
1.9.8