Rev 4718 Rev 4722
Line 22... Line 22...
22 sys.exit(1) 22 sys.exit(1)
23   23  
24 elif len(sys.argv) == 2: 24 elif len(sys.argv) == 2:
25 PORT = eval(sys.argv[1]) 25 PORT = eval(sys.argv[1])
26 SPEED = 50 26 SPEED = 50
27 DISTANCE = 5000 27 DISTANCE = 500
28   28  
29 elif len(sys.argv) == 3: 29 elif len(sys.argv) == 3:
30 SPEED = eval(sys.argv[2]) 30 SPEED = eval(sys.argv[2])
31 DISTANCE = 1000 31 DISTANCE = 1000
32   32  
Line 71... Line 71...
71 self.L6470_STEP_MODE =0x16 71 self.L6470_STEP_MODE =0x16
72 self.L6470_ALARM_EN =0x17 72 self.L6470_ALARM_EN =0x17
73 self.L6470_CONFIG =0x18 73 self.L6470_CONFIG =0x18
74 self.L6470_STATUS =0x19 74 self.L6470_STATUS =0x19
75   75  
76 self.Reset() 76 # self.Reset()
77 self.Initialize() 77 # self.Initialize()
78   -  
79   -  
80   -  
81   78  
82 def Reset(self): 79 def Reset(self):
83 'Reset the Axis' 80 'Reset the Axis'
84 self.spi.xfer([0xC0]) # reset 81 self.spi.xfer([0xC0]) # reset
85   82  
Line 87... Line 84...
87 'set default parameters for H-bridge ' 84 'set default parameters for H-bridge '
88 # self.spi.xfer( 0x14) # Stall Treshold setup 85 # self.spi.xfer( 0x14) # Stall Treshold setup
89 # self.spi.xfer( 0xFF) 86 # self.spi.xfer( 0xFF)
90 # self.spi.xfer( 0x13) # Over Current Treshold setup 87 # self.spi.xfer( 0x13) # Over Current Treshold setup
91 # self.spi.xfer( 0xFF) 88 # self.spi.xfer( 0xFF)
92 self.spi.xfer([0x15]) # Full Step speed 89 # self.spi.xfer([0x15]) # Full Step speed
93 self.spi.xfer([0xFF]) 90 # self.spi.xfer([0xFF])
-   91 # self.spi.xfer([0xFF])
94 self.spi.xfer([0xFF]) 92 # self.spi.xfer([0xFF])
95 self.spi.xfer([0x05]) # ACC 93 self.spi.xfer([0x05]) # ACC
96 self.spi.xfer([0x00]) 94 self.spi.xfer([0x00])
97 self.spi.xfer([0x10]) 95 self.spi.xfer([0x10])
98 self.spi.xfer([0x06]) # DEC 96 self.spi.xfer([0x06]) # DEC
99 self.spi.xfer([0x00]) 97 self.spi.xfer([0x00])
Line 105... Line 103...
105 self.spi.xfer([self.L6470_KVAL_DEC]) # KVAL_DEC 103 self.spi.xfer([self.L6470_KVAL_DEC]) # KVAL_DEC
106 self.spi.xfer([0x50]) 104 self.spi.xfer([0x50])
107 # self.spi.xfer([0x18]) # CONFIG 105 # self.spi.xfer([0x18]) # CONFIG
108 # self.spi.xfer([0b00111000]) 106 # self.spi.xfer([0b00111000])
109 # self.spi.xfer([0b00000000]) 107 # self.spi.xfer([0b00000000])
110 self.MaxSpeed(self.maxspeed) 108 # self.MaxSpeed(self.maxspeed)
111 109
112 def MaxSpeed(self, speed): 110 def MaxSpeed(self, speed):
113 'Setup of maximum speed in steps/s. The available range is from 15.25 to 15610 step/s with a resolution of 15.25 step/s.' 111 'Setup of maximum speed in steps/s. The available range is from 15.25 to 15610 step/s with a resolution of 15.25 step/s.'
114 speed_value = int(speed / 15.25) 112 speed_value = int(speed / 15.25)
115 if (speed_value <= 0): 113 if (speed_value <= 0):
Line 163... Line 161...
163 ('SW_F',data[1] & 0x04 == 0x04), #The SW_F flag reports the SW input status (low for open and high for closed). 161 ('SW_F',data[1] & 0x04 == 0x04), #The SW_F flag reports the SW input status (low for open and high for closed).
164 ('BUSY',data[1] & 0x02 != 0x02), 162 ('BUSY',data[1] & 0x02 != 0x02),
165 ('HIZ',data[1] & 0x01 == 0x01)]) 163 ('HIZ',data[1] & 0x01 == 0x01)])
166 return status 164 return status
167   165  
-   166 def GetACC(self):
-   167 # self.spi.xfer([0x29]) # Gotparam command on status register
-   168 self.spi.xfer([0x2D]) # Gotparam command on status register
-   169 data = self.spi.readbytes(1)
-   170 data = data + self.spi.readbytes(1)
-   171 print data
-   172  
168 def Move(self, units): 173 def Move(self, units):
169 ' Move some distance units from current position ' 174 ' Move some distance units from current position '
170 steps = units * self.SPU # translate units to steps 175 steps = units * self.SPU # translate units to steps
171 if steps > 0: # look for direction 176 if steps > 0: # look for direction
172 self.spi.xfer([0x40 | (~self.Dir & 1)]) 177 self.spi.xfer([0x40 | (~self.Dir & 1)])
Line 192... Line 197...
192 def MoveWait(self, units): 197 def MoveWait(self, units):
193 ' Move some distance units from current position and wait for execution ' 198 ' Move some distance units from current position and wait for execution '
194 self.Move(units) 199 self.Move(units)
195 while self.GetStatus()['BUSY']: 200 while self.GetStatus()['BUSY']:
196 pass 201 pass
-   202 print self.GetStatus()
197 time.sleep(0.8) 203 time.sleep(0.8)
198   204  
-   205  
199 def Float(self, hard = False): 206 def Float(self, hard = False):
200 ' switch H-bridge to High impedance state ' 207 ' switch H-bridge to High impedance state '
201 if (hard == False): 208 if (hard == False):
202 self.spi.xfer([0xA0]) 209 self.spi.xfer([0xA0])
203 else: 210 else:
Line 223... Line 230...
223 time.sleep(1) 230 time.sleep(1)
224   231  
225 print "Axis inicialization" 232 print "Axis inicialization"
226 X = axis(spi, 0, 1, MaxSpeed = SPEED) # set Number of Steps per axis Unit and set Direction of Rotation 233 X = axis(spi, 0, 1, MaxSpeed = SPEED) # set Number of Steps per axis Unit and set Direction of Rotation
227   234  
-   235 #X.Reset()
-   236  
-   237 X.GetACC()
-   238  
-   239 exit()
-   240  
-   241 print X.GetStatus()
-   242 time.sleep(1)
-   243  
-   244 print "Setting maximal speed"
228 print X.MaxSpeed(SPEED) # set maximal motor speed 245 print X.MaxSpeed(SPEED) # set maximal motor speed
-   246 print X.GetStatus()
-   247 time.sleep(1)
229   248  
230 #print X.Run(1, 200.456431) 249 print X.Run(1, 20.456431)
-   250 print X.GetStatus()
231 #time.sleep(10) 251 time.sleep(5)
232 252
233 print "Axis is running" 253 print "Axis is running"
234 for i in range(5): 254 for i in range(5):
235 print i 255 print i
236 X.MoveWait(DISTANCE) # move forward and wait for motor stop 256 X.MoveWait(DISTANCE) # move forward and wait for motor stop