Script demo_makeInchwormCSV_py
[hide private]
[frames] | no frames]

Source Code for Script script-demo_makeInchwormCSV_py

 1  from numpy import * 
 2  import sys 
 3   
4 -def inchworm(phi):
5 """Programmatic definition of inchworm gait""" 6 crv = 0.25 7 ass = 0.35 8 crv0 = 0.1 9 W =array([0, -0.75,-2,0,2,0.75]) 10 N = len(W) 11 if phi<0.33: 12 a = (phi-0.33/2)*6 13 res = (-ones(N)*pi*crv - W*a*ass) 14 elif phi>=0.33 and phi<0.66: 15 a = -(phi-0.5)*6 16 b = 1-(phi-0.33)*3 17 res = (-ones(N)*pi*((crv-crv0)*b+crv0) - W*b*ass) 18 elif phi>=0.66: 19 a = -(phi-(1.66/2))*6 20 b = (phi-0.66)*3 21 res = (-ones(N)*pi*((crv-crv0)*b+crv0) + W*b*ass) 22 return res
23 24 if __name__!="__main__": 25 raise "Don't run me" 26 27 # Our modules are oriented in the [1,-1,1,1,-1] directions relative to each 28 # other but we've found that we want the first and last modules to 29 # counter-rotate to get the gait right. 30 signs = array([1,-1,1,1,-1]) 31 sg = -signs 32 sg[0] *= -1 33 sg[-1] *= -1 34 35 # Create the CSV file headings 36 sys.stdout.write('"t","w1","w2","w3","w4","w5"\n') 37 # Sample 300 points, without the final point (since 1 is the same as 0) 38 for phi in linspace(0,1,30,endpoint=False): 39 s = inchworm(phi) 40 line = ("%.3g," % phi) + ",".join( 41 [ "%d" % (18000.0/pi*val) for val in s[1:]*sg ] ) 42 sys.stdout.write(line+"\n") 43 44 sys.stderr.write(""" 45 This program is a quick hack for creating a gait table for an inchworm gait. 46 To use this program, pipe its output into a .csv file 47 """) 48