@@ -301,6 +301,23 @@ def do_checks(self, trigger_times):
301301 Raises:
302302 LabscriptError: If a trigger time conflicts with an instruction.
303303 """
304+
305+ ### Resolve Ramps - Added 04/27/2022 GM, copied from - AP
306+ instruction_by_time = sorted (self .instructions .items ())
307+ for i , (time , instruction ) in enumerate (instruction_by_time ):
308+ if isinstance (instruction , dict ):
309+ if 'initial' in instruction ['description' ]:
310+ if i == 0 :
311+ print ("Don't begin with a ramp without an initial value." )
312+ else :
313+ previous_instruction = instruction_by_time [i - 1 ][1 ]
314+ #### Is the previous instruction a ramp
315+ if isinstance (previous_instruction , dict ):
316+ self .instructions [time ]['function' ] = instruction ['function' ](previous_instruction ['final' ])
317+ #### Is the previous instruction a constant
318+ else :
319+ self .instructions [time ]['function' ] = instruction ['function' ](previous_instruction )
320+
304321 # Check if there are no instructions. Generate a warning and insert an
305322 # instruction telling the output to remain at its default value.
306323 if not self .instructions :
@@ -589,19 +606,36 @@ def ramp(self, t, duration, initial, final, samplerate, units=None, truncation=1
589606 "output.\n "
590607 )
591608 else :
592- self .add_instruction (
593- t ,
594- {
595- "function" : functions .ramp (
596- round (t + duration , 10 ) - round (t , 10 ), initial , final
597- ),
598- "description" : "linear ramp" ,
599- "initial time" : t ,
600- "end time" : t + truncation * duration ,
601- "clock rate" : samplerate ,
602- "units" : units ,
603- }
604- )
609+ if initial == None :
610+ self .add_instruction (
611+ t ,
612+ {
613+ 'function' : functions .ramp_without_initial (
614+ round (t + duration , 10 ) - round (t , 10 ), final
615+ ),
616+ 'description' : 'linear ramp without initial' ,
617+ 'initial time' : t ,
618+ 'end time' : t + truncation * duration ,
619+ 'clock rate' : samplerate ,
620+ 'units' : units ,
621+ 'final' : final
622+ }
623+ )
624+ else :
625+ self .add_instruction (
626+ t ,
627+ {
628+ "function" : functions .ramp (
629+ round (t + duration , 10 ) - round (t , 10 ), initial , final
630+ ),
631+ "description" : "linear ramp" ,
632+ "initial time" : t ,
633+ "end time" : t + truncation * duration ,
634+ "clock rate" : samplerate ,
635+ "units" : units ,
636+ 'final' : final
637+ }
638+ )
605639 return truncation * duration
606640
607641 def sine (
0 commit comments