Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
logger_control_effectiveness.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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
25
28#include "mcu_periph/sys_time.h"
29#include "state.h"
30
31#if USE_CHIBIOS_RTOS
32#define LogFormatHeader "%.5f,%ld,%ld,%ld,%ld,%ld,%ld"
33#define LogFormatVect3 ",%ld,%ld,%ld"
34#define LogFormatI32 ",%ld"
35
36#else // assume Linux based OS
37#define LogFormatHeader "%.5f,%d,%d,%d,%d,%d,%d"
38#define LogFormatVect3 ",%d,%d,%d"
39#define LogFormatI32 ",%d"
40static FILE* pprzLogFile = NULL;
41
42/* Set the default log path to bebop storage */
43#ifndef LOGGER_CONTROL_EFFECTIVENESS_FILE_PATH
44#define LOGGER_CONTROL_EFFECTIVENESS_FILE_PATH /data/ftp/internal_000/control_eff
45#endif
46
47#endif
48
49// define parameters logged by default
50
51#ifndef LOGGER_CONTROL_EFFECTIVENESS_COMMANDS
52#define LOGGER_CONTROL_EFFECTIVENESS_COMMANDS TRUE
53#endif
54
55#ifndef LOGGER_CONTROL_EFFECTIVENESS_ACTUATORS
56#define LOGGER_CONTROL_EFFECTIVENESS_ACTUATORS FALSE
57#endif
58
59#ifndef LOGGER_CONTROL_EFFECTIVENESS_POS
60#define LOGGER_CONTROL_EFFECTIVENESS_POS FALSE
61#endif
62
63#ifndef LOGGER_CONTROL_EFFECTIVENESS_SPEED
64#define LOGGER_CONTROL_EFFECTIVENESS_SPEED FALSE
65#endif
66
67#ifndef LOGGER_CONTROL_EFFECTIVENESS_AIRSPEED
68#define LOGGER_CONTROL_EFFECTIVENESS_AIRSPEED FALSE
69#endif
70
71#ifndef LOGGER_CONTROL_EFFECTIVENESS_RPM
72#define LOGGER_CONTROL_EFFECTIVENESS_RPM FALSE
73#endif
74
75// extra includes
76
77#if LOGGER_CONTROL_EFFECTIVENESS_COMMANDS
79#endif
80
81#if LOGGER_CONTROL_EFFECTIVENESS_ACTUATORS
83#endif
84
85#if LOGGER_CONTROL_EFFECTIVENESS_RPM
87#include "modules/core/abi.h"
88static abi_event rpm_feedback_ev;
89static int32_t act_rpm[ACTUATORS_NB];
90
91static void rpm_feedback_cb(uint8_t sender_id UNUSED, struct act_feedback_t *feedback, uint8_t num_act)
92{
93 for (int i = 0; i < num_act; i++) {
94 if (feedback[i].set.rpm && feedback[i].idx < ACTUATORS_NB) {
95 act_rpm[feedback[i].idx] = feedback[i].rpm;
96 }
97 }
98}
99#endif
100
103{
104#if LOGGER_CONTROL_EFFECTIVENESS_RPM
105 AbiBindMsgACT_FEEDBACK(ABI_BROADCAST, &rpm_feedback_ev, rpm_feedback_cb);
106#endif
107}
108
111{
113
115 LogWrite(pprzLogFile, "time,gyro_p,gyro_q,gyro_r,ax,ay,az");
116#if LOGGER_CONTROL_EFFECTIVENESS_COMMANDS
117 for (unsigned int i = 0; i < COMMANDS_NB; i++) {
118 LogWrite(pprzLogFile, ",cmd_%d", i);
119 }
120#endif
121#if LOGGER_CONTROL_EFFECTIVENESS_ACTUATORS
122 for (unsigned int i = 0; i < ACTUATORS_NB; i++) {
123 LogWrite(pprzLogFile, ",act_%d", i);
124 }
125#endif
126#if LOGGER_CONTROL_EFFECTIVENESS_POS
127 LogWrite(pprzLogFile, ",pos_x,pos_y,pos_z");
128#endif
129#if LOGGER_CONTROL_EFFECTIVENESS_SPEED
130 LogWrite(pprzLogFile, ",speed_x,speed_y,speed_z");
131#endif
132#if LOGGER_CONTROL_EFFECTIVENESS_AIRSPEED
133 LogWrite(pprzLogFile, ",eas");
134#endif
135#if LOGGER_CONTROL_EFFECTIVENESS_RPM
136 for (unsigned int i = 0; i < ACTUATORS_NB; i++) {
137 LogWrite(pprzLogFile, ",rpm_%d", i);
138 }
139#endif
140 LogWrite(pprzLogFile,"\n");
141 }
142}
143
150
153{
155 return;
156 }
157
158 struct Int32Rates *rates = stateGetBodyRates_i();
159 struct Int32Vect3 *accel_body = stateGetAccelBody_i();
160
161 // log time, rate and accel
164 rates->p,
165 rates->q,
166 rates->r,
167 accel_body->x,
168 accel_body->y,
169 accel_body->z);
170
171 // log commands
172#if LOGGER_CONTROL_EFFECTIVENESS_COMMANDS
173 for (unsigned int i = 0; i < COMMANDS_NB; i++) {
174 LogWrite(pprzLogFile, ",%d", commands[i]);
175 }
176#endif
177
178 // log actuators
179#if LOGGER_CONTROL_EFFECTIVENESS_ACTUATORS
180 for (unsigned int i = 0; i < ACTUATORS_NB; i++) {
181 LogWrite(pprzLogFile, ",%d", actuators[i].pprz_val);
182 }
183#endif
184
185 // log position
186#if LOGGER_CONTROL_EFFECTIVENESS_POS
187 struct EnuCoor_i *pos = stateGetPositionEnu_i();
188 LogWrite(pprzLogFile, LogFormatVect3, pos->x, pos->y, pos->z);
189#endif
190
191 // log speed
192#if LOGGER_CONTROL_EFFECTIVENESS_SPEED
193 struct EnuCoor_i *speed = stateGetSpeedEnu_i();
194 LogWrite(pprzLogFile, LogFormatVect3, speed->x, speed->y, speed->z);
195#endif
196
197 // log airspeed
198#if LOGGER_CONTROL_EFFECTIVENESS_AIRSPEED
200#endif
201
202 // log rpm
203#if LOGGER_CONTROL_EFFECTIVENESS_RPM
204 for (unsigned int i = 0; i < ACTUATORS_NB; i++) {
205 LogWrite(pprzLogFile, LogFormatI32, act_rpm[i]);
206 }
207#endif
208 // end line
209 LogWrite(pprzLogFile,"\n");
210}
211
Main include for ABI (AirBorneInterface).
struct abi_struct abi_event
Definition abi_common.h:101
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:80
#define UNUSED(x)
Hardware independent code for commands handling.
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
angular rates
int32_t y
North.
int32_t z
Up.
int32_t x
East.
vector in East North Up coordinates
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition state.h:814
static struct Int32Rates * stateGetBodyRates_i(void)
Get vehicle body angular rate (int).
Definition state.h:1383
static struct Int32Vect3 * stateGetAccelBody_i(void)
Get acceleration in Body coordinates (int).
Definition state.h:1105
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
Definition state.h:1024
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition state.h:1615
void logger_control_effectiveness_periodic(void)
Log the values to file.
#define LogFormatI32
#define LOGGER_CONTROL_EFFECTIVENESS_FILE_PATH
void logger_control_effectiveness_init(void)
Init module.
void logger_control_effectiveness_start(void)
Write the log header line according to the enabled parts.
#define LogFormatHeader
static FILE * pprzLogFile
void logger_control_effectiveness_stop(void)
#define LogFormatVect3
Log data required to compute control effectiveness.
Generic definitions and tools for logging on ChibiOS or Linux.
#define LogOpen(_file, _path, _name)
#define LogFileIsOpen(_file)
#define LogWrite
#define LogClose(_file)
Hardware independent API for actuators (servos, motor controllers).
int32_t rpm
RPM.
Definition actuators.h:54
uint8_t idx
General index of the actuators (generated in airframe.h).
Definition actuators.h:45
static const ShellCommand commands[]
Definition shell_arch.c:77
API to get/set the generic vehicle states.
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition sys_time.h:241
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.