Skip to content

Instantly share code, notes, and snippets.

@JSchaenzle
Created March 4, 2012 23:50

Revisions

  1. JSchaenzle revised this gist Mar 5, 2012. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions AscomRubyExampleOutput.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    Connected to Filter Wheel!
    Connected to Focuser!
    Connected to Telescope!
    Connected to Camera!
    Unparking telescope…
    Telescope unparked!
    Slewing Telescope to target location… RA = 10.6763720360123, DEC = -3.18055468146352e-015
    Slew Complete! RA = 15.26, DEC = 75.4
    Focuser Position = 22000
    Filter Wheel Positon = 1
    Capturing Image 1…
    Captured Image Successfully!
    Capturing Image 10…
    Captured Image Successfully!
    Focuser Position = 21000
    Filter Wheel Positon = 2
    Capturing Image 1…
    Capturing Image 10…
    Captured Image Successfully!
    Focuser Position = 21500
    Filter Wheel Positon = -1
    Capturing Image 1…
    Captured Image Successfully!
    Capturing Image 10…
    Captured Image Successfully!
    Parking telescope…
    Telescope parked!
    Disconnecting from all devices…
    All devices disconnected
    Process Completed Successfully!
  2. JSchaenzle created this gist Mar 4, 2012.
    90 changes: 90 additions & 0 deletions AscomRubyExample1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,90 @@
    require 'win32ole' # this allows us to create instances of Windows COM objects

    # create instances of each of our drivers
    $filt = WIN32OLE.new("ASCOM.Simulator.FilterWheel")
    $foc = WIN32OLE.new("ASCOM.Simulator.Focuser")
    $tele = WIN32OLE.new("ASCOM.Simulator.Telescope")
    $cam = WIN32OLE.new("ASCOM.Simulator.Camera")

    # a function that disconnects from each connected device
    def DisconnectAllDevices()
    puts "Disconnecting from all devices..."
    # disconnect from each device
    $filt.Connected = false
    $foc.Connected = false
    $tele.Connected = false
    $cam.Connected = false
    puts "All devices disconnected"
    end

    # capture a number of images with a specific exposure time
    def CaptureImages(numImages, expTime)
    for i in 1..numImages
    puts "Capturing Image " << i.to_s << "..."
    #$cam.ExposureMin = expTime
    $cam.StartExposure(expTime, true)
    while(!$cam.ImageReady) do end
    # do something with $cam.ImageArray here, probably save it to disk
    puts "Captured Image Successfully!"
    end
    end

    # connect up to each device
    $filt.Connected = true
    if($filt.Connected) then puts "Connected to Filter Wheel!" end
    $foc.Connected = true
    if ($foc.Connected) then puts "Connected to Focuser!" end
    $tele.Connected = true
    if($tele.Connected) then puts "Connected to Telescope!" end
    $cam.Connected = true
    if($cam.Connected) then puts "Connected to Camera!" end

    # unpark the telescope so that we can move it to our target position
    $tele.Unpark()
    puts "Unparking telescope..."
    while($tele.Slewing) do end
    puts "Telescope unparked!"

    # slew scope to our target location
    puts "Slewing Telescope to target location... RA = " << $tele.RightAscension.to_s << ", DEC = " << $tele.Declination.to_s
    # tracking is a feature of the telescope mount that continuously adjusts the position to compensate for the movement of the stars
    $tele.Tracking = true
    # move the telescope to point to the target position
    $tele.SlewToCoordinates(15.26, 75.4)
    puts "Slew Complete! RA = " << $tele.RightAscension.to_s << ", DEC = " << $tele.Declination.to_s
    # move filter wheel to postion 1
    $filt.Position = 1
    $foc.Move(22000)
    while($foc.IsMoving) do end
    puts "Focuser Position = " << $foc.Position.to_s
    puts "Filter Wheel Positon = " << $filt.Position.to_s
    # capture a set of images
    CaptureImages(10, 2)
    # move filter wheel to postion 2
    $filt.Position = 2
    $foc.Move(21000)
    while($foc.IsMoving) do end
    puts "Focuser Position = " << $foc.Position.to_s
    puts "Filter Wheel Positon = " << $filt.Position.to_s
    # capture a set of images
    CaptureImages(10, 1)
    # move filter wheel to postion 3
    $filt.Position = 3
    $foc.Move(21500)
    while($foc.IsMoving) do end
    puts "Focuser Position = " << $foc.Position.to_s
    puts "Filter Wheel Positon = " << $filt.Position.to_s
    # capture a set of images
    CaptureImages(10, 3)


    # park the telescope
    puts "Parking telescope..."
    $tele.Park()
    while($tele.Slewing) do end
    puts "Telescope parked!"

    # disconnect
    DisconnectAllDevices()

    puts "Process Completed Successfully!"