In the last installment, we saw how easy it is to access functions within the KStars and Ekos user interface with the qdbus tool. Now, we’ll use DBUS in a Python program to control Ekos and the Scheduler to give us all we need to automate starting up Ekos once we’ve rolled our roof back. Once started, the Scheduler handles all the functions we need to conduct and automates the observation run.
Let’s take a closer look at the Scheduler. Below, the main Scheduler screen is running with a sample schedule to image M31. To create the test file we will load through DBUS, I manually entered M31 as my target and selected a Sequence (created by the Imaging module and saved as test.esq), which specified camera, exposure, gain, offset, filter, etc. and saved it as test.esl.1
Next, I ensure that Track, Focus, Align, and Guide are checked. When this schedule is executed, the Scheduler will first slew the telescope to where it thinks M31 is and then do a plate solve to determine if the galaxy is indeed in the centre of the field of view. If not, it iterates and refines the position until the object is centred. The Focus module is run next to do an autofocus to ensure the object is in perfect focus. Finally, the Guide module is engaged to start auto-guiding, using the internal guide or PHD22 (“Push Here Dummy 2”), an excellent Open Source guiding tool. Ekos communicates with PHD2 via DBUS, so they are connected seamlessly. And, of course, if you need to do anything connected to auto-guiding in your Python program, PHD2 can be accessed similarly.
To run a schedule in Ekos first we need to connect to the bus and create a couple of objects for Ekos and the Scheduler. We’re using PyDBus3 to make it easy access to DBus.
from pydbus import SessionBus
import time
# Create a DBUS object
bus = SessionBus()
# Connect to the Ekos and Ekos Scheduler objects
try:
ekos=bus.get("org.kde.kstars","/KStars/Ekos")
ekosScheduler=bus.get("org.kde.kstars","/KStars/Ekos/Scheduler")
except:
print("Unable to accesss KStars, please load it.")
exit(-1)
Next, we need to start up Ekos and load a profile. In this case we load the built-in Simulators profile that has everything we need to test.
# Start up Ekos, and load the Simulators profile
ekos.start()
if 'Simulators' in ekos.getProfiles():
ekos.setProfile('Simulators')
else:
print('Error: Simulators profile not present')
Now lets load a Schedule, run it, and print out what the log says. We’ll sleep for 30s to let it run for a bit.
# Load a schedule and start it running
ekosScheduler.loadScheduler('/home/gtulloch/Projects/EKOSProcessingScripts/test.esl')
ekosScheduler.start()
print('Scheduler status is',ekosScheduler.status)
print(ekosScheduler.logText)
time.sleep(30)
The log looks like below, so we can detect keywords and check that everything is working ok if need be:
['2024-02-21T14:22:21 Scheduler started.', '2024-02-21T14:22:21 Scheduler is awake.']
Finally, let’s say we detect rain and need to shut everything down.
# Oh no it's raining! Stop the scheduler and close Ekos
ekosScheduler.stop()
print(ekosScheduler.logText)
ekos.stop()
So that’s all we need! Next time we’ll put it all together into a Master Control Program (TRON FTW!) that will take care of automating the observatory.
The Scheduler file is simply an XML file, so a future task is to build some code that allows me to create or load, edit, and save Scheduler and Sequence files in Python so I can automate target selection.
https://openphdguiding.org/
https://pydbus.readthedocs.io/en/latest/