Skip to content

File syn_autotune.c

FileList > control > syn_autotune.c

Go to the source code of this file

  • #include "../port/syn_port_system.h"
  • #include "../util/syn_assert.h"
  • #include "syn_autotune.h"
  • #include <string.h>
  • #include <stdio.h>

Public Functions

Type Name
void syn_autotune_abort (SYN_AutoTune * at)
Abort the auto-tune and stop the motor immediately.
void syn_autotune_apply (SYN_AutoTune * at)
Apply computed gains to the motor controller.
void syn_autotune_calc_relay_gains (int32_t Ku, uint32_t Tu_ms, SYN_AutoTune_Method method, uint16_t multiplier_pct, int32_t * kp, int32_t * ki, int32_t * kd)
Calculate Ziegler-Nichols / Tyreus-Luyben PID gains from ultimate gain (Ku) and period (Tu_ms).
SYN_Status syn_autotune_init (SYN_AutoTune * at, SYN_MotorCtrl * ctrl, const SYN_AutoTune_Config * cfg)
Initialize the auto-tuner.
SYN_Status syn_autotune_start (SYN_AutoTune * at, SYN_MotorCtrl * ctrl, const SYN_AutoTune_Limits * limits, SYN_AutoTune_Flags flags, uint16_t gain_multiplier)
Start a fully automatic tune sequence.
SYN_AutoTune_State syn_autotune_update (SYN_AutoTune * at)
Update the auto-tuner — call from main loop.

Public Static Functions

Type Name
void apply_raw_output (SYN_AutoTune * at, int32_t output)
void emergency_stop (SYN_AutoTune * at, SYN_AutoTune_AbortReason reason)
int32_t ramp_output (SYN_AutoTune * at, int32_t target, uint32_t elapsed)
bool safety_ok (SYN_AutoTune * at, int32_t pos, int32_t velocity)
void write_log (SYN_AutoTune * at)

Public Functions Documentation

function syn_autotune_abort

Abort the auto-tune and stop the motor immediately.

void syn_autotune_abort (
    SYN_AutoTune * at
) 

Parameters:

  • at Auto-tuner instance.

function syn_autotune_apply

Apply computed gains to the motor controller.

void syn_autotune_apply (
    SYN_AutoTune * at
) 

Copies ff_kv, ff_scale, and PID gains into the motor controller. Only valid when state == DONE.

Parameters:

  • at Auto-tuner instance.

function syn_autotune_calc_relay_gains

Calculate Ziegler-Nichols / Tyreus-Luyben PID gains from ultimate gain (Ku) and period (Tu_ms).

void syn_autotune_calc_relay_gains (
    int32_t Ku,
    uint32_t Tu_ms,
    SYN_AutoTune_Method method,
    uint16_t multiplier_pct,
    int32_t * kp,
    int32_t * ki,
    int32_t * kd
) 

Parameters:

  • Ku Ultimate gain (scaled by pid_scale).
  • Tu_ms Ultimate period in milliseconds.
  • method Tuning rule (Ziegler-Nichols, Tyreus-Luyben, No-Overshoot).
  • multiplier_pct Gain safety multiplier percentage (1-200, e.g. 80 for 80%).
  • kp Output proportional gain.
  • ki Output integral gain.
  • kd Output derivative gain.

function syn_autotune_init

Initialize the auto-tuner.

SYN_Status syn_autotune_init (
    SYN_AutoTune * at,
    SYN_MotorCtrl * ctrl,
    const SYN_AutoTune_Config * cfg
) 

Parameters:

  • at Auto-tuner instance.
  • ctrl Motor controller to tune (tuner takes control while active).
  • cfg Configuration. position_limit MUST be set.

Returns:

SYN_OK, or SYN_ERROR if position_limit is 0.


function syn_autotune_start

Start a fully automatic tune sequence.

SYN_Status syn_autotune_start (
    SYN_AutoTune * at,
    SYN_MotorCtrl * ctrl,
    const SYN_AutoTune_Limits * limits,
    SYN_AutoTune_Flags flags,
    uint16_t gain_multiplier
) 

Runs probe → FF identification → braking → relay PID tune → braking as a single self-sequencing state machine. The user only provides physical constraints.

Parameters:

  • at Auto-tuner instance.
  • ctrl Motor controller to tune.
  • limits Physical constraints (track limits, max velocity).
  • flags Feature flags (e.g., SYN_ATUNE_FLAG_ALL).
  • gain_multiplier Safety margin for PID gains (percentage, e.g., 80).

Returns:

SYN_OK on success, or error code.


function syn_autotune_update

Update the auto-tuner — call from main loop.

SYN_AutoTune_State syn_autotune_update (
    SYN_AutoTune * at
) 

Parameters:

  • at Auto-tuner instance.

Returns:

Current state. When DONE, results are in syn_autotune_result().


Public Static Functions Documentation

function apply_raw_output

static void apply_raw_output (
    SYN_AutoTune * at,
    int32_t output
) 

function emergency_stop

static void emergency_stop (
    SYN_AutoTune * at,
    SYN_AutoTune_AbortReason reason
) 

function ramp_output

static int32_t ramp_output (
    SYN_AutoTune * at,
    int32_t target,
    uint32_t elapsed
) 

Ramp output from 0 toward target over ramp_ms. Returns current output.


function safety_ok

static bool safety_ok (
    SYN_AutoTune * at,
    int32_t pos,
    int32_t velocity
) 

Check all safety conditions. Returns true if safe.


function write_log

static void write_log (
    SYN_AutoTune * at
) 


The documentation for this class was generated from the following file src/syntropic/control/syn_autotune.c