Text that was in readme and not used any more is stored here
============================================================


*** 14.12.2016 ***
==================

Parker stage
============

Using IDE
---------
1 detect current sensor direction
  Motor[1].PhaseOffset 683
  Motor[1].PwmSf 2154
2 current bias
  Motor[1].IaBias=0
  Motor[1].IbBias=0
3 Voltage six step
  Motor[1].PhaseOffset -683
  Motor[1].PwmSf -2154
  Motor[1].PhasePosSf=2048/(1*256*213333.3333)
4 Tune Current Loop (Mag=200, dur=50)
  Motor[1].IiGain 10.5
  Motor[1].IpfGain=0
  Motor[1].IpbGain=14.7
5 Current six step
  Motor[1].PhasePosSf=2048/(1*1*61440000.)
6 Phase ref search
  Motor[1].PhaseFindingDac=160.95
  Motor[1].PhaseFindingTime=50



Open Loop
---------
20mm = 1003994 enc_step
20mm = 1'000'000 enc_step  -> 20nm/enc step
1 pole= 600'000 enc_step -> 12mm


>>>>>>>>>> DONT FORGET <<<<<<<<<<<
$$$***
!common()

>>> open loop with encoder counts <<<
!encoder_sim(enc=1,tbl=1,mot=1)
!encoder_inc(enc=1,tbl=9,mot=9,encctrl=7,posSf=1./1)
!motor(mot=1,dirCur=400,contCur=500,peakCur=2400,timeAtPeak=1,IiGain=1,IpfGain=0,IpbGain=2,JogSpeed=1.,numPhase=3,invDir=True)
#1j/
#1,9hmz

#1j:2048 -> moves one pole= 650'000 enc_step =13mm (Electrical Pitch in MX80 doc)

512= 90deg -> check phase *

                              *      o      x                         *      o      x
                            *   *  o   o  x   x                     *   *  o   o  x   x
                          *      o*     xo      x                 *      o*     xo      x
                        *      o    * x    o      x             *      o    * x    o      x
                      *      o      x *      o      x         *      o      x *      o      x
*------o------x-----*------o------x-----*------o------x-----*------o------x-----*------o------x-----*------o------x
  *      o      x *      o      x         *      o      x *      o      x         *      o      x *      o      x
    *      o    * x    o      x             *      o    * x    o      x             *      o    * x    o      x
      *      o*     xo      x                 *      o*     xo      x                 *      o*     xo      x
        *   *  o   o  x   x                     *   *  o   o  x   x                     *   *  o   o  x   x
          *      o      x                         *      o      x                         *      o      x
0        512     1024       1536      2048

>>> scaling encoder etc to um <<<
!encoder_sim(enc=1,tbl=1,mot=1,posSf=12000./2048)
!encoder_inc(enc=1,tbl=9,mot=9,encctrl=7,posSf=12000./600000)
!motor(mot=1,dirCur=400,contCur=500,peakCur=2400,timeAtPeak=1,IiGain=1,IpfGain=0,IpbGain=2,JogSpeed=1.*12000./2048,numPhase=3,invDir=True)

JogSpeed=1.*12000./2048 6um/ms =6mm/s


>>> close the loop with inc-encoder <<<
servoSf  : motorusteps/userUnits

!encoder_sim(enc=1,tbl=9,mot=9,posSf=12000./2048)
!encoder_inc(enc=1,tbl=1,mot=1,encctrl=7,posSf=12000./600000)
!motor(mot=1,dirCur=400,contCur=500,peakCur=2400,timeAtPeak=1,IiGain=1,IpfGain=0,IpbGain=2,JogSpeed=6.,numPhase=3,invDir=True,servoSf=2048/12000.)

>>> close the loop with inc-encoder removing direct current<<<
$$$***
!common()
!encoder_sim(enc=1,tbl=9,mot=9,posSf=12000./2048)
!encoder_inc(enc=1,tbl=1,mot=1,encctrl=7,posSf=12000./600000)
!motor(mot=1,dirCur=0,contCur=500,peakCur=800,timeAtPeak=1,IiGain=1,IpfGain=0,IpbGain=2,JogSpeed=6.,numPhase=3,invDir=True,servoSf=2048/12000.)

Motors are not moving, because no current will be set due to some wrong parameters.
But the servoloop is running and gives output:
ServoOut set value from 0.5099 to -0.5099 (= MaxPosErr*Kp) when moving at different position
Motor[1].Servo.MaxPosErr=1000.0169
Motor[1].Servo.Kp=0.000512
1000.0169*0.000512=0.5120086528

Motor[1].Servo.Kp=0.0007
Motor[1].Servo.MaxPosErr=1000.0169
1000.0169*0.0007=0.70001183

Now some elements have to be reconfigured:
SlipGain,PwmSf,PhaseMode,PhaseCtrl,PhasePosSf


Motor[1].pPhaseEnc = PowerBrick[0].Chan[0].PhaseCapt.a  //is default
use configuration open loop with encoder counts
#1j/
Read PowerBrick[0].Chan[0].PhaseCapt 130559
move one pole (13mm)
Read PowerBrick[0].Chan[0].PhaseCapt 166599808
difference = 166599808-130559= 166469249
             166469249/256 = 650270 =650000incr = 13mm
1 commutation cycle=163537664 PhaseCapt = 2048 com_cycl_units
PhasePosSf= 2048./166469249 = 1.2303e-05 or precise: 2048/(256*650000)=1.23077e-05

servoSf  : motorusteps/userUnits

servoSf=2048/12000.,PhaseCtrl=4,SlipGain=0,PhasePosSf=1.23077e-05


*******************************
****** WORKS !!!!!!!!!!!! *****
** But positioning has very bad performance **
*******************************

// controlling speed/velocity on iqCmd and constant current(=torque) on idCmd
//precission +-1 step in steady state
$$$***
!common()
!encoder_inc(enc=1,tbl=1,mot=1,encctrl=7,posSf=12000./600000)
!motor(mot=1,dirCur=300,contCur=800,peakCur=2400,timeAtPeak=1,IiGain=1,IpfGain=0,IpbGain=2,JogSpeed=6.,numPhase=3,invDir=True,servoSf=2048/12000.)


// controlling torque(=current) on iqCmd and idCmd=0
//precission +-100 and more step in steady state
$$$***
!common()
!encoder_inc(enc=1,tbl=1,mot=1,encctrl=7,posSf=12000./600000)
!motor(mot=1,dirCur=0,contCur=800,peakCur=2400,timeAtPeak=1,IiGain=1,IpfGain=0,IpbGain=2,JogSpeed=6.,numPhase=3,invDir=True,servoSf=2048/12000.,PhaseCtrl=4,SlipGain=0,PhasePosSf=1.23077e-05,PhaseMode=0,PhaseFindingDac=200,PhaseFindingTime=22.586512)

#1out10
!!! HOLD BY HAND TO LIMIT THE SPEED !!!
 Motor[1].Servo.Kp=1
Motor[1].InPosBand=0
Motor[1].Servo.BreakPosErr=0
#1j/
#1j:1000
*******************************



-> Tadejs input: use simulated encoder for the phasing


Motor[1].Servo.BreakPosErr=0
Motor[3].Servo.Kp=2000

///Motor[3].Servo.BreakPosErr=0
//Motor[3].Servo.Kp=2000
//#3out5


Testing IDE with QBL test motor
===============================

>>> close the loop with inc-encoder removing direct current<<<

-> the current/speed must be set with that PWM-scale factor

Motor idx                   1             3
Motor[x].AdvGain            0.020479999   0
Motor[x].PhasePosSf         0             0.0160000000000000003
Motor[x].PhaseCtrl          6             4
Motor[x].PhaseMode          1             0
Motor[x].PwmSf              -15134.891    4309
Motor[x].SlipGain           0.25          0
Motor[x].PhaseFindingDac    0             95.976563
Motor[x].PhaseFindingTime   0             22.586512

>>> origin setup by ide+ tweaks <<<
!encoder_inc(enc=3,tbl=3,mot=3,encctrl=7,posSf=1./2000)
!motor_servo(mot=3,ctrl='ServoCtrl',Kp=4.0424199*2000, Kvfb=160.43646*2000,Kvff=160.43646*2000,Kaff=3184.5818*2000)
!motor(mot=3,numPhase=3,servo=None, homing=None,dirCur=0,contCur=1790,peakCur=5400,timeAtPeak=1,IiGain=1.0628819,IpfGain=0,IpbGain=6.5684085,AdvGain=0,FatalFeLimit=2000,WarnFeLimit=1000,InPosBand=0,PhasePosSf=0.016,PhaseCtrl=4,PhaseMode=0,PwmSf=4309,SlipGain=0,PhaseFindingDac=95.976563,PhaseFindingTime=22.586512)

AdvGain
PhasePosSf        0 does not work at all -> must be calculated correctly as below
PhaseCtrl         6 not working. must be 4 for phase feedback and 6 for direct microstepping
PhaseMode         0,1 both are working, should be 0 for 3 phase
PwmSf             0   2000  4309  -> the higher, the more torque on error
SlipGain          0.25  squeezing
PhaseFindingDac   0  no change
PhaseFindingTime  0  no change
$$$***
!common()
!encoder_inc(enc=3,tbl=3,mot=3,encctrl=7,posSf=1./2000)
!motor_servo(mot=3,ctrl='ServoCtrl',Kp=4.0424199*2000, Kvfb=160.43646*2000,Kvff=160.43646*2000,Kaff=3184.5818*2000)
!motor(mot=3,numPhase=3,servo=None, homing=None,dirCur=0,contCur=1790,peakCur=5400,timeAtPeak=1,IiGain=1.0628819,IpfGain=0,IpbGain=6.5684085,AdvGain=0,FatalFeLimit=2000,WarnFeLimit=1000,InPosBand=0,PhasePosSf=0.016,PhaseCtrl=6,PhaseMode=1,PwmSf=1000,SlipGain=0,PhaseFindingDac=0,PhaseFindingTime=0)
!sh sleep 1
#3j/
!sh sleep 10
#3j:100

#3out10 sets directly the Motor[3].ServoOut value , sets to 10% of Motor[x].MaxDac
Motor[3].MaxDac=4526.9282
 Out        ServoOut      iqCmd      IqVolts
#3out100 -> 4526.9                               set to 100 %of Motor[x].MaxDac
#3out50  -> 2263.46411     2263.4641
#3out10  -> 452.692822     452.69281

iqMeas=iqCmd if motor is blocked, when motor moves, iqCmd stays and iqMeas drops
PwmSf IqCmd iqMeas(when blocked)
Motor[3].PwmSf;Motor[3].IqCmd;Motor[3].IqMeas;Motor[3].IqVolts
PwmSf=500  IqCmd=2263.4641 IqMeas=232.44925 IqVolts=34406.398
PwmSf=1000 IqCmd=2263.4641 IqMeas=779.05316 IqVolts=34406.398
PwmSf=2000 IqCmd=2263.4641 IqMeas=1944.9929 IqVolts=34406.398
PwmSf=3000 IqCmd=2263.4641 IqMeas=2234.2734 IqVolts=34406.398


Motor[x].PhasePosSf scale factor to convert encoder position to phase position
Motor[3].pPhaseEnc=PowerBrick[0].Chan[2].PhaseCapt.a
Motor[3].PhaseEncLeftShift=0
Motor[3].PhaseEncRightShift=0
1 rev=2000*256 enc_steps (PowerBrick[0].Chan[2].PhaseCapt)

4 Pole magnet, 2000 enc_steps/rev
encoder configured to have 1 enc_step per revolution
PhasePosSf=0.016=1/62.5=32/2000= (4*2048)/(256*2000) = (numPoles*const)/(256*2000)
const=Power PMAC divides a commutation cycle into 2048 parts

Motor[3].PhasePos position of the phase: 0..2048 this does not change if the motor is blocked


>>>>>>find PhasePosSf <<<<<<<<<<<
$$$***
!common()
!encoder_sim(enc=3,tbl=3,mot=3)
!encoder_inc(enc=3,tbl=11,mot=11,encctrl=7,posSf=1./2000)
!motor(mot=3,numPhase=3, dirCur=500,contCur=1790,peakCur=2400,timeAtPeak=1,IiGain=1.0628819,IpfGain=0,IpbGain=6.5684085,AdvGain=0,FatalFeLimit=2000,WarnFeLimit=1000,InPosBand=0,PhasePosSf=0.0,PhaseCtrl=4,PhaseMode=0,SlipGain=0)

Do manually one revolution
feeling 4 pole changes -> 8 poles (locks on N-S S-N positions, moves on N-N S-S position)
Motor[3].pPhaseEnc -> Motor[3].pPhaseEnc=PowerBrick[0].Chan[2].PhaseCapt.a

PowerBrick[0].Chan[2].PhaseCapt after one revolution
1535488-1022464=513024=512000

Phase_step = change pole from N->S->N
1 Phase_step = 2048 Phase_uStep
512000 PhaseEnc_step == 4 pole changes = 4*2048 Phase_uStep 
PhasePosSf=Phase_uStep/PhaseEnc_step=4*2048/512000==0.016


!encoder_inc(enc=3,tbl=3,mot=3,encctrl=7,posSf=1./2000)
!motor(mot=3,numPhase=3, dirCur=0,contCur=1790,peakCur=2400,timeAtPeak=1,IiGain=1.0628819,IpfGain=0,IpbGain=6.5684085,AdvGain=0,FatalFeLimit=2000,WarnFeLimit=1000,InPosBand=0,servoSf=2000./1,PhasePosSf=0.016,PhaseCtrl=4,PhaseMode=0,PwmSf=4309,SlipGain=0,PhaseFindingDac=95.976563,PhaseFindingTime=22.586512)
Motor[3].Servo.BreakPosErr=0
Motor[3].Servo.Kp=2000
#3out5







#3j/


PowerBrick[0].AdcAmpCtrl      = $f00cfe00             $f00cfe00
PowerBrick[0].Chan[0].InCtrl  = $47                   $47
PowerBrick[0].Chan[0].OutCtrl = $f000001              $f000101
PowerBrick[1].AdcAmpCtrl      = $f00cfe00             $f00cfe00
Motor[1].Servo.Kp             = 4.0424199             4.0424199
Motor[1].Servo.Kvifb          = 0                     0
Motor[1].Servo.Kviff          = 0                     0
Motor[1].Servo.Kvfb           = 160.43646             40.951927
Motor[1].Servo.Kvff           = 160.43646             40.951927
Motor[1].Servo.Kafb           = 0                     0
Motor[1].Servo.Kaff           = 3184.5818             207.48897
Motor[1].Servo.Ki             = 2.6301687e-4          0.0010304153
Motor[1].Servo.Kfff           = 0                     0
Motor[1].PhasePosSf           = 0.0160000000000000003 1.59999999999999993e-5
Motor[1].IiGain               = 1.0628819             0.2278125
Motor[1].IpbGain              = 6.5684085             0.0099999998
Motor[1].MotorTa              = -10                   -10
Motor[1].MotorTs              = -50                   -50
Motor[1].I2tSet               = 1499.7477             418.92395
Motor[1].I2tTrip              = 18220758              2632459
Motor[1].JogOffset            = 0                     0
Motor[1].AdcMask              = $fffc0000             $fffc0000
Motor[1].PhaseOffset          = 683                   -683
Motor[1].Stime                = 0                     0
Motor[1].PwmSf                = 4309                  -2154
Motor[1].MaxDac               = 4524.3784             1675.6958
Motor[1].PhaseFindingDac      = 95.976563             0
Motor[1].PhaseFindingTime     = 22.586512             1
Motor[1].TraceSize            = 0                     0
Motor[1].Control[0]           = $14000100             $14000100
Motor[1].Control[1]           = $0                    $0
Node15[0].MasterNum           = 255                   255
Node15[1].MasterNum           = 255                   255
Node15[2].MasterNum           = 255                   255
Node15[3].MasterNum           = 255                   255




IDE Setup -> changed variables
------------------------------
*Command/Feedback(3)
Motor[3].pAbsPhasePos=0  // Encoder //12/9/2016 :8:51 AM - 129.129.144.138
Motor[3].AbsPhasePosFormat=0  // Encoder //12/9/2016 :8:51 AM - 129.129.144.138
Motor[3].AbsPhasePosSf=0  // Encoder //12/9/2016 :8:51 AM - 129.129.144.138
Motor[3].AbsPhasePosOffset=0  // Encoder //12/9/2016 :8:51 AM - 129.129.144.138
Motor[3].PhaseFindingTime=1  // Encoder //12/9/2016 :8:51 AM - 129.129.144.138
Motor[3].PhaseFindingDac=0  // Encoder //12/9/2016 :8:51 AM - 129.129.144.138

*Hardware Interface
Motor[3].pLimits=PowerBrick[0].Chan[2].Status.a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pEnc= EncTable[3].a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pEnc2= EncTable[3].a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].EncType= 5  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pDac=PowerBrick[0].Chan[2].Pwm[0].a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pAdc=PowerBrick[0].Chan[2].AdcAmp[0].a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pAmpEnable=PowerBrick[0].Chan[2].OutCtrl.a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].ServoCtrl = 1  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PhaseCtrl = 4  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Gate3[0].Chan[2].PackIndata = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Gate3[0].Chan[2].PackOutdata = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PhaseMode = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pPhaseEnc=PowerBrick[0].Chan[2].PhaseCapt.a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
BrickLV.Chan[2].TwoPhaseMode=0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PhaseSplineCtrl = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pSineTable = Sys.SineTable[0].a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pVoltSineTable = Sys.SineTable[0].a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PwmDbComp = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PwmDbI = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
PowerBrick[0].Chan[2].OutputMode = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PwmSf =7618.5  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].AmpEnableBit = 8  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].AmpFaultBit = 7  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].AmpFaultLevel = 1  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].pAmpFault=PowerBrick[0].Chan[2].Status.a  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].LimitBits = 9  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].DacShift=0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].AdcMask = $FFFC0000  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].ctrl=Sys.servoctrl  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].DtOverRotorTc = 0  // Hardware Interface //12/9/2016 0:8:53 AM - 129.129.144.138
Motor[3].IxCoupleGain = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].SlipGain = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].AdvGain = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].Stime = 0  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
Motor[3].PhaseOffset =-683  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138
BrickLV.Reset = 1  // Hardware Interface //12/9/2016 :8:53 AM - 129.129.144.138



*** 16.1.2017 ***
==================

Parker stage current step response
----------------------------------

Motor[2].IiGain=0
Motor[2].IpfGain=1
Motor[2].IpbGain=-1

Current step: Magnitude 4000 bits
Phasing 0
Dwell 10 ms

Motor 2 Phase pos at hard limit (towards kable)

> Motor[2].PhasePos;#2$
Motor[2].PhasePos=1317.26495427904138
Motor[2].PhasePos=1286.11002741653601
Motor[2].PhasePos=1310.62328616849777
Motor[2].PhasePos=1310.62328616849686
Motor[2].PhasePos=1307.26431089312473
Motor[2].PhasePos=1323.77420922660667
Motor[2].PhasePos=1323.77735999583911
Motor[2].PhasePos=1331.42989161901664
Motor[2].PhasePos=1332.17854273394619

Use Motor[2].PhasePos=1330
Use Motor[3].PhasePos=150 (or 1200???)

*** 19.1.2017 ***
==================

Friction force of Parker stage

X(top stage): 1N max 0.1N min.. depends on the magnetic poles
#3out20 -> Force 2N
#3out30 -> Force 3N (changes in torque at poles)
Weight: ca 250g


Y(lower stage): 1N max 0.1N min.. depends on the magnetic poles
#2out20 -> Force 2.5N iqCmd=402
#2out30 -> Force 3N   iqCmd=603  (changes in torque at poles)
Weight: ca 750g

*** 27.1.2017 ***
==================

Friction force of Parker stage: see blue logbook.
Calculate the current at a given force:

import numpy as np
import plt as matplotlib.pyplot

F=np.array([+300, +100, 0.,-50,-100,-150,-200,-250,-300])
i=np.array([+625, 214, 38.,-104,-207,-300,-400,-500,-600])

plt.plot(i,F,'.-')

average  Motor[3].iqMeas -610.949923065
average  Motor[3].iaMeas 432.573485303
average  Motor[3].ibMeas -699.459308138
-> icMeas 432.573485303-699.459308138=-266.885822835


Check cur_bits to current
-------------------------

Block motor 4
set current to 10%:    #4out10
Measure current with amp meter and ./move_record.py

Motor[4].PhasePos=313

gelb 293 mA
idCmd=0
average  Motor[4].iqMeas 452.897308732
average  Motor[4].iaMeas -274.830633873
average  Motor[4].ibMeas 523.056988602
               -> icMeas 248.226

rot 560 mA
average  Motor[4].iqMeas 452.719438794
average  Motor[4].iaMeas -264.325534893
average  Motor[4].ibMeas 523.057788442
               -> icMeas 258.73

schwarz 290mA
average  Motor[4].iqMeas 453.042713114
average  Motor[4].iaMeas -252.726254749
average  Motor[4].ibMeas 523.302539492
               -> icMeas 270.57

PhasePos=0    ia=-512 ib=260   ic=240
PhasePos=682  ia=250  ib=250   ic=500
PhasePos=1364 ia=320  ib=-500  ic=180

https://de.wikipedia.org/wiki/D/q-Transformation
ia=-sin(phi)*iq
ib=-sin(phi-120deg)*iq
ic=-sin(phi-240deg)*iq

...cant yet figure out the scaling...


Measuring position depenmdent friction(=current)
------------------------------------------------
 ./move_record.py   cfg = {"sequencer": ['prog_1(host="SAROP11-CPPM-MOT6871",acq_per=10)', 'plot_1()']}

Avg current forward: 37.2596025196 Avg current backward: -68.9828819531
lut [[  1.00000000e+03  -2.70746096e+01]
 [  1.31399384e+03  -3.76975094e+01]
 [  1.71398707e+03  -5.78253228e+01]
...
 [  2.57135808e+04  -1.09363816e+01]
 [  2.61135740e+04  -1.42231517e+01]
 [  2.65135673e+04  -1.19655511e+01]
 [  2.69135605e+04  -6.38521106e+01]]




Python to Matlab
----------------

import numpy as np, scipy.io
fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/data/prog_1.npz'
fh=np.load(fn)
scipy.io.savemat(fn[:-3]+'mat',mdict=dict(fh.iteritems()))


compensate position depenmdent friction 1.2.2017
------------------------------------------------

Git tag: 3fafe53
gpasciiCommander --host SAROP11-CPPM-MOT6871 -i
!mx-stage()
&1 #1->0
&1 #2->0
#3$
an anschlag (kabel) bewegen
#3hmz
Motor[3].PhasePos=1200
#3j/

./move_record.py
abs average pos Error 2.1890901307

Motor[3].Servo.Kp=10
Motor[3].Servo.Kvfb=100
Motor[3].Servo.Kvff=100
abs average pos Error 1.89392140871

/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/src/usrServo/usrcode.c
line 100: c=0.f; //no friction compensation at all
abs average pos Error 1.82212631688

line 85: c=0.f; //do not use friction lut
abs average pos Error 1.47794399154

using friction lut:
abs average pos Error 0.893315213359

But if it  is put vertically, the value becomes bad again.
check friction on vertical stage

average PosError to P3000 2.2.2017
----------------------------------

modify programm generated by ./move_record.py:

open prog 2
N0:
linearabs
X505.488Y7.15189
dwell10
pvt10abs
X505.488:2526.97Y7.15189:-85.15309999999999
X556.028:4937.42Y5.44883:-34.6476
...
X508.588:0Y954.585:0
X508.588Y954.585
dwell10
goto 0
close




modify user servo to average PosError to P3000 2.2.2017
tweak parameters:
Motor[3].Servo.Kp
Motor[3].Servo.Kvfb
Motor[3].Servo.Ki
Motor[3].Servo.Kvff
Motor[3].Servo.Kaff

Kp   = 10     10   10       10    10    10   20                    
Kvfb = 220    220  220      220   220   220  220                   
Ki   = 0.001  0.01 0.02     0.01  0     0    0.02                  
Kvff = 240    240  240      240   240   240  240                   
Kaff = 0      0    0        20    1500  1500 1500                  
       1.3    .53  .43      0.52  1.88  0.7  0.1                   
                    A

A: Higher Ki than 0.02 do not help

Set Ki to 0 and seek optimal Kvff
Kvff =240 local minimum
Kvfb =220 local minimum
Kaff =1500 Kaff does not change the error amount, but makes the error smoother at 1500
Kp   =20 average error becomes smaller


Motor[3].Servo.Kvff

commit after: 3fafe53
./move_record.py 
>>>>>>>> abs average pos Error 0.353193239442 <<<<<<<

./shapepath.py gen_rand_points(n=400, scale=1000)
Random path at speed:
%100 average error x 1.32075 um, y 0.940694 um, 1.84578 um
%50  average error x 0.336186 um, y 0.259554 um, 0.478149 um
%25  average error x 0.177138 um, y 0.077619 um, 0.209937 um


./shapepath.py gen_grid_points(w=20,h=20,pitch=50,rnd=0.2)
Grid path at speed:
%100 average error x 0.363065 um, y 0.314149 um, 0.536246 um
%50  average error x 0.246374 um, y 0.0985771 um, 0.283925 um
%25  average error x 0.150303 um, y 0.0429124 um, 0.163468 um



Interferometer 11.4.2017
------------------------


adding to torqueCtrl lines:
!encoder_inc(enc=4,tbl=4,mot=4)# ,posSf=13000./650000)
!encoder_inc(enc=5,tbl=5,mot=5)# ,posSf=13000./650000)

gpasciiCommander --host SAR-CPPM-EXPMX1 -i
!mx-stage()
#1..3$
&1
#1..3j/

both interferometer works
homing and move:

#2..5p
-0.04000000000000008 0.0200000000000023 -298.8984375 39.890625
> #2j=10000;#3j=0000
#2j=10000;#3j=0000
> #2..5p
#2..5p
10000 2.380040609040179e-15 -500672.5625 4334.390625
> #2j=0000;#3j=0000
#2j=0000;#3j=0000
> #2j=0000;#3j=10000
#2j=0000;#3j=10000
> #2..5p
#2..5p
-0.02000000000000006 10000 -3559.06640625 -499752.609375




#2..5p
-0.08000000000000007 -0.003515624999636202 -0.5 7.2890625

#2j=10000
#2..5p
9999.980000000001 -0.01000000000021828 4290.96875 -500362.453125
#2j=0;#3j=10000
#2..5p
0 9999.992812500001 -499789.3984375 -3260.984375

Interferometer have 500000 counts per 10000um = 50 counts per um =20nm
at Motor[2].JogSpeed=10 the interferometer can not follow the motion.
It will not loose steps, but the maximum frequency is limiting during motion.
at Motor[2].JogSpeed=10 the interferometer and the encoder delivers similar values.


interfero_move_rec.py
      self.gather={"MaxSamples":1000000, "Period":acq_per}
      self.channels=channels=["Motor[3].ActPos","Motor[3].DesPos","Motor[3].PhasePos","Motor[3].idMeas","Motor[3].iqMeas"]

Gather.Enable=0
Gather.Items=6
Gather.MaxSamples=1000000
Gather.Period=10
Gather.Addr[0]=Motor[2].DesPos.a
Gather.Addr[1]=Motor[3].DesPos.a
Gather.Addr[2]=Motor[2].ActPos.a
Gather.Addr[3]=Motor[3].ActPos.a
Gather.Addr[4]=Motor[4].ActPos.a
Gather.Addr[5]=Motor[5].ActPos.a
open prog 2
  linear abs
  X0 Y0
  dwell 10
  Gather.Enable=2
  X10000 Y0
  dwell 100
  X0 Y0
  dwell 100
  X0 Y10000
  dwell 100
  X0 Y0
  dwell 1000
Gather.Enable=0
close
&1
b2r

download data with
PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1

cat /tmp/gather.txt

Motor[2].MaxSpeed=50
Motor[3].MaxSpeed=50
->gather50.txt

Motor[2].MaxSpeed=5
Motor[3].MaxSpeed=5
->gather5.txt

Motor[2].MaxSpeed=1
Motor[3].MaxSpeed=1
->gather1.txt

Changing encoder frequency on atto cube makes it run even at high speed


28. 4.2017 prepare for vibration measurement
--------------------------------------------
PPMAC=SAR-CPPM-EXPMX1

cd /home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX
PBInspect --host $PPMAC --cfg PBinspect.pbi

cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/src/usrServo
make


cd /home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/cfg
gpasciiCommander --host SAR-CPPM-EXPMX1 -i
!mx-stage()
#1..3$
&1
#1..3j/

#1j=360000   //360deg gegenuhrzeiger

#2j:100   //100 um right
#3j:100   //100 um up

move bottom left
#2,3$
Motor[2].PhasePos;Motor[3].PhasePos

Motor[2].PhasePos=310;Motor[3].PhasePos=1210
#2,3hmz
Motor[3].HomePos=Motor[3].HomePos+15000


Motor 2 vibriert mit 76ms =13.15 Hz


b2r
Load is now Alublock + mirrors

at 50 Hz peak to peak 200um
at 100Hz peak to Peak 50um
at 200Hz peak to Peak 13um
at 400Hz peak to Peak 1.5um



2. 5.2017 Vertical stage with load
----------------------------------

 scale=0.83832  #np.sqrt(3)/2*32767/33.850/1000

Motor[3].I2tSet=670.65601
670.65601/0.83832 = 800.000

ohne Platte   iqCmd = 625
Platte 133.2g iqCmd = 910
Platte 156.8g iqCmd = 965

Motor[3].IaMeas=-660
Motor[3].IbMeas=580
Motor[3].IqMeas=634.15991


Motor[3].IaMeas=-708
Motor[3].IbMeas=256



Motor[3].IaMeas=436  =520
Motor[3].IbMeas=-632 =-753
Motor[3].IqMeas=566.46863 = 675 


Claude messungen:
Phase 1:   330mA
Phase 2:   125mA
Phase 3:   694mA

Stromzange: 650 mA



Interferometer 29.5.2017
------------------------
cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX;PBInspect --cfg PBinspect.pbi --host SAR-CPPM-EXPMX1

gpasciiCommander --host SAR-CPPM-EXPMX1 -i
!mx-stage()
#1..3$
&1
#1..3j/

zero to neative inc values
move motor 2,3 from 500 to 28500
#1..5hmz

read acquire statements and program at to of plot_interfero.py


Motor[2].MaxSpeed=30;Motor[3].MaxSpeed=30
Motor[2].MaxSpeed=10;Motor[3].MaxSpeed=10

PPMAC=SAR-CPPM-EXPMX1
PBGatherPlot -m24 -v7 --host $PPMAC --dat gather1.txt


b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather0.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather1.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather2.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather3.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather4.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather5.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather6.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather7.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather8.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather9.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather10.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather11.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather12.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather13.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather14.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather15.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather16.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather17.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather18.txt
b2r
!sh PBGatherPlot -m24 -v7 --host SAR-CPPM-EXPMX1 --dat ../data_interfero_spd10/gather19.txt


Konstantfeder 2.6.2017
----------------------

cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX;PBInspect --cfg PBinspect.pbi --host SAR-CPPM-EXPMX1
cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/cfg/;gpasciiCommander --host SAR-CPPM-EXPMX1 -i
!mx-stage()

//#1..3$
//move bottom left
#2,3$
Motor[2].PhasePos;Motor[3].PhasePos

Motor[2].PhasePos=310;Motor[3].PhasePos=1210
#2,3hmz
Motor[2].HomePos=Motor[2].HomePos+5000
Motor[3].HomePos=Motor[3].HomePos+5000


&1

#1..3j/
#2..3j=0
L2=Motor[2].MaxDac
L3=Motor[3].MaxDac


Motor[2].MaxDac=500
#2j+

enable plc 1

Motor[2].HomeVel=2
Motor[3].HomeVel=2
#2,3$

Homing 12.6.2017
---------------

cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX;PBInspect --cfg PBinspect.pbi --host SAR-CPPM-EXPMX1
cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/cfg/;gpasciiCommander --host SAR-CPPM-EXPMX1 -i
!mx-stage()
//!init()
//!init_limit()

enable plc 1



cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/qt
CAQTDM_DISPLAY_PATH=/sf/controls/config/qt
EPICS_CA_ADDR_LIST='sf-cagw SAR-CPPM-EXPMX1'
EPICS_CA_ADDR_LIST=SAR-CPPM-EXPMX1
$ caget SAR-ESB_MX:MOTOR_X1

root@:/ioc/SAR-CPPM-EXPMX1# service shellbox status
pid port  user  dir     command
STOPPED 50001 ioc /ioc/SAR-CPPM-EXPMX1  iocsh startup.script
root@:/ioc/SAR-CPPM-EXPMX1# service shellbox start
Starting shellbox service:
Starting: 50001 ioc /ioc/SAR-CPPM-EXPMX1 iocsh startup.script

dbl
dbpf SAR-ESB_MX:MOTOR_Y1 10
dbpf SAR-ESB_MX:MOTOR_X1 10

dbpf SAR-ESB_MX:ASYN.AOUT 'enable plc 1'

Boot time of SAR-CPPM-EXPMX1 ca.4min.
telnet SAR-CPPM-EXPMX1 50001

ssh x06mx-cons-1
cd /scratch/ESB_MX/ESB_MX/qt
caqtdm -macro 'P=SAR-ESB_MX' ESB_MX_exp.ui 
caput SAR-ESB_MX:ASYN.AOUT 'enable plc 1'



tweak param 13.6.2017
---------------------

with stada stage 21.7.2017
--------------------------
telnet SAR-CPPM-EXPMX1 50001
ctrl-T
ctrl-X

$$$***
!common()
!mx-stage()

#7j:512000
511999.9988954368 49999

Motor8:#8,16p
511999.9922968491 49976

RL32-BAS050C15...
512000 ustep == 50000 encCnt == 2.5mm -> 50nm/encCnt

OpenLoop:
!encoder_sim(enc=7)
!encoder_sim(enc=8)
!encoder_biss(enc=7,tbl=15,mot=15)
!encoder_biss(enc=8,tbl=16,mot=16)
!motor(mot=7,current=200,JogSpeed=102.4*1,invDir=1,HomeOffset=39263)
!motor(mot=8,current=200,JogSpeed=102.4*1,invDir=1)//,HomeOffset=39762)

!encoder_biss(enc=7,tbl=15,mot=15)
!encoder_biss(enc=8,tbl=16,mot=16)
!motor(mot=7,current=200,JogSpeed=102.4*1,invDir=1)
!motor(mot=8,current=200,JogSpeed=102.4*1,invDir=1)




Status Review 2.8.2017
----------------------

cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX;PBInspect --cfg PBinspect.pbi --host SAR-CPPM-EXPMX1
cd ~/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/cfg/;gpasciiCommander --host SAR-CPPM-EXPMX1 -i
$$$***
!common()
!mx-stage()
enable plc 1  //homing

#1j:1000  //rotate 1 deg
#2j:1000  //x-stage parker 1000um
#3j:1000  //y-stage parker 1000um
#4,5p  //position of interferometer (if connected)
#7,8j/
#7j:1000 //x-stage stada 1000um
#8j:1000 //z-stage stada 1000um


telnet SAR-CPPM-EXPMX1 50001
ctrl-T
ctrl-X

ssh x06mx-cons-1
cd /scratch/ESB_MX/ESB_MX/qt
caqtdm -macro 'P=SAR-ESB_MX' ESB_MX_exp.ui
Press homing or following line:
caput SAR-ESB_MX:ASYN.AOUT 'enable plc 1'



