#!/bin/sh
# L2 Launch 
# BPMS -> FCOM
# Magnets -> ChannelAccess

caput FBCK:FB01:TR04:STATE 0

# 10 Hz, pockcel_perm
caput -a FBCK:FB01:TR04:POI1 21 0 0 0 8 0 0 0 32 0 0 55 0 0 0 0 0 0 0 0 0 0

# 10 Hz
#caput -a FBCK:FB01:TR04:POI1 21 0 0 0 0 0 0 0 32 0 0 55 0 0 0 0 0 0 0 0 0 0

# F matrix
caput -a FBCK:FB01:TR04:FMATRIX 50 1 0 0 0 3 0.4691 10.9833 0 0 3 0.43484 29.1592 0 0 3 0.016252 20.1972 0 0 3 0 0 1 0 3 0 0 1.3011 10.9832 3 0 0 0.4361 10.5238 3 0 0 0.094168 21.325 3

# G matrix
caput -a FBCK:FB01:TR04:GMATRIX 16 -4.0911 4.844 0 0 -0.13525 -0.058093 0 0 0 0 -5.6151 2.8454 0 0 -0.1003 -0.12712

# Dispersion
caput -a FBCK:FB01:TR04:MEASDSPR 8 1.359 -8.495 -361.6629 -17.534 1.359 -8.495 -361.6629 -17.534

# Loop configs
caput FBCK:FB01:TR04:NAME L2
caput FBCK:FB01:TR04:INSTALLED 1
caput FBCK:FB01:TR04:TOTALPOI 1
caput FBCK:FB01:TR04:ITERATEFUNC TrajectoryFit

# Measurements
caput FBCK:FB01:TR04:M1DEVNAME BPMS:LI21:301:X
caput FBCK:FB01:TR04:M1USED 0
caput FBCK:FB01:TR04:M1CAMODE 0

caput FBCK:FB01:TR04:M2DEVNAME BPMS:LI21:401:X
caput FBCK:FB01:TR04:M2USED 0
caput FBCK:FB01:TR04:M2CAMODE 0

caput FBCK:FB01:TR04:M3DEVNAME BPMS:LI21:501:X
caput FBCK:FB01:TR04:M3USED 0
caput FBCK:FB01:TR04:M3CAMODE 0

caput FBCK:FB01:TR04:M4DEVNAME BPMS:LI21:601:X
caput FBCK:FB01:TR04:M4USED 1
caput FBCK:FB01:TR04:M4CAMODE 0

caput FBCK:FB01:TR04:M5DEVNAME BPMS:LI21:701:X
caput FBCK:FB01:TR04:M5USED 1
caput FBCK:FB01:TR04:M5CAMODE 0

caput FBCK:FB01:TR04:M6DEVNAME BPMS:LI21:801:X
caput FBCK:FB01:TR04:M6USED 1
caput FBCK:FB01:TR04:M6CAMODE 0

caput FBCK:FB01:TR04:M7DEVNAME BPMS:LI21:901:X
caput FBCK:FB01:TR04:M7USED 1
caput FBCK:FB01:TR04:M7CAMODE 0

caput FBCK:FB01:TR04:M8DEVNAME BPMS:LI21:301:Y
caput FBCK:FB01:TR04:M8USED 0
caput FBCK:FB01:TR04:M8CAMODE 0

caput FBCK:FB01:TR04:M9DEVNAME BPMS:LI21:401:Y
caput FBCK:FB01:TR04:M9USED 0
caput FBCK:FB01:TR04:M9CAMODE 0

caput FBCK:FB01:TR04:M10DEVNAME BPMS:LI21:501:Y
caput FBCK:FB01:TR04:M10USED 0
caput FBCK:FB01:TR04:M10CAMODE 0

caput FBCK:FB01:TR04:M11DEVNAME BPMS:LI21:601:Y
caput FBCK:FB01:TR04:M11USED 1
caput FBCK:FB01:TR04:M11CAMODE 0

caput FBCK:FB01:TR04:M12DEVNAME BPMS:LI21:701:Y
caput FBCK:FB01:TR04:M12USED 1
caput FBCK:FB01:TR04:M12CAMODE 0

caput FBCK:FB01:TR04:M13DEVNAME BPMS:LI21:801:Y
caput FBCK:FB01:TR04:M13USED 1
caput FBCK:FB01:TR04:M13CAMODE 0

caput FBCK:FB01:TR04:M14DEVNAME BPMS:LI21:901:Y
caput FBCK:FB01:TR04:M14USED 1
caput FBCK:FB01:TR04:M14CAMODE 0

# Reference orbit
caput -a FBCK:FB01:TR04:REFORBIT 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0

# States
caput FBCK:FB01:TR04:S1NAME X.Position
caput FBCK:FB01:TR04:S1USED 1

caput FBCK:FB01:TR04:S2NAME X.Angle
caput FBCK:FB01:TR04:S2USED 1

caput FBCK:FB01:TR04:S3NAME Y.Position
caput FBCK:FB01:TR04:S3USED 1

caput FBCK:FB01:TR04:S4NAME Y.Angle
caput FBCK:FB01:TR04:S4USED 1

# Actuators
caput FBCK:FB01:TR04:A1DEVNAME XCOR:LI21:275:BCTRL
caput FBCK:FB01:TR04:A1USED 1
caput FBCK:FB01:TR04:A1CAMODE 1

caput FBCK:FB01:TR04:A2DEVNAME XCOR:LI21:302:BCTRL
caput FBCK:FB01:TR04:A2USED 1
caput FBCK:FB01:TR04:A2CAMODE 1

caput FBCK:FB01:TR04:A3DEVNAME YCOR:LI21:276:BCTRL
caput FBCK:FB01:TR04:A3USED 1
caput FBCK:FB01:TR04:A3CAMODE 1

caput FBCK:FB01:TR04:A4DEVNAME YCOR:LI21:303:BCTRL
caput FBCK:FB01:TR04:A4USED 1
caput FBCK:FB01:TR04:A4CAMODE 1

# Energy
caput -a FBCK:FB01:TR04:ACTENERGY 4 0.22 0.22 0.22 0.22

caput -a FBCK:FB01:TR04:REFORBIT 4 0.0016172 0.00014936 0.0012754 0.0028647


# Must set these up in order to have the config app work
caput FBCK:FB01:TR04:MEASNUM 14
caput FBCK:FB01:TR04:ACTNUM 4
caput FBCK:FB01:TR04:STATENUM 4
caput FBCK:FB01:TR04:PGAIN 0.1

# Enable loop
caput FBCK:FB01:TR04:INSTALLED 1
####caput FBCK:FB01:TR04:STATE 1
