示例#1
0
 def water(self):
     whereWater = [] #a list that is going to contain a value for each access point, determining how much water is needed. i.e. if the point is full, the value will be 0
     
     l = self.struct.waterAccessList #this list is read into memory when the program starts. It contains the position of each water access hole, read from potLayout.xml.
     
     self.getTool("soilSensor")  #self explanatory. It gets the soil sensor tool.
     
     for i in l: # for each water access point
         self.goto(i[0], i[1], i[2]+78) # moves the arm to a position above the water access point. The +78 is the length of the soil sensor tool, so the arm needs to go to 78mm above the position, putting the tip of the sensor exactly to the right position.
         sensor = self.waterSensor() # this function checks if the soil sensor has contact with water, so sensor is "True" if there is water at that height.
         
         while sensor == False and self.coords[2] >= -500:           # while the sensor doesn't find water                                                                   <-- !!!INSERT PROPER FLOOR HEIGHT HERE
             s = Sequence("findWater", "green")                      # create a sequence (basically a wrapper for the whole action, to keep the robot from deadlocking)
             s.add(self.move(i[0], i[1], self.coords[2] - 10, 20))   # move down 1cm. (This also implies that the height of the water is measured to an accuracy of 1cm. Since this is not rocket science, this is largely sufficient. You just need to keep it in mind when setting the position of the water access point, as the maximum height needs a little leeway.
             s.add(log("Looking for water.", message_type='info'))   # This log gives absolutely no useful information, but the last action in a sequence always has to be a log, so it HAS to be there.
             send(cp.create_node(kind='execute', args=s.sequence))   # send the sequence to the API. If you want, you can backtrack this through "farmware_tools.py" and "CeleryPy.py". It puts it into a format understandable by farmbot (CeleryScript) and puts it into JSON format before sending it to the API.
                                         
             self.coords[2] -= 10 # This adjusts the robot's position. As it is a pain to get information from the API, we found it easier to internally remember the position, instead of sending a query to the robot each time, to get it.                  
             sensor = self.waterSensor() # reads the sensor again
             self.waiting(2000) # waits two seconds, as the sensor can take a moment sometimes.
         
         whereWater.append(i[2]+78-self.coords[2]) # Adds the level of water that is missing to the list
         #WHILE END
         
     self.putTool("soilSensor") # puts back the soil sensor.
     
     for i in range(len(l)):                         # for each water access point
         if whereWater[i] > 0:                       # if the level in whereWater is > 0 (so if the level of water needed is not nada)
             self.goto(l[i][0], l[i][1], l[i][2])    # go to the access point (This time without the offset for the tool)
             self.waterFall(whereWater[i])           # unleash the water :) The value entered here is in mm. The function "waterFall" (391) transforms this value into seconds. <-- WE NEVER MEASURED THE OUTPUT PER SECOND; SO THE VALUE IN THIS FUNCTION HAS TO BE ADJUSTED!!!
示例#2
0
 def putTool(self, tool):
     l = self.struct.toolList[tool]
     s = Sequence("putTool", "green")
     s.add(self.goto(l[0] - 100, l[1], l[2] - 22))
     s.add(self.move(l[0], l[1], l[2], 50))
     s.add(self.move(l[0], l[1], l[2] + 100, 50))
     s.add(log("Putting back " + tool + ".", message_type='info'))
     send(cp.create_node(kind='execute', args=s.sequence))
     self.coords = [l[0], l[1], l[2] + 100]
示例#3
0
    def reading(self, pin, signal):
        """
            pin : int pin number
            signal : 1 analog   /   0 digital
        """

        #Sequence reading pin value
        ss = Sequence("40", "green")
        ss.add(log("Read pin {}.".format(pin), message_type='info'))
        ss.add(self.read(pin, signal, 'Soil'))
        ss.add(log("Sensor read.", message_type='info'))
        send(cp.create_node(kind='execute', args=ss.sequence))
示例#4
0
 def waiting(self, time):
     try:
         log("Waiting {} ms".format(time), message_type='debug')
         info = send(cp.wait(milliseconds=time))
         return info
     except Exception as error:
         log("Wait --> " + repr(error))
示例#5
0
 def Write(self, pin, val, m):
     """
        pin : int 10 for vaccum (0 up to 69)
        val : 1 on / 0 off
        m   : 0 digital / 1 analog
     """
     info = send(cp.write_pin(number=pin, value=val, mode=m))
     return info
示例#6
0
 def moveRel(self, distx, disty, distz, spd):
     """
     distx:Int ,disty:Int ,distz:Int
     spd :Int
     """
     log("moving " + str(distx) + ", " + str(disty) + ", " + str(distz), message_type='debug')
     info = send(cp.move_relative(distance=(distx, disty, distz), speed=spd))
     return info
示例#7
0
 def getTool(self, tool):
     l = self.struct.toolList[tool]
     s = Sequence("getTool", "green")
     s.add(self.goto(l[0], l[1], l[2]))
     s.add(self.move(l[0] - 100, l[1], l[2], 50))
     s.add(log("Getting " + tool + ".", message_type='info'))
     info = send(cp.create_node(kind='execute', args=s.sequence))
     self.coords = [l[0] - 100, l[1], l[2]]
     return info
示例#8
0
 def move(self, posx, posy, posz, spd):
     """
     posx:Int ,posy:Int ,posz:Int
     spd :Int
     """
     log("going to " + str(posx) + ", " + str(posy) + ", " + str(posz), message_type='debug')
     info = send(cp.move_absolute(location=[posx, posy, posz], offset=[0,0,0], speed=spd))
     self.coords = [posx, posy, posz]
     return info
示例#9
0
 def read(self, pin, mode, label):
     """ pin : int 64 soil sensor
         mode : 0 digital 1 analog
         label : description str
     """
     try:
         info = send(cp.read_pin(number=pin, mode=mode, label=label))
         return info
     except Exception as error:
         log("Read --> " + repr(error))
示例#10
0
 def goto(self, x, y, z):
     s = Sequence("goto", "green")
     s.add(self.move(self.coords[0], self.coords[1], 0, 100))
     s.add(self.move(self.coords[0], y, 0, 100))
     s.add(self.move(x, y, 0, 100))
     s.add(self.move(x, y, z, 100))
     s.add(log("Moved to "+str(x)+", "+str(y)+", "+str(z)+".", message_type='info'))
     info = send(cp.create_node(kind='execute', args=s.sequence)) 
     self.coords = [x, y, z]
     return info
示例#11
0
    def calibrate(self):
        i = 0
        while True and i < 21:
            try:
                s = Sequence("xCalib", "green")
                s.add(self.moveRel(-100, 0, 0, 50))
                s.add(log("Calibrating  x axis.", message_type='info'))
                send(cp.create_node(kind='execute', args=s.sequence))
                i += 1
            except:
                break

        i = 0
        while True and i < 14:
            try:
                s = Sequence("yCalib", "green")
                s.add(self.moveRel(0, -100, 0, 50))
                s.add(log("Calibrating  y axis.", message_type='info'))
                send(cp.create_node(kind='execute', args=s.sequence))
                i += 1
            except:
                break

        i = 0
        while True and i < 4:
            try:
                s = Sequence("zCalib", "green")
                s.add(self.moveRel(0, 0, 100, 50))
                s.add(log("Calibrating  z axis.", message_type='info'))
                send(cp.create_node(kind='execute', args=s.sequence))
                i += 1
            except:
                break
示例#12
0
 def water_off(self):
     wof = Sequence("03", "green")
     wof.add(self.Write(9, 0, 0))
     wof.add(log("Water off ", message_type='info'))
     send(cp.create_node(kind='execute', args=wof.sequence))
示例#13
0
 def water_on(self):
     won = Sequence("02", "green")
     won.add(self.Write(9, 1, 0))
     won.add(log("Water on ", message_type='info'))
     send(cp.create_node(kind='execute', args=won.sequence))
示例#14
0
 def vacuum_off(self):
     off = Sequence("01", "green")
     off.add(log("Vaccum off ", message_type='info'))
     off.add(self.Write(10, 0, 0))
     send(cp.create_node(kind='execute', args=off.sequence))
示例#15
0
 def vacuum_on(self):
     on = Sequence("0", "green")
     on.add(log("Vaccum on ", message_type='info'))
     on.add(self.Write(10, 1, 0))
     send(cp.create_node(kind='execute', args=on.sequence))