2 * This file is part of u360gts, aka amv-open360tracker 32bits:
3 * https://github.com/raul-ortega/amv-open360tracker-32bits
5 * u360gts is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * u360gts is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with u360gts. If not, see <http://www.gnu.org/licenses/>.
20 #include "interpolation.h"
22 #define INT_ELEMENTS 10
24 iPoint_t iPoints
[INT_ELEMENTS
];
37 bool iPutPoint(uint32_t time
,float heading
,float speed
){
40 point
.heading
= heading
;
50 return (iQIn
== (( iQOut
- 1 + INT_QSIZE
) % INT_QSIZE
));
53 bool iPut(iPoint_t point
){
56 return true; /* Full */
59 iPoints
[iQIn
].time
= point
.time
;
60 iPoints
[iQIn
].heading
= point
.heading
;
61 iPoints
[iQIn
].speed
= point
.speed
;
63 iQIn
= (iQIn
+ 1) % INT_QSIZE
;
65 return false; // No errors
71 return true; /* Queue Empty - nothing to get*/
74 iQOut
= (iQOut
+ 1) % INT_QSIZE
;
76 return false; // No errors
79 iPoint_t
iEval(float A
){
83 int index_i
= iQIn
- 1;
84 int index_j
= index_i
;
89 for(i
=1; i
<INT_QSIZE
+ 1; i
++)
91 index_i
= (index_i
+ 1) % INT_QSIZE
;
93 l
.heading
= iPoints
[index_i
].heading
;
94 l
.speed
= iPoints
[index_i
].speed
;
95 for(j
=1; j
<INT_QSIZE
+ 1; j
++)
97 index_j
= (index_j
+ 1) % INT_QSIZE
;
101 l
.heading
= (l
.heading
* (A
- iPoints
[index_j
].time
* 1.0f
))/(iPoints
[index_i
].time
* 1.0f
- iPoints
[index_j
].time
* 1.0f
);
102 l
.speed
= (l
.speed
* (A
- iPoints
[index_j
].time
))/(iPoints
[index_i
].time
- iPoints
[index_j
].time
);
103 //printf("%d %d %d %d %.2f %d %d %d\n",i,j,index_i,index_j,A,iPoints[index_i].time,iPoints[index_j].time);
106 v
.heading
= v
.heading
+ l
.heading
;
107 v
.speed
= v
.speed
+ l
.speed
;