Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
dcf.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Hector Garcia de Marina
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 *
20 */
21
22#include <math.h>
23#include <std.h>
24
25#include "modules/muti/dcf/dcf.h"
28#include "autopilot.h"
29#include "std.h"
30
31#if PERIODIC_TELEMETRY
32static void send_dcf(struct transport_tx *trans, struct link_device *dev)
33{
36}
37#endif // PERIODIC TELEMETRY
38
39// Control
41#ifndef DCF_GAIN_K
42#define DCF_GAIN_K 10
43#endif
45#ifndef DCF_RADIUS
46#define DCF_RADIUS 80
47#endif
49#ifndef DCF_TIMEOUT
50#define DCF_TIMEOUT 1500
51#endif
53#ifndef DCF_BROADTIME
54#define DCF_BROADTIME 200
55#endif
56
59
61
62void dcf_init(void)
63{
64 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++) {
65 dcf_tables.tableNei[i][0] = -1;
67 }
68
69#if PERIODIC_TELEMETRY
71#endif
72}
73
75{
76 float xc = waypoints[wp].x;
77 float yc = waypoints[wp].y;
79 float x = p->x;
80 float y = p->y;
81 float u = 0;
82
83 dcf_control.theta = atan2f(y - yc, x - xc);
84
86
87 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++) {
88 if (dcf_tables.tableNei[i][0] != -1) {
92 } else {
94
95 float t1 = dcf_control.theta;
96 float t2 = dcf_tables.tableNei[i][1] * M_PI / 1800.0;
97 float td = dcf_tables.tableNei[i][2] * M_PI / 1800.0;
98
99 float c1 = cosf(t1);
100 float s1 = sinf(t1);
101 float c2 = cosf(t2);
102 float s2 = sinf(t2);
103
104 float e = atan2f(c2 * s1 - s2 * c1, c1 * c2 + s1 * s2) - gvf_control.s * td;
105
106 u += e;
107 dcf_tables.error_sigma[i] = (uint16_t)(e * 1800.0 / M_PI);
108 }
109 }
110 }
111
112 u *= -gvf_control.s * dcf_control.k;
113
115
119 }
120
121 return true;
122}
123
125{
126 struct pprzlink_msg msg;
127
128 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++)
129 if (dcf_tables.tableNei[i][0] != -1) {
130 msg.trans = &(DefaultChannel).trans_tx;
131 msg.dev = &(DefaultDevice).device;
132 msg.sender_id = AC_ID;
133 msg.receiver_id = dcf_tables.tableNei[i][0];
134 msg.component_id = 0;
136 }
137}
138
140{
141 uint8_t ac_id = DL_DCF_REG_TABLE_ac_id(buf);
142 if (ac_id == AC_ID) {
145
146 if (nei_id == 0) {
147 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++) {
148 dcf_tables.tableNei[i][0] = -1;
149 }
150 } else {
151 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++)
152 if (dcf_tables.tableNei[i][0] == (int16_t)nei_id) {
155 return;
156 }
157
158 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++)
159 if (dcf_tables.tableNei[i][0] == -1) {
162 return;
163 }
164 }
165 }
166}
167
169{
171 for (int i = 0; i < DCF_MAX_NEIGHBORS; i++)
172 if (dcf_tables.tableNei[i][0] == sender_id) {
174 dcf_tables.tableNei[i][1] = (int16_t)((DL_DCF_THETA_theta(buf)) * 1800 / M_PI);
175 break;
176 }
177}
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition autopilot.c:222
Core autopilot interface common to all firmwares.
static uint16_t c1
static uint16_t c2
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:44
float y
Definition common_nav.h:41
float x
Definition common_nav.h:40
void send_theta_to_nei(void)
Definition dcf.c:124
#define DCF_BROADTIME
Definition dcf.c:54
uint32_t last_transmision
Definition dcf.c:60
#define DCF_RADIUS
Definition dcf.c:46
void dcf_init(void)
Definition dcf.c:62
static void send_dcf(struct transport_tx *trans, struct link_device *dev)
Definition dcf.c:32
#define DCF_TIMEOUT
Definition dcf.c:50
void parseThetaTable(uint8_t *buf)
Definition dcf.c:168
struct dcf_tab dcf_tables
Definition dcf.c:58
void parseRegTable(uint8_t *buf)
Definition dcf.c:139
struct dcf_con dcf_control
Definition dcf.c:57
#define DCF_GAIN_K
Definition dcf.c:42
bool distributed_circular(uint8_t wp)
Definition dcf.c:74
uint32_t last_theta[DCF_MAX_NEIGHBORS]
Definition dcf.h:50
float theta
Definition dcf.h:41
int16_t error_sigma[DCF_MAX_NEIGHBORS]
Definition dcf.h:49
#define DCF_MAX_NEIGHBORS
Definition dcf.h:34
float radius
Definition dcf.h:39
uint16_t broadtime
Definition dcf.h:42
uint16_t timeout
Definition dcf.h:40
int16_t tableNei[DCF_MAX_NEIGHBORS][4]
Definition dcf.h:48
float k
Definition dcf.h:38
Definition dcf.h:37
Definition dcf.h:47
static struct uart_periph * dev
#define AP_MODE_AUTO2
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
gvf_con gvf_control
Definition gvf.c:30
int8_t s
Definition gvf.h:59
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
static float p[2][2]
static float t1
uint16_t foo
Definition main_demo5.c:58
bool nav_gvf_ellipse_XY(float x, float y, float a, float b, float alpha)
Definition nav_ellipse.c:64
static float timeout
float y
in meters
float x
in meters
vector in East North Up coordinates Units: meters
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.