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

#
# with open ('/Users/klonowe/TissueTesting/app/TissueTesting/Data/TissueTestingInput.xml') as fd:
#     Data_dictionary=xmltodict.parse(fd.read())
#     Data_dictionary=Data_dictionary["TissueTest"]
#
#     root_elements=Data_dictionary["TensileTest"] if type(Data_dictionary["TensileTest"])==list else [Data_dictionary["TensileTest"]]
#     for element in root_elements:
#         var_dim =float((element["InitialLength"]))
#         thick=float(element["Thickness"])

#var_dim= float(input("Enter initial length output from 'Wait' sequence(mm): "))            #initial length
#thick = float(input("Enter sample thickness from OTMS: "))                #from the optical measurement


var_dim= -10.00
#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*var_dim
strain_rate= .20   #mm/second
print ('Move Absolute:  ', str(var_dim-(np.multiply(.02,var_dim))))   #buffer
print ('')
print ('Move Relative for Load 1')
print ('Amplitude stretch NEG  (15% of reference length)   =', var_dim*maxstrain+(np.multiply(.02,var_dim)))
print ('Velocity 20%                 =', np.abs(var_dim*strain_rate))
print ('')
print ('Move Relative for Unload 1')
print ('Amplitude Unload POS     =', np.abs(var_dim*maxstrain))
print ('Velocity 20%             =', np.abs(var_dim*strain_rate))
print ('Move Relative')
print ('Move to zero amplitude of sinusoid  =', str((var_dim*maxstrain)-(amplitude))) # ** #position just before preconditioning
print ('Velocity  =0.100 mm/s')
print ('')
print ('Sinusoidal')
print ('Amplitude 2.5%            = ',str(np.abs(var_dim*.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((var_dim*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))