Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 8ed0bc61f74cbe8b9d07278a25fd9f49c0af3f2b authored by Kellen Vu on 03 November 2022, 01:23:38 UTC, committed by Kellen Vu on 03 November 2022, 01:23:38 UTC
Fixes a bug where eyeCalibration.mlapp was trying to get the sample rate from the wrong smr channel. I tested this in D243b, and it should work for other computers, but let me know if it doesn't.
1 parent 1611f97
  • Files
  • Changes
  • cd980e7
  • /
  • Experiment Protocols
  • /
  • Parameters_Universal.s2s
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:8ed0bc61f74cbe8b9d07278a25fd9f49c0af3f2b
directory badge Iframe embedding
swh:1:dir:73ffcf87dce87be96f418e9499e77c2335fd199b
content badge Iframe embedding
swh:1:cnt:1833acfc6584d877d538bcd472d1daed3e0074ed
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Parameters_Universal.s2s
' UNIVERSAL PARAMETERS

'--------------------------------------------------------------------------------
' SINE PARAMETERS
'--------------------------------------------------------------------------------
var sinHzChair := 1;
var sinPhChair := -90;
var actualChairPh;
var sinHzDrum := 1;
var sinPhDrum := 90;
var actualDrumPh;
var sineOn% := 0;
var sinAmpChair := 10;
var sinAmpDrum := 10;
var halfPhaseDelay := (sinHzDrum * 1000) / 2;

'--------------------------------------------------------------------------------
' STEP PARAMETERS
'--------------------------------------------------------------------------------
var step_period := 1000;
var step_length := 250;
var stepStim := 0;
var step_AmpChair := 10;
var step_AmpDrum := 10;
var step_rest2;
var sStart;
var step_length_corrected;
var step_length_corrected1;
var step_rest1;
var step_length_a := 0;
var step_length_b := 0;
var step_length_c := 0;
'For video alignment pulse - duration
var pulse_durationV := 33;
'For video alignment pulse - time between pulses
var pulseWaitV := 1000 - pulse_durationV - 5;
var cycleLength := 1000;
var checkConfig := 1;
var QueTime := 0;
var step_interStepInterval := 0;

'--------------------------------------------------------------------------------
' PULSE PARAMETERS
'--------------------------------------------------------------------------------
var pulse_wait := 0;
var pulse_number := 1;
var pulse_start := 0;
var pulse_duration := 500;
var pulse_interPulseInterval := 0;
var stepLight := 0;
var lightDur := 500;
var lightStart := 0;
var everyNCycles := 1;
var fullPulse := 0;

'--------------------------------------------------------------------------------
' EXPERIMENT PARAMETERS
'--------------------------------------------------------------------------------
var nBlocks% := 6;                 'Number of run-test blocks in exmpt
var nTestreps% := 1;               'Number of times to repeat 40 sec test
var runLength := 300;             'Seconds to run protocol in each block(300 for 5 min)
var testLength := 45;             'Seconds to test
var expmtLoc% := 1;
var prePostNum := 1;
var trainLoc% := 1;
var trainAmount := 0;
var expmtMode := 2;               'expmtMode: 0=off, 1=0x, 2=2x, 3=ipsi stim, 4=contra stim
var testString$;
var runExpmt% := 0;               ' Random note: % denotes integer types
var rep% := 0;                    'Rep (5min run, 40 sec test)
var test% := 1;                   'test: 0=run testLength, 1=test testLength, 2=init&wait 20 sec, 3=init&wait 10 sec,  4=init&wait runLength
var testrep% := 0;
var goalTime := 1000000000;    'maximum time the motor is allowed to run for
var flashon% := 1;
var waitLength := 300;
var prevTime := 0;
var W := 1;
var X := 1.02;
var Y := .9;
var Z := 1;



'--------------------------------------------------------------------------------
' MISC PARAMETERS
'--------------------------------------------------------------------------------
var SampleWindow%;
var comment$;
var vidOn := 0;
var stepOn% := 0;
'Voltage Range: check in Edit -> Edit Parameters
var MaxVoltage := 10;
var driftFix := 1;
var centerLineChair := 0;
var centerLineDrum := 0;
var rotationVelocity := 0.02;
var radianConversion := 57.295779513; 'divide a value in degrees by this number to convert to radians - from Spike2 manual'
var measuredZeroChair := 0;
var measuredZeroDrum := 0;

'--------------------------------------------------------------------------------
' TOOLBAR PARAMETERS
'--------------------------------------------------------------------------------
const NewFilePos        := 3;
const InitPos           := NewFilePos+1;
const CommentPos        := InitPos+1;
const LightPos          := CommentPos+2;
const LaserPos          := LightPos+1;
const SinePos           := LaserPos+2;
const SineConfigPos     := SinePos+1;
const PulsePos          := SineConfigPos+2;
const PulseConfigPos    := PulsePos+1;
const VidPos            := PulseConfigPos+2;
const StepPos           := VidPos+2;
const StepConfigPos     := StepPos+1;
const ExpmtPos          := StepConfigPos+2;
const ExpmtConfigPos    := ExpmtPos+1;
const devPos            := ExpmtConfigPos+2;

const HTVELChCom% := 1;
const HHVELChCom% := 2;
const htposCh% := 3;
const hhposCh% := 4;
const heposCh1% := 5;
const heposCh2% := 6;
const hhvelCh% := 8;
const htvelCh% := 13;

'--------------------------------------------------------------------------------
' SINE FUNCTIONS
'--------------------------------------------------------------------------------
Func ToolbarSineStart%()
  prevTime := MaxTime();
  measuredZeroChair := ChanMeasure(hhposCh%, 2, prevTime-2, prevTime-.5);
  measuredZeroDrum := ChanMeasure(htposCh%, 2, prevTime-2, prevTime-.5);
  SampleKey( "S" );
  sineOn% := 1;
  Yield();
  ToolbarSet(SinePos, "Sine Off",ToolbarSineStop%);
  Return( 1 );
End

Func ToolbarSineStop%()
  SampleKey( "s" );
  sineOn% := 0;
  ToolbarSet(SinePos, "Sine On",ToolbarSineStart%);
  Return( 1 );
End

Func ToolbarSineConfig%()
  DlgCreate("SINE SETTINGS");  'Start new dialog
  DlgReal(1,"Chair Freq (Hz)",0,50);
  DlgReal(2,"Chair Peak Velocity (deg/sec)",0,100);    'set to 0 if not using Chair
  DlgReal(3,"Chair Phase (degree)",-180,180);
  DlgReal(4,"Drum Freq (Hz)",0,50);
  DlgReal(5,"Drum Peak Velocity (deg/sec)",0,100);   'set to 0 if not using Drum
  DlgReal(6,"Drum Phase (degree)",-180,180);
  DlgCheck(7,"Opto");
  DlgCheck(8,"Light");

  DlgShow(sinHzChair,sinAmpChair, sinPhChair, sinHzDrum, sinAmpDrum,  sinPhDrum, stepStim, stepLight);

  halfPhaseDelay := (sinHzDrum * 1000) / 2;

  SetPulseSettings%();

  SetSequencerValues();

  Return(1);
End

'--------------------------------------------------------------------------------
' LIGHT FUNCTIONS
'--------------------------------------------------------------------------------
Func ToolbarLightOn%()
  SampleKey( "L" );
  Toolbarset(LightPos,"Light Off", ToolbarLightOff%);
  Return( 1 );
End

Func ToolbarLightOff%()
  SampleKey( "l" );
  Toolbarset(LightPos,"Light On", ToolbarLightOn%);
  Return( 1 );
End

Proc runFlash()
  if flashon% = 1 then
      ToolbarLightOn%();
  endif;
  Yield(.2);
  ToolbarLightOff%();
End

'--------------------------------------------------------------------------------
'Turn both lasers on/off
'--------------------------------------------------------------------------------
Func ToolbarLasersOn%()
  SampleKey( "Z" );
  Toolbarset(LaserPos,"Lasers Off", ToolbarLasersOff%);
  Return( 1 );
End

Func ToolbarLasersOff%()
  SampleKey( "z" );
  Toolbarset(LaserPos,"Lasers On", ToolbarLasersOn%);
  Return( 1 );
End

'--------------------------------------------------------------------------------
'Start sine wave/pulses for video
'--------------------------------------------------------------------------------
Func ToolbarVidOn%()
  vidOn := 1;
  Yield();
  pulse_durationV := 33; 'For video alignment pulse
  pulseWaitV := 1000*1/sinHzChair - pulse_durationV - 5;    'For video alignment
  SetSequencerValues();
  SampleKey( "V" );
  Toolbarset(VidPos,"Video Off", ToolbarVidOff%);
  Return( 1 );
End

Func ToolbarVidOff%()
  vidOn := 0;
  Yield();
  SampleKey( "v" );
  Toolbarset(VidPos,"Video On", ToolbarVidOn%);
  Return( 1 );
End

'--------------------------------------------------------------------------------
' PULSE FUNCTIONS
'--------------------------------------------------------------------------------
Func ToolbarPulseConfig%()
  DlgCreate("Pulse settings");  'Start new dialog
  DlgReal(1,"Number of Pulses",0,1000);
  DlgReal(2,"Pulse duration (ms)",0,5000);
  DlgReal(3,"Inter-pulse interval (ms)",0,5000);
  DlgReal(4,"Pulse start rel. to cycle (ms)",0,10000);
  DlgReal(5,"Pulses Occur Every X Cycles?", 1, 10000);

  DlgShow(pulse_number, pulse_duration, pulse_interPulseInterval, pulse_start, everyNCycles);

  ' SetPulseSettings%(); is to correct for delays that occur when sending commands out from the sequencer.'
  SetPulseSettings%();
  Return( 1 );
End

Func SetPulseSettings%()
  ' This function is to correct for delays that occur when sending commands out from the sequencer.'
  cycleLength := 1/sinHzChair * 1000;
  pulse_wait := (cycleLength/2) - (pulse_number * (pulse_duration + pulse_interPulseInterval));

  ' If the pulse_wait time is <= 0, then there is no gap between pulses
  fullPulse := 0;
  if pulse_wait < 0 then
      pulse_wait := 0 ;
      fullPulse := 1;
  endif;

  SetSequencerValues();

  Return(1);
End

'--------------------------------------------------------------------------------
' STEP FUNCTIONS
'--------------------------------------------------------------------------------
Func ToolbarStepOn%()

  stepOn% := 1;
  ToolbarSet(StepPos, "Step Stop", ToolbarStepOff%);

  docase
    ' NO OPTO, NO LIGHT
    case (stepStim = 0) and (stepLight = 0) then
      if (step_period - (2*step_length)) > 0 then
        SampleKey ( "J" );
      else
        if QueTime > 0 then
          SampleKey("K");
        else
          SampleKey("k");
        endif
      endif

    ' OPTO, NO LIGHT'
    case (stepStim = 1) and (stepLight = 0) then
      prevTime := MaxTime();
      measuredZeroChair := ChanMeasure(hhposCh%, 2, prevTime-2, prevTime);
      measuredZeroDrum := ChanMeasure(htposCh%, 2, prevTime-2, prevTime);

      docase
        ' Aligned to entire step
        case lightDur = step_length and lightStart = 0 then
          SampleKey("t");
        ' Aligned to beginning of step
        case step_length_a = 0 then
          SampleKey("b");
        ' Aligned to end of step
        case step_length_c = 0 then
          SampleKey("e");
        ' Aligned to somewhere in the middle of step
        else
          SampleKey("d");
      endcase;

    ' NO OPTO, Light'
    case (stepStim = 0) and (stepLight = 1) then
      ' Nothing here yet

    ' OPTO, LIGHT'
    case (stepStim = 1) and (stepLight = 1) then
      docase
        ' Aligned to entire step
        case lightDur = step_length and lightStart = 0 then
          SampleKey("T");
        ' Aligned to beginning of step
        case step_length_a = 0 then
          SampleKey("B");
        ' Aligned to end of step
        case step_length_c = 0 then
          SampleKey("E");
        ' Aligned to somewhere in the middle of step
        else
          SampleKey("D");
      endcase;

  endcase;

  Return (1);
End

Func ToolbarStepOff%()
  SampleKey( "I" );
  stepOn% := 0;
  ToolbarSet(StepPos, "Step Start", ToolbarStepOn%);
  Return( 1 );
End

Func ToolbarStepConfig%()

  cycleLength := 1/step_period * 1000;

  step_interStepInterval := max( (cycleLength/2)  - step_length , 0);

  ' Light pulse
  if stepLight = 1 then

      ' If light pulse is not exactly the same as step pulse, break into 3 segments
      if lightDur <> step_length or lightStart <> 0 then
          step_length_a := lightStart;
          step_length_b := lightDur;
          step_length_c := max(step_length - (lightDur + lightStart),0);
      endif;
  endif;

  '........|aaaa|bbbbbbbbb|cccccc|............................................
  '.............__________....................................................
  '____________|.........|______________light_________________________________
  '...........................................................................
  '........______________________..................______________________.....
  '.......|.....................|.................|.....................|.....
  '.......|.....................|.................|.....................|.....
  '.......|.....................|.................|.....................|.....
  '_______|.....................|____drum/chair___|.....................|_____

  if stepStim = 1 then
  	pulse_number := trunc((step_length-4)/(pulse_duration + pulse_interPulseInterval));
  	var pulse_duration_corrected := pulse_duration -2;
  	var pulse_interPulseInterval_corrected := pulse_interPulseInterval -3;
  	step_length_corrected1 := step_length - ((pulse_duration + pulse_interPulseInterval)*pulse_number)-4;
  endif;

  'testing
  SetPulseSettings%();
  Yield();
  SetSequencerValues();
  Return (1);
End

Func StepConfigWindow%()
  DlgCreate("STEP SETTINGS"); 'Start new dialog for entering step commands
  DlgReal(1,"Total Period (ms)", 0, 21000);
  DlgReal(2,"Step length (ms)", 0, 15000);
  DlgReal(3,"Chair Velocity (deg/sec)", -100, 100);
  DlgReal(4,"Drum Velocity (deg/sec)", -100, 100);
  DlgCheck(5,"Stimulate");
  DlgReal(6, "Pulse duration (ms)", 0, 5000);
  DlgReal(7, "Interpulse interval (ms)", 0, 5000);
  DlgCheck(8, "Light");
  DlgReal(9, "Light duration (ms)", 0, 5000);
  DlgReal(10, "Start time rel. step", 0, 5000);
  DlgShow(step_period, step_length, step_AmpChair, step_AmpDrum, stepStim, pulse_duration, pulse_interPulseInterval, stepLight, lightDur, lightStart);

  ToolbarStepConfig%();
  Return (1);
End

'--------------------------------------------------------------------------------
' STIM/PULSE FUNCTIONS
'--------------------------------------------------------------------------------
Func ToolbarStimOn%()
  if fullPulse = 1 then
      SampleKey( "Q" );
  else
      SampleKey("P");
  endif;
  sineOn% := 0;
  Yield();
  Toolbarset(PulsePos,"Pulse Off", ToolbarStimOff%);
  Return( 1 );
End

Func ToolbarStimOff%()
  SampleKey( "p" ); Yield();
  SampleKey( "I" ); Yield();
  sineOn% := 0;

  Toolbarset(PulsePos,"Pulse On", ToolbarStimOn%);
  Return( 1 );
End

'--------------------------------------------------------------------------------
' OTHER FUNCTIONS
'--------------------------------------------------------------------------------
Proc ToolbarConfig()
  ToolbarClear();     'Remove any old buttons

  ToolbarSet(0, "Idle",ToolbarIdle%);
  ToolbarSet(1, "Quit",  ToolbarQuit%);
  ToolbarSet(InitPos, "Init", ToolbarInit%);
  ToolbarSet(LightPos, "Light On", ToolbarLightOn%);
  ToolbarSet(LaserPos, "Lasers On", ToolbarLasersOn%);
  ToolbarSet(SinePos, "Sine On", ToolbarSineStart%);
  ToolbarSet(SineConfigPos, "Sine Config", ToolbarSineConfig%);
  ToolbarSet(PulseConfigPos, "Pulse Config", ToolbarPulseConfig%);
  ToolbarSet(PulsePos, "Pulse On", ToolbarStimOn%);
  ToolbarSet(VidPos, "Video On", ToolbarVidOn%);
  ToolbarSet(StepPos, "Step On", ToolbarStepOn%);
  ToolbarSet(StepConfigPos, "Step Config", StepConfigWindow%);
  ToolbarSet(ExpmtPos, "Run Expmt", ToolbarRunExpmt%);
  ToolbarSet(ExpmtConfigPos, "Expmt Config", ToolbarConfigExpmt%);
  ToolbarSet(CommentPos, "Comment", ToolbarComment%);
  ToolbarSet(NewFilePos, "New File", ToolbarNew%);
  ToolbarSet(devPos+1, "Dev", DevParams%);
  Toolbar("", 231);
End

Proc WindowConfig()

  SampleClear(); 'Set the sampling configuration to a standard state

  'sequencer setup - returns zero if OK
  var err%; err% := SampleSequencer( SequencerFile$ );
  if err%<0 then
  	Message(Print$("I can't find your Sequencer File:%s",Error$(err%)));
  	halt
  endif

  'Channel 1
  SampleWaveform(HTVELChCom%,0,1000);  'Channel= 1, port= 0, ideal sampling rate= 1000 Hz
  SampleCalibrate(HTVELChCom%,"deg/s", DrumVoltage2Velocity, DrumVoltage2VelocityC);
  SampleTitle$(HTVELChCom%,"HTVEL");
  SampleComment$(HTVELChCom%, "Velocity Signal sent to drum");

  'Channel 2
  SampleWaveform(HHVELChCom%,1,1000);
  SampleCalibrate( HHVELChCom%, "deg/s", ChairVoltage2Velocity, ChairVoltage2VelocityC);
  SampleTitle$(HHVELChCom%,"HHVEL");
  SampleComment$(HHVELChCom%, "Velocity Signal sent to chair");

  'Channel 3
  SampleWaveform(htposCh%,2,1000);
  SampleCalibrate(htposCh%, "deg", DrumPosReadoutScale, DrumPosReadoutOffset);
  SampleTitle$(htposCh%,"htpos");
  SampleComment$(htposCh%, "Drum position");

  'Channel 4
  SampleWaveform(hhposCh%,3,1000);
  SampleCalibrate(hhposCh%,"deg", ChairPosReadoutScale, ChairPosReadoutOffset);
  SampleTitle$(hhposCh%,"hhpos");
  SampleComment$(hhposCh%, "Chair Position");

  'Channel 5
  SampleWaveform(heposCh1%,4,1000);
  SampleCalibrate(heposCh1%,"V",EyeVoltage2Position,EyeVoltage2PositionC);
  SampleTitle$(heposCh1%,"hepos1");
  SampleComment$(heposCh1%, "Eye Position 1");

  'Channel 6
  SampleWaveform(heposCh2%,5,1000);
  SampleCalibrate(heposCh2%,"V", EyeVoltage2Position,EyeVoltage2PositionC);
  SampleTitle$(heposCh2%,"hepos2");
  SampleComment$(heposCh2%, "Eye Position 2");

  'Channel 7 UCOMMENT THIS FOR EPHYS
  'SampleWaveform(7,6,1000);
  'SampleCalibrate(7,"V",1,0);
  'SampleTitle$(7,"phys");
  'SampleComment$(7, "phys");

  'Channel 7 UNCOMMENT THIS FOR HD MOTOR
  'SampleTalker(7,"LS7366",0);
  'SampleCalibrate(7,"deg",1111.111,0);
  'SampleTitle$(7,"DrumPos");
  'SampleComment$(7,"Drum Position");

  'Channel 8
  SampleWaveform(hhvelCh%,7,1000);
  SampleCalibrate(hhvelCh%,"deg/s",ChairVelReadoutScale,ChairVelReadoutOffset);
  SampleTitle$(hhvelCh%,"hhvel");
  SampleComment$(hhvelCh%, "Chair velocity");

  'Channel 9
  SampleEvent(9,0,2,1000);     'Func SampleEvent(chan%, port%, type%, rate);
  SampleTitle$(9,"TTL1");
  SampleComment$(9, "TTL1: Shutter");

  'Channel 10
  SampleEvent(10,1,2,1000);
  SampleTitle$(10,"TTL2");
  SampleComment$(10, "TTL2: IR LED");

  'Channel 11
  SampleEvent(11,2,2,1000);
  SampleTitle$(11,"TTL3");
  SampleComment$(11, "TTL3: L laser");

  'Channel 12
  SampleEvent(12,3,2,1000);
  SampleTitle$(12,"TTL4");
  SampleComment$(12, "TTL4: R laser");

  'Channel 13
  SampleWaveform(htvelCh%,8,1000);
  SampleCalibrate(htvelCh%,"deg/s",DrumVelReadoutScale,DrumVelReadoutOffset);
  SampleTitle$(htvelCh%,"htvel");
  SampleComment$(htvelCh%, "Drum Velocity");

  'Channel 15 - ALEX FANNING
  'SampleEvent(15,4,2,1000); '- ALEX FANNING
  'SampleTitle$(15,"TTL5"); '- ALEX FANNING
  'SampleComment$(12, "TTL5: FP Pulse"); '- ALEX FANNING

  'Channel 30
  SampleTextMark(200);

  'Set optimise mode (do this last)
  SampleOptimise(1,1,0,2,50);

  'Continuous sampling
  SampleMode(1);

  'Create a spike2 data file and make the new window visible immediately
  SampleWindow% := FileNew(0,1);

  'Add smoothing to some channels
  'ChanProcessAdd(13, 1, 0.05);

  SetSequencerValues();

  'Hide all
  ChanHide(-1);

  'Show certain channels in a particular order
  ChanShow(1,2,3,4,5,6,7,8,9,10,11,12,13,14,30,31);
  'ChanShow(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,30,31); 'Alex Fanning

  'ChanSelect(13,1);    'Select channel 13
  'ChanOrder(4,1,-3);   'Move selected channels
  '-----------------------------------------

  'Channel y-range (channel num, low, high)
  YRange( 1, -10, 10 );
  YRange( 2, -10, 10 );
  YRange( 3, -10, 10 );
  YRange( 4, -10, 10 );
  YRange( 5, -10, 10 );
  YRange( 6, -10, 10 );
  YRange( 7, -10, 10 );
  YRange( 8, -10, 10 );
  'YRange( htvelChan%, -10, 10 ); ' OPTIONAL D019 CHANNELS???
  'YRange( hhvelChan%, -10, 10 ); ' OPTIONAL D019 CHANNELS???

  ChanWeight(1,.5);           ' Make command channel smaller
  ChanWeight(2,.5);           ' Make command channel smaller

  XRange( 0, 20);      ' Set the default X axis time range

  ' Channel order
  'ChanOrder(0, -1, "5, 4, 8, 13, 3, 2, 1, 12, 11, 10, 9, 30, 31");
  'ChanOrder(0, -1, "5, 4, 8, 13, 3, 2, 1, 12, 11, 10, 9, 30, 31, 15"); 'Alex Fanning
  ChanOrder(0, -1, "2,4,8,1,3,13,5,6,9,10,11,12,30,31"); 'Trace Stay

  ' Background Colour'
  ViewColour(0,5);
  ' Font
  FontSet("Verdana", 8, 0);
  ' Chan colors
  chanColour(HTVELChCom%, 1, 28);
  chanColour(htposCh%, 1, 28);
  chanColour(htvelCh%, 1, 28);

  chanColour(HHVELChCom%, 1, 30);
  chanColour(hhposCh%, 1, 30);
  chanColour(hhvelCh%, 1, 30);

  chanColour(heposCh1%, 1, 1);
  chanColour(heposCh2%, 1, 1);


  ' Useful Zero line indicators
  HCursorNew(1);
  HCursor(1, 0, 1);

  HCursorNew(2);
  HCursor(2, 0, 2);

  HCursorNew(3);
  HCursor(3, 0, 3);

  HCursorNew(4);
  HCursor(4, 0, 4);

  HCursorNew(5);
  HCursor(5, 0, 8);

  HCursorNew(6);
  HCursor(6, 0, 12);
End

Func ToolbarNew%()
  WindowConfig();
  ' Make window full screen
  WindowVisible(3);
  Return (1);
End

Func ToolbarComment%()
  DlgCreate("Comment"); 'Start new dialog for entering comments
  DlgString(1,"Comment",200);
  DlgShow(comment$);
  SampleText(comment$);
  Return(1);
End

Func ToolbarRunExpmt%()
  runExpmt% := 1;
  rep% := 0;
  test% := 0;
  testrep% := 0;
  goalTime := MaxTime();
  SampleKey("H");
  ToolbarSet(ExpmtPos, "Quit Expmt",ToolbarQuitExpmt%);
  Return(1);
End

Func ToolbarQuitExpmt%()
  runExpmt% := 0;
  ToolbarInit%();
  SampleKey("h");
  ToolbarSet(ExpmtPos, "Run Expmt",ToolbarRunExpmt%);
  Return(1)
End

Func ToolbarInit%()
  ToolbarLightOff%(); Yield();
  ToolbarStepOff%(); Yield();
  ToolbarSineStop%(); Yield(.01);
  ToolbarStimoff%(); Yield();
  ToolbarLasersOff%(); Yield();
  prevTime := 0;  ' Reset prev time so sine offset code continues running in a new file
  SampleKey( "I" );
  Return( 1 );
End

Func ToolbarQuit%()
  SampleKey( "O" );
  Return( 0 );
End

Func DevParams%()
  DlgCreate("Dev Params");  'Start new dialog
  DlgReal(1,"W",-2,2);
  DlgReal(2,"X",-2,2);
  DlgReal(3,"Y",-2,2);
  DlgReal(4,"Z",-2,2);
  DlgShow(W, X, Y, Z);
  Return(1);
end

' Send values to the sequencer
Proc SetSequencerValues()
  actualChairPh := ((sinPhChair + 180) mod 360) - 180;
  actualDrumPh  := ((sinPhDrum + 180) mod 360) - 180;

  'Chair parameters
  SampleSeqVar( 23, ChairAmp2Int32%( ChairDegreesPerSecondOffset ) );
  SampleSeqVar( 27, ChairAmp2Int16%( sinAmpChair ) );
  SampleSeqVar( 28, Angle2Int32%( actualChairPh ) );
  SampleSeqVar( 29, Hz2Int32%( sinHzChair ) );
  SampleSeqVar( 55, ChairResetDirection); 'default chair direction

  'Drum parameters
  SampleSeqVar( 22, DrumAmp2Int32%( DrumDegreesPerSecondOffset ) );
  SampleSeqVar( 24, DrumAmp2Int16%( sinAmpDrum ) );
  SampleSeqVar( 25, Angle2Int32%( actualDrumPh ) );
  SampleSeqVar( 26, Hz2Int32%( sinHzDrum ) );
  SampleSeqVar( 65, DrumResetDirection); 'default drum direction

  'Pulse parameters
  SampleSeqVar( 33, pulse_wait );
  SampleSeqVar( 34, pulse_number );
  SampleSeqVar( 35, pulse_duration);
  SampleSeqVar( 36, pulse_interPulseInterval);
  SampleSeqVar( 37, pulse_start);

  'Step parameters
  SampleSeqVar( 38, step_rest2);
  SampleSeqVar( 39, sStart);
  SampleSeqVar( 40, step_length_corrected);
  SampleSeqVar( 41, step_length_corrected1);
  SampleSeqVar( 42, step_rest1);
  SampleSeqVar( 43, ChairVel2Int32%( step_AmpChair ));
  SampleSeqVar( 44, DrumVel2Int32%(  step_AmpDrum ));
  SampleSeqVar( 45, (0 - ChairVel2Int32%( step_AmpChair )) );
  SampleSeqVar( 46, (0 - DrumVel2Int32%(  step_AmpDrum )) );
  SampleSeqVar( 47, step_length_a); ' For delayed light pulse with step
  SampleSeqVar( 48, step_length_b);
  SampleSeqVar( 49, step_length_c);
  SampleSeqVar( 50, pulse_durationV);
  SampleSeqVar( 51, pulseWaitV);
  SampleSeqVar( 52, cycleLength);
  SampleSeqVar( 54, everyNCycles);
  SampleSeqVar( 55, QueTime );
  SampleSeqVar( 56, DrumAmp2Int32%( DrumDegreesPerSecondOffsetDefault ) );
  SampleSeqVar( 57, ChairAmp2Int32%( ChairDegreesPerSecondOffsetDefault ) );
  SampleSeqVar( 58, halfPhaseDelay);

  'Rotation Parameters
  SampleSeqVar( 66, rotationVelocity); 'This is a relative value
End

Func driftFix%()
  'drift back to 0 if sine wave isn't running
  docase
  case stepOn% = 1 then
    'SampleKey("7");
    if step_AmpChair > 0 then
      'SampleKey("8");
      centerLineChair := (step_length/1000) * step_AmpChair * W;
    endif
    if step_AmpChair < 0 then
      'SampleKey("9");
      centerLineChair := (step_length/1000) * step_AmpChair * X;
    endif
    if step_AmpChair = 0 then
      'SampleKey("0");
      centerLineChair := 0;
    endif

    if step_AmpDrum > 0 then
      'SampleKey("7");
      centerLineDrum := (step_length/1000) * step_AmpDrum * Y;
    endif
    if step_AmpDrum < 0 then
      'SampleKey("6");
      centerLineDrum := (step_length/1000) * step_AmpDrum * Z;
    endif
    if step_AmpDrum = 0 then
      centerLineDrum := 0;
    endif

  case sineOn% = 1 or vidOn = 1 then
    var chairSign := 1; 'set default to 1 if phase = 0'
    var drumSign := 1;

    'figure out whether we want velocity to be positive or negative'
    if sinPhChair <> 0 then
      chairSign := sinPhChair / Abs(sinPhChair);
    endif
    if sinPhDrum <> 0 then
      drumSign := sinPhDrum / Abs(sinPhDrum);
    endif

    'convert from the sine amplitude signal to the actual position amplitude'
    var trueAmpChair := sinAmpChair / (2 * 3.14159 * sinHzChair);
    var trueAmpDrum := sinAmpDrum / (2 * 3.14159 * sinHzDrum);

    'calculates the center y value according to the phase given'
    var centerForPhaseChair := trueAmpChair * (1 - cos((-1 * sinPhChair)/radianConversion));
    var centerForPhaseDrum := trueAmpDrum * (1 - cos((-1 * sinPhDrum)/radianConversion));

    'takes into account that chair/drum may not start at 0'
    var theoreticalCenterChair := (centerForPhaseChair + measuredZeroChair) * chairSign;
    var theoreticalCenterDrum := (centerForPhaseDrum + measuredZeroDrum) * drumSign;

    'NOTE: there is something funky with the motors where there is an error that follows a sine wave from phase'
    'WE DON'T KNOW WHY, ONLY THAT IT HAPPENS'
    'the drift coefficients need to be calculated manually by testing the error for different phase offsets'
    var errorOffsetChair := ChairDriftFactor * sinAmpChair * sin(2 * sinPhChair / radianConversion);
    var errorOffsetDrum := DrumDriftFactor * sinAmpDrum * sin(2 * sinPhDrum / radianConversion);

    centerLineChair := (theoreticalCenterChair + errorOffsetChair) * ChairResetDirection;
    centerLineDrum := (theoreticalCenterDrum + errorOffsetDrum) * DrumResetDirection;

  else
    centerLineChair := 0;
    centerLineDrum := 0;
  endcase

  prevTime := MaxTime();
  ' Measure slope from last 1 cycle of chair/drum position feedback
  var hhposSlope := ChanValue(hhposCh%, prevTime) - ChanValue(hhposCh%, prevTime-(1/sinHzChair));
  var htposSlope := ChanValue(htposCh%, prevTime) - ChanValue(htposCh%, prevTime-(1/sinHzDrum));
  var hhposPos := ChanMeasure(hhposCh%, 2, prevTime-(1/sinHzChair), prevTime) + (centerLineChair);
  var htposPos := ChanMeasure(htposCh%, 2, prevTime-(1/sinHzDrum), prevTime) + (centerLineDrum);

  ' Scales *1 for D253, *-1 for D019
  ChairDegreesPerSecondOffset :=  (ChairDegreesPerSecondOffsetDefault - hhposSlope/4 - hhposPos/4) * ChairResetDirection;
  DrumDegreesPerSecondOffset  :=  (DrumDegreesPerSecondOffsetDefault - htposSlope/4 - htposPos/4) * DrumResetDirection;

  'ToolbarStepConfig%();

  SetSequencerValues();
End

'--------------------------------------------------------------------------------
' CONVERSION FUNCTIONS
'--------------------------------------------------------------------------------

' Angles in the range [-180,180] should span [-2147483648.0,2147483647.0]
Func Angle2Int32%( angle )
  Return( angle * 2147483647.0 / 180 );
End

' Rates are calculated in degrees per sequencer step, with one degree being 11930465.
Func Hz2Int32%( hz )
 'This assumes a sequencer rate of 1 kHz.
  Return( hz * 11930465 * 360 / 1000 );
End

' Amplitudes must be converted such that [ 0, 32768 ] spans the positive range of the dac, e.g. [0, 5 ]
' We have to include the dac maximum and the degrees-per-second-to-voltage conversion factor. Does not include offset.
Func ChairAmp2Int16%( amp )
  Return( amp * ChairDegreesPerSecond2Voltage * 32768 / MaxVoltage  ) ;
End

Func DrumAmp2Int16%( amp )
  Return( amp * DrumDegreesPerSecond2Voltage * 32768 / MaxVoltage  )  ;
End

Func ChairAmp2Int32%( amp )
  Return( amp * ChairDegreesPerSecond2Voltage * 2147483647 / MaxVoltage  ) ;
End

Func DrumAmp2Int32%( amp )
  Return( amp * DrumDegreesPerSecond2Voltage * 2147483647 / MaxVoltage  )  ;
End

' steps
' Command velocities must be converted such that [ 0, 2147483647 ] spans the positive range of the dac, e.g. [0, 5 ]
' We have to include the dac maximum and the degrees-per-second-to-voltage conversion factor.
Func ChairVel2Int32%( amp )
  Return(  (amp + ChairDegreesPerSecondOffset) * ChairDegreesPerSecond2Voltage* 2147483647 / MaxVoltage  );
End

Func DrumVel2Int32%( amp )
  Return( (amp + DrumDegreesPerSecondOffset) * DrumDegreesPerSecond2Voltage * 2147483647 / MaxVoltage  );
End
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API