Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 
31 void 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;
35  doublet->total_length_s = doublet->tf + extra_waiting_time_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  }
59 }
60 
61 void doublet_reset(struct doublet_t *doublet, float current_time_s){
62  doublet->t0 = current_time_s;
63  doublet->current_value = 0.0f;
64  doublet->current_time_s = current_time_s;
65 }
66 
67 bool doublet_is_running(struct doublet_t *doublet, float current_time_s){
68  float t = current_time_s - doublet->t0;
69  return (t >= 0) && (t <= doublet->total_length_s);
70 }
71 
72 float doublet_update(struct doublet_t *doublet, float current_time_s){
73 
74  if(!doublet_is_running(doublet, current_time_s)){
75  doublet->current_value = 0.0f;
76  return 0;
77  }
78 
79  float t = current_time_s - doublet->t0; // since the start of the doublet
80  if ((t>=0) & (t<=doublet->tf)){
81  if (doublet->mod == 0) {
82  if((t >= doublet->t1) & (t <= doublet->t2)){
83  doublet->current_value = 1.0f;
84  }else if((t >= doublet->t2) & (t <= doublet->t3)){
85  doublet->current_value = -1.0f;
86  }else{
87  doublet->current_value = 0.0f;
88  }
89  } else if (doublet->mod == 1) {
90  if((t >= doublet->t1) & (t <= doublet->t2)){
91  doublet->current_value = 1.0f;
92  }else if((t >= doublet->t2) & (t <= doublet->t3)){
93  doublet->current_value = 1.0f;
94  }else{
95  doublet->current_value = 0.0f;
96  }
97  } else if (doublet->mod == 2) {
98  if (((t >= doublet->t1) & (t <= doublet->t2)) | ((t >= doublet->t3) & (t <= doublet->t4))){
99  doublet->current_value = 1.0f;
100  }else if(((t >= doublet->t2) && (t <= doublet->t3)) | ((t >= doublet->t4) && (t <= doublet->t5))){
101  doublet->current_value = -1.0f;
102  }else{
103  doublet->current_value = 0.0f;
104  }
105  }
106  } else {
107  doublet->current_value = 0.0f;
108  }
109  return doublet->current_value;
110 }
void doublet_init(struct doublet_t *doublet, float length_s, float extra_waiting_time_s, float current_time_s, uint8_t mod)
Definition: pprz_doublet.c:31
bool doublet_is_running(struct doublet_t *doublet, float current_time_s)
Definition: pprz_doublet.c:67
void doublet_reset(struct doublet_t *doublet, float current_time_s)
Definition: pprz_doublet.c:61
float doublet_update(struct doublet_t *doublet, float current_time_s)
Definition: pprz_doublet.c:72
float t2
Definition: pprz_doublet.h:59
float total_length_s
Definition: pprz_doublet.h:64
float tf
Definition: pprz_doublet.h:63
float t5
Definition: pprz_doublet.h:62
uint8_t mod
Definition: pprz_doublet.h:68
float t4
Definition: pprz_doublet.h:61
float t3
Definition: pprz_doublet.h:60
float current_value
Definition: pprz_doublet.h:65
float t1
Definition: pprz_doublet.h:58
float t0
Definition: pprz_doublet.h:57
float current_time_s
Definition: pprz_doublet.h:66
Initialize with doublet_init.
Definition: pprz_doublet.h:56
static struct doublet_t doublet
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98