Remote control of a Telescope through Linux OS and Arduino controller

Since I was 14 I love Astronomy and I have been working as Amateur Astronomy for the "Osservatorio Astronomico Naturalistico di Casasco" in Italy for quite some time ...

I had experience in controlling the telescope and the dome of this Observatory through Windows XP and some professional software (i.e. MaximDL) but my love for Linux and Open Source projects induced me to start a project to be able to remotely control my amateur telescope while being comfortable sitting in my sofa (instead of being outside getting cold).

This is an ongoing project which I started on October 2016. The object of this post is to keep track and share the results (if any); as the finance are not great and family comes always first, my target is to be able to achieve the below result not spending more than an average of 50£ per month.

October 8 - 2016

Tomorrow will be my birthday and as it was almost 10 years without a telescope I decided to make myself a gift and I bought a Sky-Watcher Explorer 200P on an EQ5 mount. I knew that this mount was probably not the best for the object of this project but I needed a start and for the price I paid on the auction on eBay ... that was a good deal.

My main objective are:

  1. Control my DSLR camera (change camera settings, capture image sequences)
  2. Control my telescope mount (adjust tracking errors by using a guide camera)
  3. Automatically slew the telescope to find DeepSky objects (which means replace the mount... which is the equivalent of 2 years savings ...)
My current equipment:
  1. Newton reflector, Sky-Watcher Explorer 200P
  2. 9x50 finder scope (180 focal length)
  3. Equatorial mount, Sky-Watcher EQ5-PRO
  4. RA-Dec gears with controller (ST4 port, max 16x slew speed)
  5. Canon EOS 350D (Rebel XT DSLR camera)
  6. Logitech C270 webcam HD 720P
  7. Laptop Lenovo T410 - Centos 7
 
October - 2016

No clear sky (just only the 9th of October)... hence I had time to figure out how much mis-aligned were the mirrors and learn how to correct the problem quickly (2 minutes).
I spent some time to learn how to configure my DSLR camera to take astronomy pictures. I discovered that it is not possible to control the shutter speed over 30 seconds just through USB ... you need to use a remote bulb controller or create a special cable (serial cable, then USB converter) to be able to control the shutter through computer ... bad news to me as I paid 70£ for my camera and I should add other 40£ for the cables ... probably I will opt for just wait and upgrade my camera to a Canon EOS 450D which has a bigger display, higher resolution and can be fully controlled through USB.
I installed gphoto2 and DarkTable on Centos 7 and tested them with good results.

During the month I found an existing Linux library to control remote telescope called libindi. The library is client/server style so I can install the server on a small computer (like a Raspberry Pi) and control the server through my laptop remotely.
Before working on my Raspberry Pi (version 1.0b) I installed libindi on my Centos ... with a lot of pain cause of compatibility issues and missing dependencies ... I finally opted to create a virtual machine running the suggested Linux distribution: Ubuntu 15.04 or later (I installed Ubuntu 16.04 LTS). In this way I can create a snapshot of a working setup and be able to always have a running environment.

November 7 - 2016

Finally a clear sky, not the best one but ... who cares ...

I placed my telescope just on the other side of a window close to my small home office, polar aligned using a fantastic app (as my mount as got the South Pole polar finder ...). The App for Android is called "PolarFinder". I setup the equipment and search for some deep sky object.
My idea was to test which was the longest exposure I can achieve using my mount without tracking correction and with an incredibly light polluted sky ... my closest street light is just 5 meters from the observation place with no trees or barriers to create shadows ...
The easiest object would be M13 but ... another issue ... my backyard head North and I have fences on the sides and my house South ... so M13 was already below fences ...
I moved to M103, not a fantastic object but easy to find. The second object I tried was the Andromeda Galaxy (M31-32 and M110). The telescope focal length of 1000mm is really not the ideal for such a wide object but ... I love Andromeda Galaxy and I wished to give it a try.

Results ... going over 10 seconds is not a good idea ... you start to see star trails and the light pollution ... wow ...
Another important setting is the sensibility of the DSLR sensor, which is expressed in ISO (as a comparison with the old cameras). My DSLR can go up to ISO 1600 but it is really not a good idea to set such high sensibility as the sensor reading noise increase considerably.

I was in a rush as it was Monday night and I wished to sleep ... so I forgot to take darks.

Below you may find the pre-processed and post-processed image of M103. The picture is just a 1 shot, 30 second, 800 ISO without any dark and any LPR filter. I am amazed to see how good was the tracking without correction. The image processing consisted in level stretching using GIMP which unfortunately does not handle 16 bit pictures so the color depth is reduced to 8 bits which means no more than 256 grey levels.




Note: the USB cable between the DSLR camera and the laptop should be no more than 5 meters long (better no more than 4 meters) ... I had to stay outside to get pictures ... it was not fun ...

So ... the cheapest solution is to have a powered USB HUB installed close to the telescope and run a cable from the HUB to the laptop. I need a good USB 2.0 HUB ... let start to use part of my 50£ months budget.


November 10 - 2016

Bought an USB HUB (Belkin 4 ports USB 2.0 from Argos ~ 19 pounds ... November budget still have about 30 quids left ...).
Worked on the Ubuntu virtual installation
1) download Ubuntu 16.04
2) installed on VM (Virutal Box) with 2GB RAM, 2 CPU, 16GB disk space
3) installed guest additions - installed host extension pack (to have USB 2.0 support)
4) run update/upgrade of the OS (sudo apt-get update; sudo apt-get upgrade)
5) installed indi full package:
     sudo apt-add-repository ppa:mutlaqja/ppa
     sudo apt-get update
     sudo apt-get install indi-full kstars-bleeding
6) reboot VM
7) installed add-on to kstars (all!)
7) install cart du ciel
8) install ccdciel (require installation of libpasastro)

November 11 - 2016

To test if indi works with the camera (most important if the virtualization forward correctly the DSLR connected through the USB to the Guest VM):
Type (in a terminal): sudo indiserver indi_gphoto_ccd
leave the terminal open; while indiserver is running, openup ccdciel, connect to indiserver and add the camera !! No problem for the DSLR (only issue is that the 350D does not allow to use the USB to set more than 30 sec ... you need to use the BULB connection or to create a special circuit ... as mentioned above)

November 12 - 2016

Still indoor ... the sky is not clear ... or better it has been clear all the day but in the late afternoon ... rain rain ...
So, time to see if I can get my webcam working within the Virtual machine and connected to indiserver.
There is a special device named "WebCam" within the device list in VirtualBox. This allow to have better performance through the USB compare to the traditional USB virtualized driver. The option is called "Webcam passthrough". You need to have the host VirtualBox Extension Pack with the same version of the running VirtualBox (don't make the mistake I did as you will pass hours debugging using strace and reading logs to find out that the issue was just a version mismatch).
The result is not great ... not good to use the webcam for a video-meeting but ... we don't need such frame rate, do we? As the webcam will be used as guide camera, we need to be able to get one picture per second ... really low bit rate ... Following the procedure you need to follow:
a) unplug the webcam
b) start the VM guest
c) plug the webcam
d) remove it from the USB list if it appear there (on the VM tool bar click on device and un-tick the webcam from the list within the USB devices) then add to the device-webcam in the vbox console
e) test the web cam with cheese (yes there is a really easy tool which just open the webcam and allow you to take snapshot and video ... or just use it as a debug tool)
f) start libindi with this command:
   indiserver indi_gphoto_ccd indi_v4l2_ccd
g) tested with kstars ... good if used as a guide camera as you don't need high frame rate but long integration time

It is already midnight ... fortunately my wife is having a night shift (I mean ... not happy she is doing the night shift but at least I will not wake her up when I go to bad and she didn't hear me screaming during the tests and while debugging the Virtual environment).

November 13 - 2016

Next steps will be getting the cables and adaptors to be able to control my mount from indi library ... a total of 25£ more or less including shipment costs ...
a) cable ST4-RS232 (http://astronomiser.co.uk/mcc.htm for ~16 pounds)
b) USB to RS232 converter (from Amazon for ~9 pounds)

While I will be waiting for the above, as the webcam works correctly, I need to:
a) open the webcam and paint the LED to avoid having it illuminating the picture I just took
b) connect the webcam to the findersope and be able to focus it
c) take some night picture

I need also to learn which is the best configuration for the webcam (unfortunately it does not allow many settings but ...).



While searching for any similar experience I found this webpage: http://www.instructables.com/id/Webcam-mod-for-Astrophotography/
This amateur astronomer is using the same webcam I got. He removed the lens of the webcam as he is going to use it on the prime focus of the telescope. I am not doing the same setup. I will use the finder ocular lens and position the camera ideally where normally you place your eyes during observation.

The idea is to use the finder-scope as a guide scope... I know that this is not the best solution but at the moment with restricted budget I cannot affort to buy a 500mm or more guide scope and ... the total weight of the instruments will be higher so the mount will start to show backslash ...
Eventually it is always possible to add a barlow lens to the finderscope... only issue maybe the long length of the resulting optical tube which can bring to flexure.

More than this, possibly the first thing I have to buy next month will be a LPR filter to cut down the light pollution and allow me to take "long" exposure pictures (my next target is to achieve 2 minutes without start trails).

Another possible way to manage the connection of my ST4 port to my guiding system (indi library) is through an Arduino board and a simple and cheap circuitry.

I found this project and I may give it a try...
https://github.com/kevinferrare/arduino-st4

November 14 - 2016

This evening I ordered the electronics component to build the interface between the ST4 and my computer. I will use an Arduino Nano v3 (cost around 40 quids but it include a soldering iron). The components will arive along the week. Next weekend I will be able to build the board and test it. The overall cost of the project is slightly higher compare to the RS232 to ST4 and RS232 to USB but it give me the opportunity to eventually use the same board to control both the mount and the bulb of the camera (to manage the shutter over 30 secs).
While waiting for the hardware I still need to work on the software side, expecially on the image processing.
I have being trying "siril" which is a good image converter and stacking tools but ... it ddoes not handle correctly color pictures (such as the one produced by a DSLR camera).The image processing start with the conversion of the RAW picture from the DSLR camera into the FITS format normally used by professional astronomers.
I prefer a command line tool as I can eventually build my own script odr wrapper to personalize the process, hence I found dcraw which convert raw picture into TIF/PPM and imagemagick (which is already installed on Ubuntu) which can convert TIF into FITS.
Installation:
a) download dcraw from: https://www.cybercom.net/~dcoffin/dcraw/
b) compile the gcc file: "gcc -o dcraw -O4 dcraw.c -lm -DNODEPS"
Basic usage (I still need to learn...):
a) convert RAW file to ppm file using: dcraw original-raw-file
b) convert the ppm file into FITS: convert ppm-file.ppm fits-file.fits
It is important to specify the file extension. After the conversion I tried to open the file using ccdciel ... working.
It is time to go to sleep... next step will be finding a good PDF about pre-processing ... I need to know if you have to stack pictures before or after having applied dark, bias and flat. I also need to know how to create flat and dark-flat in the easiest way (while keeping a scientifically valid result... I still have a degree to onour).


November 15 - 2016

Wow ... in just one day I received the Arduino nano and the connectors board ... just enough to do a couple of tests.
a) Downloaded and installed the Arduino IDE - on the Host computer
b) Configured the OS to enable RW on the /dev/ttyUSB0 used by the board - on the host computer
c) Started the Guest VM and forwarded the USB to the Guest
d) Found an indi implementation of the ASCOM driver for Arduino-ST4 ... the driver does not support GoTo functionality but ... maybe I can help the developer ?
     https://github.com/tliff/indi_ardust4
e) Downloaded and compiled the driver







First feedback: using ccdciel I can see the indi_ardust4 driver listed and I can enable all the options. No way to get it working using Kstars
So at the moment to start indi-server this is the command:
# sudo indiserver indi_gphoto_ccd indi_v4l2_ccd indi_ardust4

There are 2 ways to enable GoTo functionality:
1) using a RT clock board to be able to send a movement command and measure how long to run the command
2) using a rotatory encoder to read the position of the telescope
At least at the moment I think the ways are 2 ... I need to work on this further !

I need to compare the 2 solutions and Google the possible existing projects !

So it is November 16 and this month budget has run out ... I am at 55£.

November 17 - 2016 

Finally even the soldering has arrived and it is time to put together the circuit and give it a try ! As I still don't have a webcam neither a clear sky, I need to create a "sky emulator" ... hence this evening I will spend some time in configuring my IDE and read some C++ code !! Last time I wrote in C++ was about 10 years ago ...

At least the indi library is really good and well documented and the tutorial are really useful. I will start by modifying the ardust4 library adding the calls for the libindi telescope library which contain GoTo functions.

Whenever this is done I need to put together the basic algorithm for GoTo ... that will be tough !!

November  18 to 20 - 2016

That's it .. the board is almost complete ... my friend Andrew reminded me that I was using the wrong side of the board when soldering but ... too late !! Thanks anyway ... Second version will be better !!


I spend most of the weekend free time to fork the ardust4 project into indi_arduinogoto_telescope ! The new project will use the existing low level library  (from ardust4) while creating the goto functionalities.

At the end of the weekend the code was compiling without errors (which is always good) but the driver was not receiving all the communication messages from the library.

My next week free time will be devoted to learn how to use gdb to debug driver issues !!

I use QT as IDE and I found it really powerful.

The INDI library developer is a wonderful person ! He helped me a lot to start the project and to find the reason of the project not compiling.

I did already thanked you in the indi-forum but I wish to thank you here again Jasem !

November 21 - 2016

Thanks to Jasem again ... I got the debugger working and now I can really concentrate in the algorithm cutting down the telescope simulator I am using as a skeleton for my driver.
The ST4 protocol has been developed for tracking purpose not for GoTo so ... it basically has 4 commands ... slew North, South, East and West.
You cannot Park/Unpark, sync or change the slew speed (that has to be done manually on the mount).
So ... as I wish to have Goto ... I need to fully understand the technical limitation and get the best out of it !

No comments:

Post a Comment