MAOS
Multithreaded Adaptive Optics Simulator
servo.h File Reference

Data Structures

struct  servo_t
 
struct  sho_t
 
union  servo_t.__unnamed__
 
union  servo_t.__unnamed__
 

Functions

dcellservo_optim (real dt, long dtrat, real al, real pmargin, real f0, real zeta, int servo_type, const dmat *psdin, const dmat *sigma2n)
 
real servo_optim_margin (real dt, long dtrat, real al, real pmargin, real f0, real zeta)
 
dmatservo_cl2ol (const dmat *psdcl, real dt, long dtrat, real al, real gain, real sigma2n)
 
real servo_residual (real *noise_amp, const dmat *psdin, real dt, long dtrat, real al, const dmat *gain, int servo_type)
 
servo_tservo_new (anyarray merr, const dmat *ap, real al, real dt, const dmat *ep)
 
servo_tservo_new_scalar (anyarray merr, real ap, real al, real dt, real ep)
 
servo_tservo_new_sho (anyarray merr, const dmat *ap, real al, real dt, const dmat *ep, real f0, real zeta)
 
int servo_filter (servo_t *st, const anyarray merr)
 
void servo_add (servo_t *st, const anyarray madj, real alpha)
 
void servo_output (const servo_t *st, panyarray out)
 
dmatservo_test (dmat *mideal, real dt, int dtrat, dmat *sigma2n, dmat *gain)
 
void servo_reset (servo_t *st)
 
void servo_free (servo_t *st)
 
sho_tsho_new (real f0, real zeta)
 
void sho_free (sho_t *sho)
 
void sho_step (panyarray xout, sho_t *sho, anyarray xi, real dt, int average)
 
void sho_reset (sho_t *sho)
 
dmatsho_filter (const dmat *xi, real dt, real f0, real zeta, int average)
 

Detailed Description

Routines for servo optimization, filtering, etc.


Data Structure Documentation

◆ servo_t

struct servo_t

Struct for servo filtering

+ Collaboration diagram for servo_t:
Data Fields
union servo_t __unnamed__
union servo_t __unnamed__
cell * mlead

lead filter temporary storage

cell * merrlast

recorded errro signal from last step

cell * merrhist

Keep a short history of merr

int initialized

is this data initialized

int alint

Integral part of latency

real alfrac

Fractional latency

dmat * ap
dmat * ep
real dt
sho_t * sho

◆ sho_t

struct sho_t

struct for state space modeling of a second order harnomic oscillator with resonance frequency of f0 and damping ratio of zeta.

+ Collaboration diagram for sho_t:
Data Fields
real dt
real c1
real c2
cell * dx
cell * x
cell * ddx
cell * ytmp

◆ servo_t.__unnamed__

union servo_t.__unnamed__
+ Collaboration diagram for servo_t.__unnamed__:
Data Fields
cell * mint

second integrator. It is array to accomodate multiple ap's

dccell * mintc
dcell * mintd

◆ servo_t.__unnamed__

union servo_t.__unnamed__
+ Collaboration diagram for servo_t.__unnamed__:
Data Fields
cell * mpreint

first integrator or other value.

dcell * mpreintc
dmat * mpreintd

Function Documentation

◆ servo_optim()

dcell* servo_optim ( real  dt,
long  dtrat,
real  al,
real  pmargin,
real  f0,
real  zeta,
int  servo_type,
const dmat psdin,
const dmat sigma2n 
)

Optimize the servo gains by balancing errors due to noise and signal propagation.

Written: 2010-06-11

Tested OK: 2010-06-11

2011-01-17: The optimization process is quite slow, but the result is only dependent on the sigma2n and fs. psdin does not change during the simulation. Built a lookup table in skyc using various sigma2n and interpolate to get ress, resn, and gain.

2012-03-28: Cleaned up this routine. groupped similar calculations together. Change g2=a from g=sqrt(a)

2013-06-27: The maximum gain should not be limited to 0.5 beause it is later scaled by sqrt(a);

sigma2n is a dmat array of all wanted sigma2n. Returns a zfarray of a dmat of [g0, a, T, res_sig, res_n]

The upper end of frequency must be nyquist freq so that noise transfer can be computed. But we need to capture the turbulence PSD beyond nyquist freq, which are uncorrectable.

2022-03-04: added SHO response parameter.

◆ servo_optim_margin()

real servo_optim_margin ( real  dt,
long  dtrat,
real  al,
real  pmargin,
real  f0,
real  zeta 
)

Optimize integrator control with optional SHO response (output) to have correct phase margin (pi/4) when abs(Hol)==1.

◆ servo_cl2ol()

dmat* servo_cl2ol ( const dmat psdcl,
real  dt,
long  dtrat,
real  al,
real  gain,
real  sigma2n 
)

Convert Closed loop residual PSD back to OL psd using rejection transfer function: PSD_OL=PSD_CL/Hrej-sigma2n/F_nyquist; Only implemented for integrator.

◆ servo_residual()

real servo_residual ( real *  noise_amp,
const dmat psdin,
real  dt,
long  dtrat,
real  al,
const dmat gain,
int  servo_type 
)

Compute the residual error after servo rejection of a type II servo given the gain.

Written: 2010-06-11

Tested OK: 2010-06-11

◆ servo_new()

servo_t* servo_new ( anyarray  merr,
const dmat ap,
real  al,
real  dt,
const dmat ep 
)

Initialize servo_t. al is additional latency

◆ servo_new_scalar()

servo_t* servo_new_scalar ( anyarray  merr,
real  ap,
real  al,
real  dt,
real  ep 
)

Initialize servo_t with scalar ap and ep

◆ servo_new_sho()

servo_t* servo_new_sho ( anyarray  merr,
const dmat ap,
real  al,
real  dt,
const dmat ep,
real  f0,
real  zeta 
)

Initialize servo_t with an sho

◆ servo_filter()

int servo_filter ( servo_t st,
const anyarray  _merr 
)

Applies type I or type II filter based on number of entries in gain.

◆ servo_add()

void servo_add ( servo_t st,
const anyarray  madj,
real  alpha 
)

Adjust integrator content without shift.

◆ servo_output()

void servo_output ( const servo_t st,
panyarray  out_ 
)

Create servo output. It handles st->alfrac. and outputs the averaged position over the integration period.

◆ servo_test()

dmat* servo_test ( dmat input,
real  dt,
int  dtrat,
dmat sigma2n,
dmat gain 
)

test type I/II filter with ideal measurement to make sure it is implemented correctly.

◆ servo_reset()

void servo_reset ( servo_t st)

reset the data to 0.

◆ servo_free()

void servo_free ( servo_t st)

Free servo_t struct

◆ sho_new()

sho_t* sho_new ( real  f0,
real  zeta 
)

Second harmonic oscillator. Initialization. Equation is is d^x/dt^2+c1*dx/dt+c2*x=c2*xi State space model is |x'|' | -c1 -c2 | |x'| |xi| |x | = | 1 0 | | x| + c2 |0 | where x' is dx/dt and written as dx in struct. we use c2*xi so that it is in the same unit and scale as x.

Parameters
f0Resonance frequency
zetaDamping

◆ sho_step()

void sho_step ( panyarray  xout_,
sho_t sho,
anyarray  xi_,
real  dt,
int  avg 
)

Second harmonic oscillator state space update. xi is driving position.
Second harmonic oscillator state space update. xi is driving position. Update the position after time dt. Also compute the average position between 0 and dt (for WFS integration) if avg is set.

sho->x +=dt*sho->dx;//update position ddx=sho->dx*(-sho->c1)+sho->x*(-sho->c2)+xi;//update speed sho->dx+=dt*ddx; //update speed

◆ sho_reset()

void sho_reset ( sho_t sho)

Second harmonic oscillator. Reset.

◆ sho_filter()

dmat* sho_filter ( const dmat x,
real  dt,
real  f0,
real  zeta,
int  avg 
)

Second harmonic oscillator. Filter a time series for testing.

Parameters
xInput time series
dtInput time series sampling
f0Resonance frequency
zetaDamping
avgAverage or not