Ejemplo n.º 1
0
    def __init__(self,
                 noinvertx=1,
                 noinverty=1,
                 GUI_Object=None,
                 jukeboxKWArgs={},
                 noFinishTone=True,
                 **kwargs):
        # noinvertx can take values 1 and -1

        assert noinvertx in (-1, 1), "No invertx can only take -1 or 1"
        assert noinverty in (-1, 1), "No inverty can only take -1 or 1"

        self.controller = micron.Micos(GUI_Object=GUI_Object, **kwargs)
        self.GUI_Object = GUI_Object
        self.noinvertx = noinvertx
        self.noinverty = noinverty
        # Generate filename based on the serial number of the model
        self.serial = self.controller.getSerial()

        self.noFinishTone = noFinishTone

        # define contants
        self.UP, self.RIGHT, self.DOWN, self.LEFT = 0, 1, 2, 3

        # music thread
        self.musicProcess = None
        # jukeboxKWArgs.update({
        # 	"profile": "alarm"
        # })
        self.jukebox = jukebox.JukeBox(**jukeboxKWArgs)  # playmusic = True,
Ejemplo n.º 2
0
from extraFunctions import query_yes_no as qyn

import datetime

# PURELY FOR THE RUDOLPH

_MAINFILENAME = "map-sections/{}.bmp"
_VELOCITIES = [50, 30, 50, 30, 50, 30, 30]
_ESTIMATEONLY = False
# 0 = lines, 1 = Top, 2 = Bottom Right, 3 = Bottom Left

mic = micron.Micos(
    shutterAbsolute=True,
    noHome=True,
    shutter_channel=servos.Servo.LEFTCH,
    stageConfig={
        "xlim": [-10000, 0],
        "ylim": [-10000, 0],
    },
)

testPic = picConv.PicConv(
    filename=_MAINFILENAME.format(1),
    allowDiagonals=True,
    prioritizeLeft=True,
    shutterTime=servos.Shutter.DEFAULT_DURATION,
    yscale=0.5,
    xscale=0.5,
    micronInstance=mic,
    takeoverControl=True,
    flipVertically=True,
Ejemplo n.º 3
0
elif _MODE == "OSCAR":
    testPic = picConv.PicConv(filename=_FILENAME,
                              allowDiagonals=True,
                              prioritizeLeft=True,
                              flipVertically=True,
                              yscale=0.5,
                              xscale=0.5,
                              shutterTime=servos.Shutter.DEFAULT_DURATION
                              # simulateDrawing = True
                              )

    if not _ESTIMATEONLY:
        testPic.controller = micron.Micos(stageConfig={
            "xlim": [-10000, 0],
            "ylim": [-10000, 0],
        },
                                          noHome=True,
                                          shutterAbsolute=True,
                                          shutter_channel=servos.Servo.RIGHTCH)

        testPic.controller.setvel(1000)
        # testPic.controller.send("rm")
        # time.sleep(2)
        # testPic.controller.abort()
        testPic.controller.setpos(0, 0)

        xl = abs(testPic.controller.stage.xlim[1] -
                 testPic.controller.stage.xlim[0])
        yl = abs(testPic.controller.stage.ylim[1] -
                 testPic.controller.stage.ylim[0])
Ejemplo n.º 4
0
import micron

x = micron.Micos()
print(x.getpos())
Ejemplo n.º 5
0
    def draw(self, velocity, **kwargs):
        assert isinstance(velocity,
                          (int, float)), "velocity must be int or float"

        if not isinstance(self.controller,
                          micron.Micos) and self.controller is not False:
            # initialize the stage
            self.controller = micron.Micos(**kwargs)

        gotController = isinstance(self.controller, micron.Micos)

        if gotController:
            if not self.GUI_Object or not self.takeoverControl:
                self.controller.setvel(self.fast_velocity)

                self.controller.shutter.close()

                xlim = abs(self.controller.stage.xlim[1] -
                           self.controller.stage.xlim[0])
                ylim = abs(self.controller.stage.ylim[1] -
                           self.controller.stage.ylim[0])

                try:
                    assert self.shape[0] < ylim, "Image exceed y-limit"
                    assert self.shape[1] < xlim, "Image exceed x-limit"
                except AssertionError as e:
                    raise AssertionError(e)
                except Exception as e:
                    raise RuntimeError(
                        "Did you forget to load self.shape in form of y, x? Error: {}"
                        .format(e))

                # do a rmove to the (0,0) of the image and let the user move the sample to match the (0,0) point
                # checking if the image will exceed limits
                dy, dx = self.shape[0] / 2, self.shape[1] / 2
                self.controller.rmove(x=dx * self.scale["x"],
                                      y=dy * self.scale["y"])

            # Estimate time if not yet estimated
            if self.estimatedTime is None or velocity != self.estimatedVelocity:
                self.estimateTime(velocity=velocity)

            deltaTime = datetime.timedelta(seconds=self.estimatedTime)
            if not self.GUI_Object or not self.takeoverControl:
                print(
                    "Given {} sec / shutter movement:\nEstimated time required  \t {}"
                    .format(self.shutterTime, deltaTime))
                if not qyn("This is the (0,0) of the image. Confirm?"):
                    print("Exiting...")
                    sys.exit(1)

            now = datetime.datetime.now()
            finish = now + deltaTime

            if self.GUI_Object:
                self.OP_Status = "Given {} sec / shutter movement:\nEstimated time required  \t {}, Est End = {}.".format(
                    self.shutterTime, deltaTime, finish)
                self.GUI_Object.setOperationStatus(self.OP_Status)
            else:
                print("Printing starting now \t {}".format(
                    now.strftime('%Y-%m-%d %H:%M:%S')))
                print(
                    "Given {} sec / shutter movement:\nEstimated time required  \t {}"
                    .format(self.shutterTime, deltaTime))
                print("Esimated to finish at \t {}".format(
                    finish.strftime('%Y-%m-%d %H:%M:%S')))

        # SVGCODE
        svgLine = ["M 0,0"]
        svgMap = ["m", "l"]  # 0 = off = m, 1 = on = l
        # / SVGCODE

        # do a rmove to the first point of self.lines from (0,0) of the image
        dy, dx = self.lines[0][0][0], self.lines[0][0][1]

        svgLine.append("m {},{}".format(dx * self.scale["x"],
                                        dy * self.scale["y"]))

        if gotController:
            self.controller.rmove(x=dx * self.scale["x"],
                                  y=dy * self.scale["y"])
            self.controller.setvel(velocity)

        # then we print
        totalLines = len(self.commands)
        for i, cmd in enumerate(self.commands):
            if not self.GUI_Object:
                print(cmd, "{}/{}".format(i + 1, totalLines))
            else:
                self.GUI_Object.setOperationStatus(
                    self.OP_Status +
                    "\nAt Segment {}/{}".format(i + 1, totalLines))

            state = cmd[0]  # laser on state
            rmoves = cmd[1]

            if gotController:
                if state:
                    self.controller.shutter.open()
                else:
                    self.controller.setvel(self.fast_velocity)

            for rmove in rmoves:
                # SVGCODE
                svgLine.append("{} {},{}".format(svgMap[state],
                                                 rmove[1] * self.scale["x"],
                                                 rmove[0] * self.scale["y"]))
                # / SVGCODE
                if gotController:
                    self.controller.rmove(y=rmove[0] * self.scale["y"],
                                          x=rmove[1] * self.scale["x"])

            if gotController:
                if state:
                    self.controller.shutter.close()
                else:
                    self.controller.setvel(velocity)

        if gotController:
            self.controller.shutter.close()

        # SVGCODE
        # PRINT TO SVG
        if self.simulateDrawing:
            import svgwrite

            dl = " ".join(svgLine).strip()

            dwg = svgwrite.Drawing("test.svg",
                                   size=(str(self.shape[1]) + "px",
                                         str(self.shape[0]) + "px"))
            dwg.add(
                dwg.path(d=dl, stroke="#000", fill="none", stroke_width=0.5))
            dwg.save()