Beispiel #1
0
    def __init__(self):
        com_ports = list(serial.tools.list_ports.comports())
        xy_com_port = "NULL"
        z_com_port = "NULL"

        #detect com ports
        for port in com_ports:
            print(port)
            if XYDEVPORT in port[2]:
                xy_com_port = port[0]
            if ZDEVPORT in port[1]:
                z_com_port = port[0]

        if "NULL" == xy_com_port:
            self.x_axis_device = "NULL"
            self.y_axis_device = "NULL"
            print("Could not find xy-axis device")
        #connects to devices if found
        else:
            port = BinarySerial(xy_com_port)
            self.x_axis_device = BinaryDevice(port, 1)
            self.y_axis_device = BinaryDevice(port, 2)
        if "NULL" == z_com_port:
            self.z_axis_device = "NULL"
            print("Could not find z-axis device")
        else:
            self.z_axis_device = serial.Serial(z_com_port, 115200)
Beispiel #2
0
print "Port Opening..."
port = BinarySerial("/dev/ttyUSB0")
port.timeout = 30

resolution_mm = 0.124023438*1e-3
spd_mm_s = 10
spd_steps = int((spd_mm_s * 1.6384)/resolution_mm)
print spd_steps 

# Device number 0, command number 1.
radius = 100000
steps = 10
theta = (2*3.14159)/steps

device = BinaryDevice(port, 2)
device1 = BinaryDevice(port, 3)

device.send(42, spd_steps)
device1.send(42, spd_steps)

#move to diameteric point so as to avoid negative cos and sin
dia = 2*radius+1000000
resp = device.move_abs(dia)
resp1 = device1.move_abs(dia)
print 'New origin (',resp.data,', ',resp1.data,')'
time.sleep(2)
#move (R,0) relative to diamteric opposite point
#resp = device.move_rel(radius)
#print 'moving to (',resp.data,', ',0,') for theta value = 0'
time.sleep(2)
Beispiel #3
0
 def connect(self):
     self.comport = BinarySerial(self.port)
     self.x_axis = BinaryDevice(self.comport,1)
     self.y_axis = BinaryDevice(self.comport,2)
     self.rot_axis = BinaryDevice(self.comport,3)
Beispiel #4
0
class star_projector:

    def __init__(self, base_directory, config_file, logger=None, simulate=False):
        self.base_directory=base_directory
        self.config_file = self.base_directory + '/config/' + config_file
        self.simulate=simulate

        # set up the log file                                                                 
        if logger == None:
            self.logger = utils.setup_logger(base_directory + '/log/', 'star_simulator')
        else: self.logger = logger

        # read the config file                                                                
        config = ConfigObj(self.config_file)

        # read the config file                                                                
        if os.path.exists(self.config_file):
            config = ConfigObj(self.config_file)
        else:
            self.logger.error('Config file not found: (' + self.config_file + ')')
            sys.exit()

        self.port = config['PORT']
        self.mm_per_step_x = float(config['MM_PER_STEP_X'])
        self.mm_per_step_y = float(config['MM_PER_STEP_Y'])
        self.deg_per_step = float(config['DEG_PER_STEP'])
        self.arcsec_per_mm_x = float(config['ARCSEC_PER_MM_X'])
        self.arcsec_per_mm_y = float(config['ARCSEC_PER_MM_Y'])

        self.theta = float(config['THETA'])
        self.flip = (config['FLIP'] == 'True')

        # in mm
        self.min_x = float(config['MIN_X'])
        self.min_y = float(config['MIN_Y'])
        self.max_x = float(config['MAX_X'])
        self.max_y = float(config['MAX_Y'])

        # convert to step coordinates
        self.min_x_steps = self.min_x/self.mm_per_step_x
        self.min_y_steps = self.min_y/self.mm_per_step_y
        self.max_x_steps = self.max_x/self.mm_per_step_x
        self.max_y_steps = self.max_y/self.mm_per_step_y

        # derive arcsec/step
        self.arcsec_per_step_x = self.mm_per_step_x*self.arcsec_per_mm_x
        self.arcsec_per_step_y = self.mm_per_step_y*self.arcsec_per_mm_y
        
        if not self.simulate:
            self.connect()
            self.home()
            self.move_absolute(x=0.0, y=0.0)

    # Helper to check that commands succeeded.
    def check_command_succeeded(reply):
        """
        Return true if command succeeded, print reason and return false if command
        rejected

        param reply: BinaryReply

        return: boolean
        """
        if reply.command_number == 255: # 255 is the binary error response code.
            print ("Danger! Command rejected. Error code: " + str(reply.data))
            return False
        else: # Command was accepted
            return True

    def get_position(self):
        return (self.x_axis.get_position(), 
                self.y_axis.get_position(),
                self.rot_axis.get_position())
    
    def connect(self):
        self.comport = BinarySerial(self.port)
        self.x_axis = BinaryDevice(self.comport,1)
        self.y_axis = BinaryDevice(self.comport,2)
        self.rot_axis = BinaryDevice(self.comport,3)


    def home(self):
        # this always times out if at the end of range
        self.x_axis.home()
        self.y_axis.home()
        #self.rot_axis.home() # broken

    ''' X/Y motion in arcsec, angle in degrees ''' 
    # TODO: error handling
    def move_relative(self, x=0, y=0, degrees=0, wait=True, mm=False):
        
        if mm:
            x_move = int(round(x/self.mm_per_step_x))
            y_move = int(round(y/self.mm_per_step_y))
        else:
            x_move = int(round(x/self.arcsec_per_step_x))
            y_move = int(round(y/self.arcsec_per_step_y))

        self.x_axis.move_rel(x_move)
        self.y_axis.move_rel(y_move)
        # self.rot_axis.move_rel(degrees/self.deg_per_step)

        # doesn't work for binary library
#        if wait:
#            self.x_axis.poll_until_idle()
#            self.y_axis.poll_until_idle()
#            self.rot_axis.poll_until_idle()

    ''' X/Y motion in arcsec, angle in degrees ''' 
    # TODO: error handling
    def move_absolute(self, x=0.0, y=0.0, degrees=0.0, wait=True, mm=False):

        if mm:
            x_move = int(round((self.min_x_steps + self.max_x_steps)/2.0 + x/self.mm_per_step_x))
            y_move = int(round((self.min_y_steps + self.max_y_steps)/2.0 + y/self.mm_per_step_y))
        else:
            x_move = int(round((self.min_x_steps + self.max_x_steps)/2.0 + x/self.arcsec_per_step_x))
            y_move = int(round((self.min_x_steps + self.max_x_steps)/2.0 + y/self.arcsec_per_step_y))

        if x_move > self.max_x_steps or x_move < self.min_x_steps or y_move > self.max_y_steps or y_move < self.min_y_steps:
            self.logger.error("Requested move beyond bounds")


        self.x_axis.move_abs(x_move)
        self.y_axis.move_abs(y_move)
        #self.rot_axis.move_abs(int(round(degrees/self.deg_per_step)))

        # doesn't work for binary library
#        if wait:
#            self.x_axis.poll_until_idle()
#            self.y_axis.poll_until_idle()
#            self.rot_axis.poll_until_idle()


    ''' 
        impose an asynchronous drift with optional periodic error terms 
        drift_x     -- x drift, in arcsec/sec (or mm/sec if mm=True)
        drift_y     -- y drift, in arcsec/sec (or mm/sec if mm=True)
        drift_rot   -- rotation drift, in deg/sec
        period      -- an array of periods for periodic error, in seconds
                       must be length 1 or match length of amplitude_x
        x_amplitude -- an array of x amplitudes for periodic error, in arcsec
                       must be length 1 or match length of period
        y_amplitude -- an array in y amplitudes for periodic error, in arcsec
                       must be length 1 or match length of period
        t0          -- an array of times, in seconds relative to the start, to start the 
                       periodic error term. 
                       must be length 1 or match length of period        
        this function will also read a correction file (base_directory/guide_correction.txt) 
             to accept corrections (e.g., from the "guider") on top of the drifts
    '''
    def drift(self, drift_x=0.0, drift_y=0.0, drift_rot=0.0, period=[None], amplitude_x=[0.0], amplitude_y=[0.0], t0=[0.0], mm=False):

        if mm:
            x_vel = int(round(drift_x/self.mm_per_step_x))
            y_vel = int(round(drift_y/self.mm_per_step_y))
        else:
            x_vel = int(round(drift_x/self.arcsec_per_step_x))
            y_vel = int(round(drift_y/self.arcsec_per_step_y))

        self.x_axis.move_vel(x_vel)
        self.y_axis.move_vel(y_vel)

        # you wish!
        # but these functions will likely form the basis of the code... 
        #self.x_axis.get_max_speed(unit = Units.NATIVE)
        #self.y_axis.stop()


    '''
        Impose an asycronous drift with a random jitter imposed on top
    '''
    def jitter_drift(self, jitter, drift_x=0.0, drift_y=0.0, mm=False):

        while True:
            if mm:
                x_vel = int(round(np.random.normal(drift_x, jitter)/self.mm_per_step_x))
                y_vel = int(round(np.random.normal(drift_y, jitter)/self.mm_per_step_y))
            else:
                x_vel = int(round(np.random.normal(drift_x,jitter)/self.arcsec_per_step_x))
                y_vel = int(round(np.random.normal(drift_y,jitter)/self.arcsec_per_step_y))

            self.x_axis.move_vel(x_vel)
            self.y_axis.move_vel(y_vel)

            if self.queued_move_x != 0.0 or self.queued_move_y != 0.0:
                self.move_relative(x=self.queued_move_x, y=self.queued_move_y, mm=False)
                self.queued_move_x = 0.0
                self.queued_move_y = 0.0

    '''
        this is meant to be run asynchronously with drift or jitter_drift
    '''
    def guide_xy(self, x=0.0, y=0.0, degrees=0, mm=False):

        # convert to arcsec if necessary, then add to queued move
        if mm:
            self.queued_move_x += x/self.mm_per_step_x*self.arcsec_per_step_x
            self.queued_move_y += y/self.mm_per_step_y*self.arcsec_per_step_y
        else:
            self.queued_move_x += x
            self.queued_move_y += y


#-------------------------------------------------------------------------------
    # these function names emulate dfm_telescope so it can be used as a telescope replacement
    def offset_target_object(self, east, north):
        x = north*math.cos(self.theta*math.pi()/180.0) - east*math.sin(self.theta*math.pi()/180.0)
        y = north*math.sin(self.theta*math.pi()/180.0) + east*math.cos(self.theta*math.pi()/180.0)
        if self.flip: y = -y
        guide_xy(x=x,y=y,mm=False)
        
    def populate_header(self,hdr):

        hdr['TELESCOP'] = ("Star projector","Telescope")
        hdr['SITELAT'] = (42.398067,"Site Latitude (deg)") # CDP
        hdr['SITELONG'] = (-71.149436,"Site East Longitude (deg)") # CDP
        hdr['SITEALT'] = (0.0,"Site Altitude (m)")
        #hdr['RA'] = (ra, "Solved RA (J2000 deg)")
        #hdr['DEC'] = (dec,"Solved Dec (J2000 deg)")
        #hdr['ALT'] = (alt,'Telescope altitude (deg)')
        #hdr['AZ'] = (az,'Telescope azimuth (deg E of N)')
        #hdr['AIRMASS'] = (airmass,"airmass (plane approximation)")
        #hdr['HOURANG'] = (hourang,"Hour angle")
        #hdr['PMODEL'] = ('',"Pointing Model File")
        #hdr['FOCPOS'] = (focus,"Focus Position (microns)")
        #hdr['ROTPOS'] = (rotpos,"Mechanical rotator position (degrees)")
        #hdr['PARANG'] = (parang,"Parallactic Angle (degrees)")
        #hdr['SKYPA' ] = (skypa,"Position angle on the sky (degrees E of N)")

        #hdr['MOONRA'] = (moonra, "Moon RA (J2000 deg)")
        #hdr['MOONDEC'] =  (moondec, "Moon Dec (J2000 deg)")
        #hdr['MOONPHAS'] = (moonphase, "Moon Phase (Fraction)")
        #hdr['MOONDIST'] = (moonsep, "Distance between pointing and moon (deg)")
    
        pass

    def get_objname(self, mask='grid'):
        return "star_projector_mask_" + mask
Beispiel #5
0
def setup_stages():

    global rotary, xAxis, yAxis

    serial_conn = BinarySerial(STAGES_PORT, timeout=None)

    rotary = BinaryDevice(serial_conn, 1)
    xAxis = BinaryDevice(serial_conn, 2)
    yAxis = BinaryDevice(serial_conn, 3)

    xAxis.set_home_speed(mm2lindata(DEFAULT_HOMING_SPEED))
    xAxis.set_home_speed(mm2lindata(DEFAULT_HOMING_SPEED))

    rotary.set_acceleration(20)
    xAxis.set_acceleration(2000)
    yAxis.set_acceleration(2000)

    # rotary.set_max_position

    home_all()
def setup_stages():
    global x_linear, y_linear, z_rotary

    serial_conn = BinarySerial(STAGES_PORT, timeout=None)

    x_linear = BinaryDevice(serial_conn, 2)
    y_linear = BinaryDevice(serial_conn, 3)
    z_rotary = BinaryDevice(serial_conn, 1)

    x_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    # need to  check that mm2rotdata does the right conversion
    #rotary.set_target_speed(mm2rotdata(DEFAULT_ROT_SPEED))
    x_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    x_linear.set_acceleration(LIN_STAGE_ACCELERATION)
    y_linear.set_acceleration(LIN_STAGE_ACCELERATION)
    z_rotary.set_acceleration(ROT_STAGE_ACCELERATION)

    z_rotary.set_min_position(deg2rotdata(ROTARY_MIN_ANGLE))
    z_rotary.set_max_position(deg2rotdata(ROTARY_MAX_ANGLE))

    home_all()
ncol = 5                #Number of columns (maximum) in a row
matrixOffset = 0        #If rows are offset type 0, if rows are inline type 1.
                        # This program assumes it's halfway between each column
## Import functions
from src.moveRow import moveRow
from src.moveCol import moveCol
from zaber.serial import BinarySerial, BinaryDevice
from src.home import home

##hardware and OS setup
with BinarySerial("/dev/ttyUSB0") as port:  # Linux
# with BinarySerial("COM3") as port:         # Windows

# Get a handle for device #1 on the serial chain. This assumes you have a
# device already in Binary 9,600 baud mode at address 1 on your port.
device1 = BinaryDevice(port, 1) # motor on x axis
device2 = BinaryDevice(port, 2) # motor on y axis
device3 = BinaryDevice(port, 3) # motor on z axis


## Home all devices
# Home the device and check the result.
home(device1)
home(device2)
home(device3)

#make window for map
window = rg.TurtleWindow()
marker = rg.SimpleTurtle()

marker.pen = rg.Pen("red",2)
Beispiel #8
0
class Maya:
    #init creates serial connections to devices
    def __init__(self):
        com_ports = list(serial.tools.list_ports.comports())
        xy_com_port = "NULL"
        z_com_port = "NULL"

        #detect com ports
        for port in com_ports:
            print(port)
            if XYDEVPORT in port[2]:
                xy_com_port = port[0]
            if ZDEVPORT in port[1]:
                z_com_port = port[0]

        if "NULL" == xy_com_port:
            self.x_axis_device = "NULL"
            self.y_axis_device = "NULL"
            print("Could not find xy-axis device")
        #connects to devices if found
        else:
            port = BinarySerial(xy_com_port)
            self.x_axis_device = BinaryDevice(port, 1)
            self.y_axis_device = BinaryDevice(port, 2)
        if "NULL" == z_com_port:
            self.z_axis_device = "NULL"
            print("Could not find z-axis device")
        else:
            self.z_axis_device = serial.Serial(z_com_port, 115200)

    #move a device in a specified way/direction
    #@param move_type:
    #   move_rel: move in position steps in the positive or negative position
    #   move_abs: move to the absolution position specified by position
    #       - requires positive position
    #   home: move to the home position of the device
    #@param axis:
    #   x,y, or z
    #@param position:
    #   a positive or negative number indicating direction and distance to move
    def move_dev(self, move_type, axis, position):
        if "z" == axis.lower():
            if "NULL" != self.z_axis_device:
                if "move_abs" == move_type:
                    self.z_axis_device.write(
                        ("MA," + position).encode('ascii'))
                    self.z_axis_device.flush()
                elif "move_rel" == move_type:
                    self.z_axis_device.write(
                        ("MR," + position).encode('ascii'))
                    self.z_axis_device.flush()
                elif "home" == move_type:
                    self.z_axis_device.write("H,".encode('ascii'))
                    self.z_axis_device.flush()
                else:
                    print("ERROR: invalid move type")
            else:
                print("ERROR: z-axis device wasn't found during init")
        elif "y" == axis.lower():
            if "NULL" != self.y_axis_device:
                if "move_abs" == move_type:
                    self.y_axis_device.move_abs(int(position))
                elif "move_rel" == move_type:
                    self.y_axis_device.move_rel(int(position))
                elif "home" == move_type:
                    self.y_axis_device.home()
            else:
                print("ERROR: y-axis device wasn't found during init")
        elif "x" == axis.lower():
            if "NULL" != self.x_axis_device:
                if "move_abs" == move_type:
                    self.x_axis_device.move_abs(int(position))
                elif "move_rel" == move_type:
                    self.x_axis_device.move_rel(int(position))
                elif "home" == move_type:
                    self.x_axis_device.home()
            else:
                print("ERROR: x-axis device wasn't found during init")
        else:
            print("ERROR: invalid axis")
def setup_stages():
    global serial_conn, x_linear, y_linear, z_rotary

    serial_conn = BinarySerial(STAGES_PORT, timeout=None)

    if CONNECT_ROTARY:
        z_rotary = BinaryDevice(serial_conn, 1)
        z_rotary.set_home_speed(degspeed2rotdata(DEFAULT_ROT_SPEED))
        z_rotary.set_target_speed(degspeed2rotdata(DEFAULT_ROT_SPEED))
        z_rotary.set_acceleration(ROT_STAGE_ACCELERATION)

        z_rotary.set_min_position(deg2rotdata(ROTARY_MIN_ANGLE))
        z_rotary.set_max_position(deg2rotdata(ROTARY_MAX_ANGLE))

    x_linear = BinaryDevice(serial_conn, 2)
    y_linear = BinaryDevice(serial_conn, 3)

    x_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_home_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    x_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))
    y_linear.set_target_speed(linspeed2lindata(DEFAULT_HOME_SPEED))

    x_linear.set_acceleration(LIN_STAGE_ACCELERATION)
    y_linear.set_acceleration(LIN_STAGE_ACCELERATION)

    x_linear.disable_manual_move_tracking()
    y_linear.disable_manual_move_tracking()

    home_all()
def device(binaryserial):
    return BinaryDevice(binaryserial, 1)
def test_constructor(binaryserial):
    bd1 = BinaryDevice(binaryserial, 1)
    bd2 = BinaryDevice(binaryserial, 2)
    assert (bd1.number == 1)
    assert (bd2.number == 2)
    assert (bd1.port == bd2.port == binaryserial)