deviceDesc = MA11 cryomagnet for SANS

defineTemperature tt
device stick_menu "ma11 ma11t hvolt dil2 dil3 dil4 coil"

makenv tt -driver [lsdriver] {
  lsc_sensor tm B -sensor x14667 -sensorname VTI
  lsc_sensor ts C -sensorname sample
  lsc_sensor tm_pt A -sensor pt-100 -sensorname VTI_pt -color hidden
  lsc_sensor ts_2 D -sensor code -sensorname sample2
#  lsc_sensor ts_2 D -sensor x63166 -sensorname sample2 -color hidden
  lsc_loop set -loop 1 -channel B -maxheater 80W -resist 40Ohm -color green
  if {[lsdriver] eq "336_lsc"} {
    lsc_loop setsamp -loop 2 -channel C -maxheater 62.5W -resist 40Ohm -color dark_green -loopname sample
  }
}
tt set/limit 310

makeCCU4 ma11 nv he_ilm
hupdate /nv/set 1.5
makeN2Fill ccu4ilm {
  ln2fill lowlevel 30
  ln2fill highlevel 95
  ln2fill minfillminutes 8
  ln2fill maxfillminutes 40
  ln2fill minholdhours 24
  ln2fill maxholdhours 96
#  appendVars ln2fill.smooth/%/N2smooth/13
}

catch {
  hefill minfillminutes 20
  hefill maxfillminutes 60
}

makeIlm -channels 2 -port ma11-ts:3001
makeIps -limit 11 -startRamp 0.5 -port ma11-ts:3002
catch {
  mf limit 9.9
}

# exchanged td and ta, tc and tb, but kept the labels in order (M.Z. 27.8.2015)
# NO, we can not do that! the name (ta ... td) in mom matters! (M.Z. 10.11.2015)

makenv tcoil -driver mom -port ma11-ts:3003 {
  mom_sensor td -label OnLambda    -curve c_ab -adjust {239.4 300. 244.4 77.4 1238 4.22 5130 2.2}
  mom_sensor tc -label AboveLambda -curve c_ab -adjust {235.6 300. 240.5 77.4 1208 4.22 5020 2.2}
  mom_sensor tb -label Coil1       -curve c_ab -adjust {236.2 300. 240.7 77.4 1419 4.22 5936 2.2}
  mom_sensor ta -label Coil2       -curve c_ab -adjust {235.9 300. 237.8 77.4 1008 4.22 3383 2.2}
}

makenv table -driver table /tt/tm {
  # for some reason, we had int 5 and prop 5 at base - which is not nice
  "tt set/prop" "10:50 30:50 50:200 100:500 300:500"
  "tt set/integ" "10:20 50:20 100:1 300:0.5"
  "tt dblctrl/int2" "10:30 50:100 300:600"
  "tt dblctrl/prop_up" "20:0.1 100:0.4"
  "tt dblctrl/prop_lo" "20:0.1 50:0.8"
}

#makenv lpr -driver nv_ccu -port ma11-ts:3004 "lambda point refrigerator"
makeLPR lpr lnv ma11-ts:3004 "/tcoil/tc /tcoil/ta /tcoil/tb /tcoil/td"

# outmax has to lower than outmin because a high value means cooling
lpr outmax 12
lpr outmin 35
lpr prop 1
lpr int 300

makenv lambdawatch -driver lambdawatch 9.9 11 2.5 tcoil/ta tcoil/tb
GraphAdd lambdawatch K_2 lim

setstickrot ma11-ts:3005

default ignore_msg lpr
