Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
pprz_doublet.c
Go to the documentation of this file.
1/*
2* Copyright (C) Alessandro Collicelli
3*
4* This file is part of paparazzi
5*
6* paparazzi is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2, or (at your option)
9* any later version.
10*
11* paparazzi is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with paparazzi; see the file COPYING. If not, see
18* <http://www.gnu.org/licenses/>.
19*/
26#include "pprz_doublet.h"
27#include "std.h"
28
29
30
31void doublet_init(struct doublet_t *doublet, float length_s, float extra_waiting_time_s, float current_time_s, uint8_t mod)
32{
33 doublet->t0 = current_time_s;
34 doublet->tf = length_s;
36 doublet->mod = mod;
38 doublet->current_time_s = current_time_s;
39
40 if (mod==0) { // Normal doublet
41 doublet->t1 = length_s / 4;
42 doublet->t2 = doublet->t1 * 2;
43 doublet->t3 = doublet->t1 * 3;
44 doublet->t4 = doublet->t1 * 4;
45 doublet->t5 = doublet->tf;
46 } else if (mod==1) { // Half doublet
47 doublet->t1 = length_s / 4;
48 doublet->t2 = doublet->t1 * 2;
49 doublet->t3 = doublet->t1 * 3;
50 doublet->t4 = doublet->t1 * 4;
51 doublet->t5 = doublet->tf;
52 } else if (mod==2) { // 3211 doublet
53 doublet->t1 = length_s / 9;
54 doublet->t2 = doublet->t1 * 4;
55 doublet->t3 = doublet->t1 * 6;
56 doublet->t4 = doublet->t1 * 7;
57 doublet->t5 = doublet->t1 * 8;
58 } else if (mod==3) { // highspeed doublet: one doublet, no waiting time
59 doublet->t1 = 0;
60 doublet->t2 = length_s / 2;
61 doublet->t3 = doublet->tf;
62 doublet->t4 = 0; // not used
63 doublet->t5 = 0; // not used
64 }
65}
66
67void doublet_reset(struct doublet_t *doublet, float current_time_s){
68 doublet->t0 = current_time_s;
69 doublet->current_value = 0.0f;
70 doublet->current_time_s = current_time_s;
71}
72
73bool doublet_is_running(struct doublet_t *doublet, float current_time_s){
74 float t = current_time_s - doublet->t0;
75 return (t >= 0) && (t <= doublet->total_length_s);
76}
77
78float doublet_update(struct doublet_t *doublet, float current_time_s){
79
80 if(!doublet_is_running(doublet, current_time_s)){
81 doublet->current_value = 0.0f;
82 return 0;
83 }
84
85 float t = current_time_s - doublet->t0; // since the start of the doublet
86 if ((t>=0) & (t<=doublet->tf)){
87 if (doublet->mod == 0 || doublet->mod == 3) {
88 if((t >= doublet->t1) & (t <= doublet->t2)){
89 doublet->current_value = 1.0f;
90 }else if((t >= doublet->t2) & (t <= doublet->t3)){
91 doublet->current_value = -1.0f;
92 }else{
93 doublet->current_value = 0.0f;
94 }
95 } else if (doublet->mod == 1) {
96 if((t >= doublet->t1) & (t <= doublet->t2)){
97 doublet->current_value = 1.0f;
98 }else if((t >= doublet->t2) & (t <= doublet->t3)){
99 doublet->current_value = 1.0f;
100 }else{
101 doublet->current_value = 0.0f;
102 }
103 } else if (doublet->mod == 2) {
104 if (((t >= doublet->t1) & (t <= doublet->t2)) | ((t >= doublet->t3) & (t <= doublet->t4))){
105 doublet->current_value = 1.0f;
106 }else if(((t >= doublet->t2) && (t <= doublet->t3)) | ((t >= doublet->t4) && (t <= doublet->t5))){
107 doublet->current_value = -1.0f;
108 }else{
109 doublet->current_value = 0.0f;
110 }
111 }
112 } else {
113 doublet->current_value = 0.0f;
114 }
115 return doublet->current_value;
116}
uint16_t foo
Definition main_demo5.c:58
void doublet_init(struct doublet_t *doublet, float length_s, float extra_waiting_time_s, float current_time_s, uint8_t mod)
bool doublet_is_running(struct doublet_t *doublet, float current_time_s)
void doublet_reset(struct doublet_t *doublet, float current_time_s)
float doublet_update(struct doublet_t *doublet, float current_time_s)
float total_length_s
uint8_t mod
float current_value
float current_time_s
Initialize with doublet_init.
static struct doublet_t doublet
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.