
# quick calculation for inputs required for Mach-1
import sys
import numpy as np

from xml.etree import ElementTree as ET

tree= ET.parse('/Users/klonowe/Downloads/Ramp2.xml')
print(tree)
root = tree.getroot()

for child in root:
    print(child.tag, child.attrib)

reflength1= -47.422

#initial length
thick = 2.47  ## from the optical measurement
maxstrain = .15    #The max amount that the material is stretched beyond its initial length
amplitude= .025 * reflength1
strain_rate= .20   #mm/secon
print ('Move Absolute:  ', str(reflength1 - (np.multiply(.02, reflength1))))   #buffer
print ('')
print ('Move Relative for Load 1')
print ('Amplitude stretch NEG  (15% of reference length)   =', reflength1 * maxstrain + (np.multiply(.02, reflength1)))
print ('Velocity 20%                 =', np.abs(reflength1 * strain_rate))
print ('')
print ('Move Relative for Unload 1')
print ('Amplitude Unload POS     =', np.abs(reflength1 * maxstrain))
print ('Velocity 20%             =', np.abs(reflength1 * strain_rate))
print ('Move Relative')
print ('Move to zero amplitude of sinusoid  =', str((reflength1 * maxstrain) - (amplitude))) # ** #position just before preconditioning
print ('Velocity  =0.100 mm/s')
print ('')
print ('Sinusoidal')
print ('Amplitude 2.5%            = ', str(np.abs(reflength1 * .025))) # ** ---> ** lines move rel amp plus sin amp
print('')
print ('Cycles: 1000')
print ('Freq:   2Hz')
print ('')
print ('Move Relative')
print ('Amplitude Unload POS     =', str(abs((reflength1 * maxstrain - amplitude))))


reflength2=float(input("Enter second reference length output from 'Wait' sequence(mm): "))

print ('Move Absolute:  ', str(reflength2-(np.multiply(.02,reflength2))))   #buffer
print ('')
print ('Move Relative for Load 1')
print ('Amplitude stretch NEG  (15% of reference length)   =',  reflength2*maxstrain+(np.multiply(.02,reflength2)))
print ('Velocity 20%                 =', np.abs(reflength2*strain_rate))
print ('')
print ('Move Relative for Unload 1')
print ('Amplitude Unload POS     =', np.abs(reflength2*maxstrain))
print ('Velocity 20%             =', np.abs(reflength2*strain_rate))

tree.write('Ramp2.xml')