Skip to content

Instantly share code, notes, and snippets.

@JSchaenzle
Created March 4, 2012 23:50
Show Gist options
  • Save JSchaenzle/1975469 to your computer and use it in GitHub Desktop.
Save JSchaenzle/1975469 to your computer and use it in GitHub Desktop.
Controlling ASCOM devices from Ruby
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!"
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!
@Elvinas
Copy link

Elvinas commented Oct 4, 2014

Hello, Jordan

I'd like to know how is it possible to change this script to make my telescope slew to specified coordinates but by specifying the exact hour and minute when it should do it, so my telescope could slew to object at a certain time.

Thank you in advance for the information you can provide me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment