×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

fully automated telescope control

Sure, let us how it goes!
5 years 7 months ago #28017

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 13
First things first, I upgraded and tested the DBus script to python3 + more recent python binding system for dbus scripting called pydbus (dbus python module is now obsolete):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
from gi.repository import GObject
from gi.repository import GLib
import os
import time
 
# Create a session bus.
from pydbus import SessionBus
bus = SessionBus()
 
# Create an object that will proxy for a particular remote object.
remote_object = bus.get("org.kde.kstars", # Connection name
                        "/KStars/INDI" # Object's path
                       )
 
# Introspection returns an XML document containing information
# about the methods supported by an interface.
print("Introspection data:")
print(remote_object.Introspect())
 
# Get INDI interface
myDevices = [ "indi_simulator_telescope", "indi_simulator_ccd" ]
 
# Start INDI devices
remote_object.start("7624", myDevices)
 
print("Waiting for INDI devices...")
 
# Create array for received devices
devices = []
 
while True:
    devices = remote_object.getDevices()
    if (len(devices) < len(myDevices)):
        time.sleep(1)
    else:
        break;
 
print("We received the following devices:")
for device in devices:
    print(device)
 
print("Establishing connection to Telescope and CCD...")
 
# Set connect switch to ON to connect the devices
remote_object.setSwitch("Telescope Simulator", "CONNECTION", "CONNECT", "On")
# Send the switch to INDI server so that it gets processed by the driver
remote_object.sendProperty("Telescope Simulator", "CONNECTION")
# Same thing for CCD Simulator
remote_object.setSwitch("CCD Simulator", "CONNECTION", "CONNECT", "On")
remote_object.sendProperty("CCD Simulator", "CONNECTION")
 
telescopeState = "Busy"
ccdState       = "Busy"
 
# Wait until devices are connected
while True:
    telescopeState = remote_object.getPropertyState("Telescope Simulator", "CONNECTION")
    ccdState       = remote_object.getPropertyState("CCD Simulator", "CONNECTION")
    if (telescopeState != "Ok" or ccdState != "Ok"):
        time.sleep(1)
    else:
        break
 
print("Connected to Telescope and CCD is established.")
print("Commanding telescope to slew to coordinates of star Caph...")
 
# Set Telescope RA,DEC coords in JNOW
remote_object.setNumber("Telescope Simulator", "EQUATORIAL_EOD_COORD", "RA", 0.166)
remote_object.setNumber("Telescope Simulator", "EQUATORIAL_EOD_COORD", "DEC", 59.239)
remote_object.sendProperty("Telescope Simulator", "EQUATORIAL_EOD_COORD")
 
# Wait until slew is done
telescopeState = "Busy"
while True:
    telescopeState = remote_object.getPropertyState("Telescope Simulator", "EQUATORIAL_EOD_COORD")
    if (telescopeState != "Ok"):
        time.sleep(1)
    else:
        break
 
print("Telescope slew is complete, tracking...")
print("Taking a 5 second CCD exposure...")
 
# Take 5 second exposure
remote_object.setNumber("CCD Simulator", "CCD_EXPOSURE", "CCD_EXPOSURE_VALUE", 5.0)
remote_object.sendProperty("CCD Simulator", "CCD_EXPOSURE")
 
# Wait until exposure is done
ccdState       = "Busy"
while True:
    ccdState = remote_object.getPropertyState("CCD Simulator", "CCD_EXPOSURE")
    if (ccdState != "Ok"):
        time.sleep(1)
    else:
        break
 
print("Exposure complete")
 
# Get image file name and open it in external fv tool
fileinfo = remote_object.getBLOBFile("CCD Simulator", "CCD1", "CCD1")
print("We received file: ", fileinfo[0], " with format ", fileinfo[1], " and size ", fileinfo[2])
 
print("Invoking fv tool to view the received FITS file...")
# run external fits viewer
command = "fv " + fileinfo[0]
os.system(command)
 
print("Shutting down INDI server...")
# Stop INDI server
remote_object.stop("7624")

That may be useful for people trying to use your example script from the documentation.
The following user(s) said Thank You: Jasem Mutlaq, Gonzothegreat
Last edit: 5 years 7 months ago by dolguldur.
5 years 7 months ago #28031

Please Log in or Create an account to join the conversation.

I think we really need a new up-to-date tutorial on this topic. Can you please write a guide on this so we can publish here to benefit all users?
5 years 7 months ago #28061

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 13
Yes, as I am currently exploring this topic, I can definitely try to write at least a small summary of the features accessible through DBus scripting.
Do you know where I should put that ? / in which format I should edit it ?

For now I see 3 main topics that can be interesting:

Indi DBus scripting
For now, I think the previous code that shows how to acquire an image and make basic use of INDI DBus interface is already a good introduction to this topic.

Scripting KStars, as a planetarium engine,through DBus
I did not tried to use this feature, as I try to rely on astropy to get ephemeride related data. but it could be interesting to show how to setup an observer position, time, and export a view in a script.
I did not saw where was the documentation for this, but it looks like Introspection already gives what's needed for a short example.
I guess the SimClock module should be introduced here.

Using Ekos features through DBus
That is my main point of interest, and the module documentation here helps a lot: api.kde.org/extragear-api/edu-apidocs/kstars/html/modules.html
However, there are still things that I need to understand.

Question 1: Related to this page: api.kde.org/extragear-api/edu-apidocs/ks...osDBusInterface.html
I don't understand how to get this object through the bus, for me, the following code:
from pydbus import SessionBus
bus = SessionBus()
ekosmanager = bus.get("org.kde.kstars","/KStars/EkosManager")
Result in the following error:
Apparently EkosManager does not exist ? However Ekos exist and doesn't looks like it is documented. ?

Question 2:
I managed to somehow start indi client, whithout needing to connect every Devices using INDIDBus interface thanks to something like this:
ekos = bus.get("org.kde.kstars","/KStars/Ekos")
ekos.connectDevices()
ekos.start()

However, I guess it worked only because there was a default profile already loaded somwhere (and I was able to set a specific existing profile thanks to ekos.setProfile("profilename")). But I don't know how to programaticaly create such profile.

Question 3:
I am working on setting up a fully automated focusing routine. I was surprised how easy it was to get something close to that (I'll share the code when it will work), with a few lines of DBus that starts with:
autofocuser = bus.get("org.kde.kstars","/KStars/Ekos/Focus")

However, there are manyy subteleties that I was not able to implement:
-Whenever I launched ekos.start(), how can I synchronize to the end of the startup, when the object is ready to handle submodule (focus, alignment, etc...)
-After setting up some parameters, and launching with autofocuser.start(), I would also like to be able to put a callback on every iterations to monitor HFR, and logs in my own app, and especially, be able to synchronize with the end of the process, how should I do ?
-It looks like many parameters from the GUI are not accessible through DBus (suspend guiding checkbox, number of frames,... )

Question 4:
When I press Ctrl+b, I was expecting to find all the content exposed in the DBus documentation. However, I only see KStars and SimClock module, is it normal ?

Thank you in advance for your help
The following user(s) said Thank You: Jasem Mutlaq, Gonzothegreat
Last edit: 5 years 7 months ago by dolguldur.
5 years 7 months ago #28063

Please Log in or Create an account to join the conversation.

Great! The content can be submitted as an article (indilib.org/create-article.html). Though I think you bring up very good points. When I coded the DBus a couple of years ago, I wasn't aware of DBus properties/signals, so for KStars 3.0.0, I believe a complete restructuring should be in order where they can be divided into Properties/Methods/Signals.

I highly recommend using qdbusviewer since it lists all the DBus tree quite nicely.

1. There is no EkosManager path, it's /KStars/Ekos
2. Currently, there is no way to programatically create a profile. I also don't see it as high priority, why would you want to create a profile on the fly? Usually, you have a list of profiles and you select which one you're interested in running.
3. Goods points. I think I need to implement signals here to indicate when the modules are ready, and also to emit the HFR progress.
4. Sorry not following .. Ctrl+B where? KStars provides several object paths (e.g. /KStars, /KStars/INDI, /KStars/Ekos/Align ..etc) and each path has one or more interface (e.g. /KStars/Ekos/Align has interface org.kde.kstars.Ekos.Align which is a collection you methods you can call)

I'll start working tomorrow on revamping the KStars DBus interface. So if you can compile from GIT, that would be great so you can keep up with the latest changes and get your feedback accordingly.
The following user(s) said Thank You: dolguldur
5 years 7 months ago #28070

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 13
Awesome !

Thank you very much Jasem for your commitment ! being able to use Ekos directly from scripts is my dream feature, (I started doing nice things with python bindings of Indi, but I really had to get my hands dirty to understand that I would never be able to build a software as powerful and an robust as Ekos on my own, even if I only need a subset of its features).

I will now switch to the dev version of KStars in order to be able to test the latest features to come

Edit, in question 4, I was talking about the KStars shortcut Ctrl+B that open the script builder window (see enclosed image)
Edit2: Thank you for the tips regarding qdbusviewer, it is a really nice tool (part of qttools5-dev-tools package in ubuntu)
Last edit: 5 years 7 months ago by dolguldur.
5 years 7 months ago #28075
Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 2247
  • Thank you received: 223
@dolguldur @Jasem
I shall be following this thread with great interests, as I would like to control my remote observatory from scripts alone with having to use Ekos.
My aim is to be able to choose a target (script can query a database and find out the coordinates), unpark, slew/track, focus, guide, snap, park, close observatory.
5 years 5 months ago #30398

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 13
First, I wanted to apologize for being late on working on this dbus scripting tutorial.
If you are interested in building your own python app to automate your observations, there are multiple choices of course, as you probably know, because you can either use pyIndi bindings, or dbus scripting.

In my case, I wanted to start on a pure pyIndi code, but I soon realized, that although it was very cool to use pyIndi to automate some acquisition/slew task, writing my own focuser or guider app, would have been quite a bit of work, and probably not as robust as already existing software.

I am now in the process of trying to see if it is possible to integrate easily my pyIndi code with debus scripting ekos functionalities (because ekos wants to run its own indi server it seems ?) and also because there is no interoperbility between pyIndi devices, and dbus scripting classes apparently (but I am not entirely sure though).

In terms of what you want to do, mabe you know that much more than I do, but in case, let me provide you with links to opensource code that people used for operating automated astronomy:

-A very cool wrapper for pyIndi devices:
github.com/GuLinux/indi-lite-tools/tree/...d76b/pyindi_sequence

-Use python native http astrometry client:
github.com/dstndstn/astrometry.net/tree/master/net/client

-wrap astrometry server in a docker that you can run on a more beefy machine:
github.com/dstndstn/nova-docker

-inspirational project for fully automated observatory, that implements nearly everything you need: astrometry, focusing, databases, scheduling,..., but guiding (as far as I know but it may be included):
github.com/panoptes/POCS

-very cool project that includes a 3D rendering engine based on pyqt5, to show what your (stl-modeled) telescope looks like
github.com/geehalel/npindi

I tried to mix up all these differents projects to have something fun to do, and maybe useful in the future, but I still have a long way to go. And deciding how to integrate ekos with dbus scripting is not necessarily an easy thing to do for me, as there are already multiple modules that I wrote (and don't want to get rid of, for now), and that are already there in Ekos.

In practice, the biggest obstacle I see with the dbus scripting approach, is that it might end-up just being a way to manipulate the interface, but not the underlying object with a good granularity (for instance, attaching callback upon blob reception, of stuff like this) that pyIndi does offer.
I still have to investigate dbus scripting more thoroughly, but all comments or answer, feeback on this are welcome.
The following user(s) said Thank You: Gonzothegreat, Stephen Wong, Josh Walawender
5 years 5 months ago #30401

Please Log in or Create an account to join the conversation.

Time to create page: 0.297 seconds