39 #include "physical_constants.h"
40 #include "flightstatus.h"
41 #include "modulesettings.h"
42 #include "manualcontrolcommand.h"
43 #include "manualcontrolsettings.h"
45 #include "actuatordesired.h"
46 #include "stabilizationdesired.h"
47 #include "stabilizationsettings.h"
48 #include "systemident.h"
51 #include "systemsettings.h"
56 #define AUTOTUNE_STATE_PERIOD_MS 100
58 #ifndef AUTOTUNE_AVERAGING_DECIMATION
59 #define AUTOTUNE_AVERAGING_DECIMATION 1
65 #define ATFLASH_MAGIC 0x656e755480008041
97 void *ctx,
void *obj,
int len);
105 if (SystemIdentInitialize() == -1) {
111 #ifdef MODULE_Autotune_BUILTIN
114 uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM];
115 ModuleSettingsAdminStateGet(module_state);
116 if (module_state[MODULESETTINGS_ADMINSTATE_AUTOTUNE] == MODULESETTINGS_ADMINSTATE_ENABLED)
135 .
obj = SystemIdentHandle(),
148 void *ctx,
void *obj,
int len) {
149 (void) ev; (void) ctx;
151 static bool first_cycle =
false;
154 ActuatorDesiredGet(&actuators);
159 if (actuators.SystemIdentCycle == 0xffff) {
172 if (actuators.SystemIdentCycle == 0x0000) {
179 first_cycle = ! first_cycle;
189 avg_point->
y[0] += g.x;
190 avg_point->
y[1] += g.y;
191 avg_point->
y[2] += g.z;
193 avg_point->
u[0] += actuators.Roll;
194 avg_point->
u[1] += actuators.Pitch;
195 avg_point->
u[2] += actuators.Yaw;
203 SystemIdentData system_ident;
205 system_ident.NewTune = new_tune;
206 system_ident.NumAfPredicts = predicts;
208 system_ident.HoverThrottle = hover_throttle;
210 SystemIdentSet(&system_ident);
247 offset +=
sizeof(hdr);
263 void *ctx,
void *obj,
int len)
265 (void) ev; (void) ctx; (void) obj; (void) len;
295 FlightStatusArmedGet(&armed);
298 if (armed == FLIGHTSTATUS_ARMED_DISARMED) {
int32_t PIOS_FLASH_find_partition_id(enum pios_flash_partition_labels label, uintptr_t *partition_id)
int32_t PIOS_FLASH_erase_partition(uintptr_t partition_id)
uint16_t ident_wiggle_points
Main PiOS header to include all the compiled in PiOS options.
#define AUTOTUNE_AVERAGING_DECIMATION
static int autotune_save_averaging()
void PIOS_Modules_Enable(enum pios_modules module)
void * PIOS_malloc(size_t size)
int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId)
static volatile uint32_t throttle_accumulator
static void UpdateSystemIdent(uint32_t predicts, float hover_throttle, bool new_tune)
static bool module_enabled
uint32_t PIOS_SENSORS_GetSampleRate(enum pios_sensor_type type)
Get the sample rate of a sensor (Hz)
int32_t EventPeriodicCallbackCreate(UAVObjEvent *ev, UAVObjEventCallback cb, uint16_t periodMs)
int32_t PIOS_FLASH_write_data(uintptr_t partition_id, uint32_t offset, const uint8_t *data, uint16_t len)
int32_t PIOS_FLASH_end_transaction(uintptr_t partition_id)
#define MODULE_INITCALL(ifn, sfn)
int32_t AutotuneStart(void)
struct @16 actuators[FPPROTO_MAX_SERVOS]
Event dispatcher, distributes object events as callbacks. Alternative to using tasks and queues...
static volatile uint32_t update_counter
static volatile bool tune_running
Includes PiOS and core architecture components.
static uint16_t decim_wiggle_points
static void at_new_actuators(const UAVObjEvent *ev, void *ctx, void *obj, int len)
static void autotune_step(const UAVObjEvent *ev, void *ctx, void *obj, int len)
int32_t PIOS_FLASH_start_transaction(uintptr_t partition_id)
#define AUTOTUNE_STATE_PERIOD_MS
static enum autotune_state state
int32_t AutotuneInitialize(void)
static struct at_measurement * at_averages