コード例 #1
0
class DobotPlating():
    def __init__(self, dobotPort='/dev/ttyUSB0'):
        available_ports = glob('/dev/tty*USB*')  # mask for OSX Dobot port
        if len(available_ports) == 0:
            print('no port /dev/tty*USB* found for Dobot Magician')
            exit(1)

        #self.DobotPort = 'COM4'
        self.DobotPort = dobotPort;

        self.ecRelay = Relay(18);#bcm pin for physical pin 12
        self.pdRelay = Relay(24);#bcm for physical 18
        self.rhRelay = Relay(23);#bcm for physical 16
        self.gripper = ServoGripper(2);
        self.dvc = DigitalVoltControl();

        self.lastCmd = [0,0,0,0]; #x, y, z, r

        print("Setting Port to " + self.DobotPort);
        self.device = Dobot(port=self.DobotPort)
        time.sleep(1)
        if self.device is not None:
            print("Opened connection")

        self.device.speed(60)

        self.z_up = 100
        self.z_down = -70
        #self.RH_Voltage = 2.5;
        #self.PD_Voltage = 1.9;
        #self.EC_Voltage = 4.8;
        
        self.home_xyzr = [215, 0, self.z_up, 0];                    
        global global_status
        global_status = "Rh Electroplating";
    
    def calibrate(self):
        self.device.goHome();

    def isMoveFinished(self):
        euDist = math.pow(self.lastCmd[0] - self.device.x,2) + math.pow(self.lastCmd[1] - self.device.y, 2) + math.pow(self.lastCmd[2] - self.device.z, 2) + math.pow(self.lastCmd[3] - self.device.r, 2);
        euDist = math.sqrt(euDist);
        if(euDist < 2):
            return True;
        else:
            #print("still moving ..");
            return False;
        
    def move_home(self):
        self.move_xy(self.home_xyzr[0], self.home_xyzr[1], self.home_xyzr[2], self.home_xyzr[3], 0.3);

    def move_xy(self, x, y, z, r, duration = 1):
        self.lastCmd = [x, y, z, r];
        self.device.go(x, y, z, r);  #MOVJ
#        time.sleep(duration);
#            print("in is move finished..");
        print("xyzr position: " + str(self.device.x) + ", " + str(self.device.y) + ", " + str(self.device.z) + ", " + str(self.device.r));
   
    def move_xy_linear(self, x, y, z, r, duration = 1):
        self.lastCmd = [x, y, z, r];
        self.device.goMovL(x, y, z, r);  #MOVJ
#        time.sleep(duration);
#            print("in is move finished..");
        print("xyzr position: " + str(self.device.x) + ", " + str(self.device.y) + ", " + str(self.device.z) + ", " + str(self.device.r));
        
    def shake(self, x, y, z, r, shakeDuration, dispStr):
        global global_status;
        t_end = time.time() + shakeDuration;
        tdiff = t_end - time.time();
        while tdiff > 0:
            if(dispStr is not None):
                global_status = dispStr + str(int(tdiff)) + "s"
            self.move_xy(x, y, z + 10, r, 0.1);
            self.move_xy(x, y, z - 10, r, 0.1);
            tdiff = t_end - time.time();
        
    def up_down_beaker(self,id):

        print ("Doing beaker %d now" % (id));
        self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3], 0.3);
        self.move_xy(Beakers[id][0], Beakers[id][1], (self.z_up + self.z_down)/2.0 , Beakers[id][3], 0.3); #adding a mid point so that the Joint motion isn't touching th edges of the beakers
        self.move_xy(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], 0.3);
        dispStr = "Step " + str(id) + ": ";
        while(not self.isMoveFinished()):
            time.sleep(0.01);

        if(id == 1):
            self.ecRelay.on();
            dispStr = dispStr + "EC "
        elif(id == 8):
            self.pdRelay.on();
            dispStr = dispStr + "Pd Solution "
        elif(id == 11):
            self.rhRelay.on();
            dispStr = dispStr + "Rh Solution "
            
        if(id == 1 or id == 8 or id == 11):
            if(id == 11):
                self.shake(Beakers[id][0], Beakers[id][1], self.z_down - 20, Beakers[id][3], Beakers[id][4], dispStr); #x, y, z and shake_duration
            else:
                self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], Beakers[id][4], dispStr); #x, y, z and shake_duration
        else:    
            self.shake(Beakers[id][0], Beakers[id][1], self.z_down, Beakers[id][3], Beakers[id][4], None); #x, y, z and shake_duration
        
        self.ecRelay.off();
        self.pdRelay.off();
        self.rhRelay.off();
        #move up
        
        #shake to drop the excess drops
        #go half way to adjust for MOVJ
        self.move_xy(Beakers[id][0], Beakers[id][1], (self.z_up + self.z_down)/2.0 , Beakers[id][3], 0.3); #adding a mid point so that the Joint motion isn't touching th edges of the beakers
        #self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]);

        self.shake(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3], 2, None);
        
        self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]);
        
        while(not self.isMoveFinished()):
            time.sleep(0.01);
     
    def startProcess(self, EC_Voltage, PD_Voltage, RH_Voltage):
        global process_running
        process_running = True;
        global global_status
        global_status = "Step 1: EC"
        #1
        if(EC_Voltage == 5.6):
            self.dvc.setMaxVoltage();
        else:
            self.dvc.setVoltage(EC_Voltage);
        self.up_down_beaker(1);
        
        #2
        global_status = "Step 2: Dragout"
        self.up_down_beaker(2);
        
        #3
        global_status = "Step 3: Water"
        self.up_down_beaker(3);

        #4
        global_status = "Step 4: Activation"
        self.up_down_beaker(4);
        
        #5
        global_status = "Step 5: Water"
        self.up_down_beaker(5);

        #6
        global_status = "Step 6: Water"
        self.up_down_beaker(6);
        
        #7
        global_status = "Step 7: Water"
        self.up_down_beaker(7);

        #8
        #global_status = "Step 8: Pd Solution"
        #self.dvc.setVoltage(PD_Voltage);
        #self.up_down_beaker(8);
        
        #9
        #global_status = "Step 9: Pd Dragout"
        #self.up_down_beaker(9);
        
        #10
        #global_status = "Step 10: Water"
        #self.up_down_beaker(10);
        
        #11
        global_status = "Step 11: Rh Solution"
        self.dvc.setVoltage(RH_Voltage);
        self.up_down_beaker(11);
        
        #12
        global_status = "Step 12: Rh Dragout"
        self.up_down_beaker(12);
        
        #13 #repeat of beaker 10
        global_status = "Step 13: Water"
        self.up_down_beaker(10);

        #Home
        self.move_home()
        global_status = "Done.."
        process_running = False;
        print("\n DONE \n");
   
    def __del__(self):
        self.device.close();        
        del self.gripper;
        del self.dvc;
        del self.ecRelay;
        del self.pdRelay;
        del self.rhRelay;
        print("Exiting Cleanly..");
コード例 #2
0
class DobotPlating():
    def __init__(self, dobotPort='/dev/ttyUSB0'):
        available_ports = glob('/dev/tty*USB*')  # mask for OSX Dobot port
        if len(available_ports) == 0:
            print('no port /dev/tty*USB* found for Dobot Magician')
            exit(1)
        else:
            dobotPort = available_ports[0]

        #self.DobotPort = 'COM4'
        self.DobotPort = dobotPort

        self.ecRelay = Relay(18)
        #bcm pin for physical pin 12
        self.pdRelay = Relay(24)
        #bcm for physical 18
        self.rhRelay = Relay(23)
        #bcm for physical 16
        self.gripper = ServoGripper(2)
        self.dvc = DigitalVoltControl()

        self.RH_Duration = 60
        self.PD_DURATION = 60

        self.lastCmd = [0, 0, 0, 0]
        #x, y, z, r

        print("Setting Port to " + self.DobotPort)
        self.device = Dobot(port=self.DobotPort)
        time.sleep(1)
        if self.device is not None:
            print("Opened connection")

        self.device.speed()

        self.z_up = 100
        self.z_down = -70
        #self.RH_Voltage = 2.5;
        #self.PD_Voltage = 1.9;
        #self.EC_Voltage = 4.8;

        self.home_xyzr = [215, 0, self.z_up, 0]
        global global_status
        global_status = "Rh Electroplating"

    def calibrate(self):
        global global_status
        response = self.device.setHomeParams(self.home_xyzr[0],
                                             self.home_xyzr[1],
                                             self.home_xyzr[2],
                                             self.home_xyzr[3])
        #if(response):
        #           global_status = "Error..";

        response = self.device.goHome()


#        if(response):
#            global_status = "Error..";

    def isMoveFinished(self):
        global global_step_indicator
        global_step_indicator = "isMoveFinished"

        euDist = math.pow(self.lastCmd[0] - self.device.x, 2) + math.pow(
            self.lastCmd[1] - self.device.y, 2) + math.pow(
                self.lastCmd[2] - self.device.z, 2) + math.pow(
                    self.lastCmd[3] - self.device.r, 2)
        euDist = math.sqrt(euDist)
        if (euDist < 10):
            return True
        else:
            #print("still moving ..");
            return False

    def move_home(self):
        global global_step_indicator
        global_step_indicator = "move_home"
        self.move_xy(self.home_xyzr[0], self.home_xyzr[1], self.home_xyzr[2],
                     self.home_xyzr[3], 0.3)

    def move_xy(self, x, y, z, r, duration=1):
        global global_step_indicator
        global_step_indicator = "move_xy"
        self.lastCmd = [x, y, z, r]
        response = self.device.go(x, y, z, r)
        #MOVJ
        #        if(response):
        #            global global_status
        #            global_status = "Error..";

        #        time.sleep(duration);
        #            print("in is move finished..");
        print("xyzr position: " + str(self.device.x) + ", " +
              str(self.device.y) + ", " + str(self.device.z) + ", " +
              str(self.device.r))

    def move_xy_linear(self, x, y, z, r, duration=1):
        self.lastCmd = [x, y, z, r]
        response = self.device.goMovL(x, y, z, r)
        #MOVJ
        #        if(response):
        #            global global_status
        #            global_status = "Error..";
        #        time.sleep(duration);
        #            print("in is move finished..");
        print("xyzr position: " + str(self.device.x) + ", " +
              str(self.device.y) + ", " + str(self.device.z) + ", " +
              str(self.device.r))

    def shake(self,
              x,
              y,
              z,
              r,
              shakeDuration,
              dispStr,
              dontShake=False,
              doInOut=False):
        global global_step_indicator
        global_step_indicator = "shake "
        global global_status
        t_end = time.time() + shakeDuration
        tdiff = t_end - time.time()
        while tdiff > 0:
            if (dispStr is not None):
                global_status = dispStr + " " + str(int(tdiff)) + "s"
            if (not dontShake):
                self.move_xy(x, y, z + 10, r, 0.1)
                self.move_xy(x, y, z - 10, r, 0.1)
            tdiff = t_end - time.time()

    def shakeHalfUp(self,
                    x,
                    y,
                    z,
                    r,
                    shakeDuration,
                    dispStr,
                    dontShake=False,
                    doInOut=False):
        global global_step_indicator
        global_step_indicator = "shake "
        global global_status
        t_end = time.time() + shakeDuration
        tdiff = t_end - time.time()
        while tdiff > 0:
            if (dispStr is not None):
                global_status = dispStr + " " + str(int(tdiff)) + "s"
            if (not dontShake):
                self.move_xy(x, y, (self.z_up + self.z_down) / 2.0, r, 0.1)
                self.move_xy(x, y, z - 10, r, 0.1)
            tdiff = t_end - time.time()

    def up_down_beaker(self, id, dispStr=None):

        print("Doing beaker %d now" % (id))
        self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3],
                     0.3)
        self.move_xy(Beakers[id][0], Beakers[id][1],
                     (self.z_up + self.z_down) / 2.0, Beakers[id][3], 0.3)
        #adding a mid point so that the Joint motion isn't touching th edges of the beakers
        self.move_xy(Beakers[id][0], Beakers[id][1], self.z_down,
                     Beakers[id][3], 0.3)
        #dispStr = "Step " + str(id) + ": ";

        t_end = time.time() + 25
        while (not self.isMoveFinished()):
            time.sleep(0.01)
            if (time.time() > t_end):
                global global_step_indicator
                global_step_indicator = "timing error.."
                break

        global global_step_indicator
        global_step_indicator = "up_down_beaker " + str(id)

        if (id == 1):
            self.ecRelay.on()
        #    dispStr = dispStr + "EC "
        elif (id == 8):
            self.pdRelay.on()
        #    dispStr = dispStr + "Pd Solution "
        elif (id == 11):
            self.rhRelay.on()
        #    dispStr = dispStr + "Rh Solution "

        if (id == 1 or id == 8 or id == 11):
            if (id == 11):
                self.shake(Beakers[id][0], Beakers[id][1], self.z_down - 10,
                           Beakers[id][3], self.RH_Duration, dispStr)
                #x, y, z and shake_duration
            elif (id == 1):  #dont' shake
                self.shake(Beakers[id][0], Beakers[id][1], self.z_down,
                           Beakers[id][3], Beakers[id][4], dispStr, True)
                #x, y, z and shake_duration
            else:  #this means id is 8 i.e. Pd
                self.shake(Beakers[id][0], Beakers[id][1], self.z_down,
                           Beakers[id][3], self.PD_Duration, dispStr)
                #x, y, z and shake_duration
        else:
            self.shakeHalfUp(Beakers[id][0], Beakers[id][1], self.z_down,
                             Beakers[id][3], Beakers[id][4], None)
            #x, y, z and shake_duration

        global global_step_indicator
        global_step_indicator = "bottom_shake_finished"

        self.ecRelay.off()
        self.pdRelay.off()
        self.rhRelay.off()
        #move up

        #shake to drop the excess drops
        #go half way to adjust for MOVJ
        self.move_xy(Beakers[id][0], Beakers[id][1],
                     (self.z_up + self.z_down) / 2.0, Beakers[id][3], 0.3)
        #adding a mid point so that the Joint motion isn't touching th edges of the beakers
        #self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3]);

        self.shake(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3],
                   2, None)

        self.move_xy(Beakers[id][0], Beakers[id][1], self.z_up, Beakers[id][3])

        global_step_indicator = "excess_shake_finished"

        t_end = time.time() + 25
        while (not self.isMoveFinished()):
            time.sleep(0.01)
            if (time.time() > t_end):
                global global_step_indicator
                global_step_indicator = "timing error.."
                break

        global_step_indicator = "excess_shake_move_finished"

    def startProcess(self, EC_Voltage, PD_Voltage, RH_Voltage, processType,
                     pdTimeToDo, rhTimeToDo):
        global process_running
        process_running = True
        global global_status

        self.RH_Duration = rhTimeToDo
        #if(processType == PROCESS_RH_20):
        #    self.RH_Duration = 20;
        self.PD_Duration = pdTimeToDo

        global_status = "Step 1: EC"
        #1
        if (EC_Voltage == 5.6):
            self.dvc.setMaxVoltage()
        else:
            self.dvc.setVoltage(EC_Voltage)
        self.up_down_beaker(1, global_status)

        #2
        global_status = "Step 2: Dragout"
        self.up_down_beaker(2)

        #3
        global_status = "Step 3: Water"
        self.up_down_beaker(3)

        #4
        global_status = "Step 4: Activation"
        self.up_down_beaker(4)

        #5
        global_status = "Step 5: Water"
        self.up_down_beaker(5)

        #6
        global_status = "Step 6: Water"
        self.up_down_beaker(6)

        #7
        global_status = "Step 7: Water"
        self.up_down_beaker(7)

        #8
        if (processType == PROCESS_RH_PD):
            global_status = "Step 8: Pd Solution"
            self.dvc.setVoltage(PD_Voltage)
            self.up_down_beaker(8, global_status)

            #9
            global_status = "Step 9: Pd Dragout"
            self.up_down_beaker(9)

            #10
            global_status = "Step 10: Water"
            self.up_down_beaker(10)

        #11
        if (processType == PROCESS_RH_PD):
            global_status = "Step 11: Rh Solution"
        else:
            global_status = "Step 8: Rh Solution"
        self.dvc.setVoltage(RH_Voltage)
        self.up_down_beaker(11, global_status)

        #12
        if (processType == PROCESS_RH_PD):
            global_status = "Step 12: Rh Dragout"
        else:
            global_status = "Step 9: Rh Dragout"
        self.up_down_beaker(12)

        #13 #repeat of beaker 10
        if (processType == PROCESS_RH_PD):
            global_status = "Step 13: Water"
        else:
            global_status = "Step 10: Water"
        self.up_down_beaker(10)

        #Home
        self.move_home()
        global_status = "Done.."
        process_running = False
        print("\n DONE \n")

    def __del__(self):
        self.device.close()
        del self.gripper
        del self.dvc
        del self.ecRelay
        del self.pdRelay
        del self.rhRelay
        print("Exiting Cleanly..")