Commits

Elias Bakken committed 187830b

Working of porting to Device Tree

Comments (0)

Files changed (10)

 stl/
 *~
 *.pyc
+libs/PyBBIO
+images/ubuntu/linux-dev
+images/ubuntu/local-files
 
 
-RPATH=/home/root/replicape
-REMOTE=root@10.24.2.105
-
+#RPATH=/home/root/replicape
+#REMOTE=root@10.24.2.124
+RPATH=/root/replicape
+REMOTE=root@10.24.2.85
 
 .PHONY : software firmware eeprom
 

PCB_rev1/Replicape.brd

Binary file modified.

PCB_rev1/Replicape.sch

Binary file modified.
 
 PCA9685_MODE1 = 0x0
 PCA9685_PRESCALE = 0xFE
+DEVICE_TREE = True
 
-pwm = Adafruit_I2C(0x70, 3, False) # Open device
+if DEVICE_TREE:
+	pwm = Adafruit_I2C(0x70, 1, False) # Open device
+else:
+	pwm = Adafruit_I2C(0x70, 3, False) # Open device
+	
 pwm.write8(PCA9685_MODE1, 0x01)    # Reset 
 time.sleep(0.05)				   # Wait for reset
 
 
 You can use and change this, but keep this heading :)
 '''
-import bbio as io
+
+DEVICE_TREE = True
+
+if not DEVICE_TREE:
+    import bbio as io
 
 class Mosfet:
 
     def __init__(self, pin):
         self.pin = pin
-        io.pwmEnable(pin) # Init the Pin to PWM mode
-        io.pwmFrequency(pin, 20000) # Set a frequency, not important for now
+        self.freq = 20000
+        if DEVICE_TREE:
+            pass
+        else:    
+            io.pwmEnable(pin) # Init the Pin to PWM mode
+            io.pwmFrequency(pin, self.freq) # Set a frequency, not important for now
         self.setPower(0.0)
 	
     '''Set duty cycle between 0 and 1'''
     def setPower(self, value):
         self.power = value
-        io.analogWrite(self.pin, int((1.0-value)*256.0))
+        if DEVICE_TREE:            
+            with open(self.pin+"/duty", "w") as f:
+                val = str(int(500000.0*value))                
+                f.write(val)
+        else:
+            io.analogWrite(self.pin, int((1.0-value)*256.0))
 
     '''Set the PWM frequency'''
     def setFrequency(self, freq):
-        io.pwmFrequency(self.pin, freq)
+        self.freq = freq
+        if DEVICE_TREE: 
+            pass
+        else:
+            io.pwmFrequency(self.pin, freq)
 
     ''' return the current power level '''
     def get_power(self):
         return self.power
 
     def close(self):
-        io.pwmDisable(self.pin) # Init the Pin to PWM mode
+        if DEVICE_TREE:
+            pass
+        else:
+            io.pwmDisable(self.pin) # Init the Pin to PWM mode
+		
+
+if __name__ == "__main__":
+    mosfet = Mosfet("/sys/bus/platform/devices/mosfet_ext1.12")    
+    mosfet.setPower(0.5)
+
+
 
 
 import os
-os.system("export LD_LIBRARY_PATH=/usr/local/lib")
 import logging
 import pypruss      					                            # The Programmable Realtime Unit Library
 import numpy as np						                            # Needed for braiding the pins with the delays
         self.ddr_mem_used   = 0  
         self.clear_events   = []       
         self.ddr_lock       = Lock() 
-        self.debug = 0
+        self.debug = 2
     
         self.i = 0
         pypruss.modprobe(0x40000)    			        # This only has to be called once pr boot

software/Replicape.py

 #        sys.exit(0)
 #signal.signal(signal.SIGINT, signal_handler)
 
+DEVICE_TREE = True
+
 class Replicape:
     ''' Init '''
     def __init__(self):
+        print "Replicape initializing"
         # Init the IO library 
         io.bbio_init()
 
         self.steppers = {}
 
         # Init the 5 Stepper motors
-        self.steppers["X"] = SMD(io.GPIO1_12, io.GPIO1_13, io.GPIO2_4,  0, "X")  # Fault_x should be PWM2A?
+        self.steppers["X"] = SMD(io.GPIO1_12, io.GPIO1_13, io.GPIO2_4,  0, "X") 
         self.steppers["Y"] = SMD(io.GPIO1_31, io.GPIO1_30, io.GPIO1_15, 1, "Y")  
         self.steppers["Z"] = SMD(io.GPIO1_1,  io.GPIO1_2,  io.GPIO0_27, 2, "Z")  
         self.steppers["E"] = SMD(io.GPIO3_21, io.GPIO1_7, io.GPIO2_1,  3, "Ext1")
-        self.steppers["F"] = SMD(io.GPIO1_14, io.GPIO1_6, io.GPIO2_3,  4, "Ext2")
+        self.steppers["G"] = SMD(io.GPIO1_14, io.GPIO1_6, io.GPIO2_3,  4, "Ext2")
 
         # Enable the steppers and set the current, steps pr mm and microstepping  
         self.steppers["X"].setCurrentValue(1.0) # 2A
         self.steppers["E"].set_microstepping(2)
 
         # init the 3 thermistors
-        self.therm_ext1 = Thermistor(io.AIN4, "Ext_1", chart_name="B57560G104F") # QU-BD
-        self.therm_hbp  = Thermistor(io.AIN6, "HBP", chart_name="B57560G104F")
+        if DEVICE_TREE:
+            self.therm_ext1 = Thermistor("AIN4", "MOSFET_Ext_1", "B57560G104F") # QU-BD
+            self.therm_hbp  = Thermistor("AIN6", "MOSFET_HBP", "B57560G104F")
+        else:
+            self.therm_hbp  = Thermistor(io.AIN6, "HBP", chart_name="B57560G104F")
 
         # init the 3 heaters
-        self.mosfet_ext1 = Mosfet(io.PWM2B) # PWM2B on rev1
-        self.mosfet_hbp  = Mosfet(io.PWM0C) # PWM0C on rev1 
-        self.mosfet_ext2 = Mosfet(io.PWM2A) # 
+        if DEVICE_TREE:
+            self.mosfet_ext1 = Mosfet("/sys/bus/platform/devices/mosfet_ext1.12")
+            self.mosfet_hbp  = Mosfet("/sys/bus/platform/devices/mosfet_hbp.14")
+            self.mosfet_ext2 = Mosfet("/sys/bus/platform/devices/mosfet_ext2.13")
+        else:
+            self.mosfet_ext1 = Mosfet(io.PWM2B) # PWM2B on rev1
+            self.mosfet_hbp  = Mosfet(io.PWM0C) # PWM0C on rev1 
+            self.mosfet_ext2 = Mosfet(io.PWM2A) # 
+
         # Make extruder 1
         self.ext1 = Extruder(self.steppers["E"], self.therm_ext1, self.mosfet_ext1)
         self.ext1.setPvalue(0.5)
         elif g.code() == "M31":                                     # Set stepper current limit (Propietery to Replicape)
             for i in range(g.numTokens()):                         
                 self.steppers[g.tokenLetter(i)].setCurrentValue(float(g.tokenValue(i)))            
-        elif g.code() == "M84":                                     # Disable all steppers
-            print "Waiting for path planner"
+        elif g.code() == "M84":                                     # Disable all steppers           
             self.path_planner.wait_until_done()
-            print "Path planner done"
             for name, stepper in self.steppers.iteritems():
             	stepper.setDisabled()
         elif g.code() == "M92": 
 D7 = 		 = 0
 '''
 from spi import SPI
-from bbio import *
 from threading import Thread
 import time
 
+DEVICE_TREE = True
+
 # init the SPI for the DAC
-spi2_0 = SPI(2, 0)
+if DEVICE_TREE:
+    spi2_0 = SPI(1, 0)	
+else:
+    spi2_0 = SPI(2, 0)
 spi2_0.bpw = 8
 spi2_0.mode = 1
 # Init the SPI for the serial to parallel
-spi2_1 = SPI(2, 1)
+if DEVICE_TREE:
+    spi2_1 = SPI(1, 1)	
+else:
+    spi2_1 = SPI(2, 1)
 spi2_1.bpw = 8
 spi2_1.mode = 0
 
+DEVICE_TREE = True
+
+if not DEVICE_TREE:
+    from bbio import *
+
 class SMD:
 
     all_smds = list()
         self.pru_num         = -1           # PRU number, if any 
         SMD.all_smds.append(self) 	        # Add to list of smds
 
-        pinMode(stepPin,   0, 0) 	        # Output, no pull up
-        pinMode(dirPin,    0, 0) 	        # Output, no pull up
-        pinMode(faultPin,  1, 0) 	        # Input, no pull up
+        if not DEVICE_TREE:
+            pinMode(stepPin,   0, 0) 	        # Output, no pull up
+            pinMode(dirPin,    0, 0) 	        # Output, no pull up
+            pinMode(faultPin,  1, 0) 	        # Input, no pull up
  						
     ''' Sets the SMD enabled '''
     def setEnabled(self):

software/Thermistor.py

 from temp_chart import *
 from threading import Lock
 
+DEVICE_TREE = True
+
 ''' Represents a thermistor '''
 class Thermistor: 
 
     mutex = Lock()
 
     ''' Init '''
-    def __init__(self, pin, name, chart_name="B57560G104F"):
+    def __init__(self, pin, name, chart_name):
         self.pin = pin
         self.name = name
         # Get the chart and transpose it
 	
     ''' Return the temperature in degrees celcius '''
     def getTemperature(self):	
-        #print "Getting Temp"
-        Thermistor.mutex.acquire()                        # Get the mutex
-        #print "Mutex acquired"
-        try:
-            time.sleep(1)
-            #print "Delay done"
-            adc_val = io.analogRead(self.pin)        # Read the value 		
-            time.sleep(1)
-            print "Got adc value: "+str(adc_val)
-        except:
-            print "Unexpected error:", sys.exc_info()[0]          
-        finally:
-            #print "Releasing mutex"
-            Thermistor.mutex.release()                    # Release the mutex
-        voltage = io.inVolts(adc_val)                     # Convert to voltage
+        if DEVICE_TREE:
+            with open("/sys/devices/ocp.2/thermistors.15/"+self.pin, "r") as f:
+                try:
+                    voltage = 0.001*float(f.read().rstrip())
+                except IOError:
+                    print "Unable to get ADC value"
+                    return 0            
+        else:
+            Thermistor.mutex.acquire()                        # Get the mutex
+            try:
+                time.sleep(0.1)
+                adc_val = io.analogRead(self.pin)        # Read the value 		
+                voltage = io.inVolts(adc_val)                     # Convert to voltage
+            except:
+                print "Unexpected error:", sys.exc_info()[0]          
+            finally:
+                Thermistor.mutex.release()                    # Release the mutex
         res_val = self.voltage_to_resistance(voltage)     # Convert to resistance  
         temperature = self.resistance_to_degrees(res_val) # Convert to degrees
         if self.debug > 1: