Converting rotator coordinates to RA-DEC

Hello!

I am using a NexStar Celestron telescope mount with Hamlib and gpredict to make a satellite tracking system. I’m using gpredict to track the coordinates, and then hamlib is sending the coordinates to the telescope mount. However, when my celestron telescope mount receives the alt-az coordinates it interprets them as RA-DEC coordinates. In other words, when gpredict tells the mount to go to 0 degrees altitude, my mount looks at 0 degree right ascension (so it looks up at the celestial equator). Does anyone know how to make the telescope mount lusten for alt-as coordinates or how I could go about converting the coordinates being sent by gpredict into RA-DEC coordinates? Thanks to everyone in advance!

Hi,
The data messages sent by GPredict (it opens a TCP socket) are very simple:

  • “p” for inquiring the current position
  • “P XXX YY” for setting the position (XXX: Azimuth YY: elevation)
  • “S” for stopping the movement (disengage)

Guessing that your telescope is comunicating via a serial port.
Based on that you can write a small program (in Python?) which listen a TCP socket, converts the data then send to your telescope via serial or insert an Arduino in the communication line to do the same job.

I’m actually working on something like that right now, but I can’t figure out the format that gpredict expects to hear. For example, when gpredict says “p”, I know I need to respond with the mount positions, but in what format??? Any help with that part would be hugely appreciated!

After a “set” command, GPredict waits for “RPRT 0\n” which means no error.
After a “p” inquiry, it waits for:
“XXX\n”
“YY\n”
(Azimuth then Elevation in degrees with \n new lines)

If it helps, here is the interesting part of my Arduino code (home made rotator working on an ESP8266 via WIFI)
Simple like that :wink:

        if (client) {
            ESP.wdtFeed();
            incomingByte = client.read();
            str3 = String("\n");

            // Read new data until '\n'
            if (incomingByte == '\n' || incomingByte == '\r') {
                buffer[BufferCnt] = 0;
                if (buffer[0] == 'p') {
                    // Send current absolute position in deg
                    str1 = String(control_az.input, 1);
                    str2 = String(control_el.input, 1);
                    client.print(str1 + str3 + str2 + str3);
                } else if (buffer[0] == 'P' && buffer[1] == ' ') {
                    // Get the absolute position in deg for azimuth
                    rotator.control_mode = position;
                    rawData = strtok_r(Data, " ", &Data);
                    strncpy(data, rawData + 2, 10);
                    char* az = strtok(data, " ");
                    char* el = strtok(NULL, "\0");

                    if (isNumber(az) && isNumber(el)) {
                        control_az.setpoint = atof(az);
                        control_el.setpoint = atof(el);
                        str1 = String("RPRT 0");
                        client.print(str1 + str3);
                    } else {
                        str1 = String("RPRT 1");
                        client.print(str1 + str3);
                    }
                } else if (buffer[0] == 'S') {
                    // Stop Moving
                    rotator.control_mode = position;
                    control_az.setpoint = control_az.input;
                    control_el.setpoint = control_el.input;
                    str1 = String("RPRT 0");
                    client.print(str1 + str3);
                }

                // Clean the buffer
                BufferCnt = 0;
            } else {
                // Fill the buffer with incoming data
                buffer[BufferCnt] = incomingByte;
                BufferCnt++;
            }
        }

So i have my code sending coordinates to predict now, but I send it once after predict says ‘p’. And I send something like ‘090\n30\n’ and then I see it come up in my antenna controller window and then after about half a second it says error. Do I need to continuously send the coordinates, is there something I’m missing? This is my Gpredict log file if it helps, thanks!:

2023/06/01 12:29:32|3|sat_log_init: Session started
2023/06/01 12:29:32|4|sat_cfg_load: Everything OK.
2023/06/01 12:29:32|3|qth_data_read: QTH has no description.
2023/06/01 12:29:32|3|qth_data_read: QTH data: TXST-GS, 29.9000, -97.8669, 182
2023/06/01 12:29:32|3|gtk_sat_module_load_sats: Read 43 out of 43 satellites
2023/06/01 12:29:32|3|mod_mgr_add_module: Added FULLTRACK to module manager (page 0).
2023/06/01 12:29:32|3|qth_data_read: QTH has no description.
2023/06/01 12:29:32|3|qth_data_read: QTH data: TXST-GS, 29.9000, -97.8669, 182
2023/06/01 12:29:32|3|gtk_sat_module_load_sats: Read 10 out of 10 satellites
2023/06/01 12:29:32|3|mod_mgr_add_module: Added Amateur to module manager (page 1).
2023/06/01 12:29:39|3|Loaded new rotator configuration Celestron
2023/06/01 12:29:44|3|Loaded new rotator configuration TEST
2023/06/01 12:30:44|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:45|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:45|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:45|1|rotctld_socket_rw: SIZE ERROR -1 / 15
2023/06/01 12:30:45|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:45|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:45|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:46|1|rotctld_socket_rw: SIZE ERROR -1 / 15
2023/06/01 12:30:46|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:46|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:46|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:47|1|rotctld_socket_rw: SIZE ERROR -1 / 15
2023/06/01 12:30:47|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:47|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:47|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:48|1|rotctld_socket_rw: SIZE ERROR -1 / 15
2023/06/01 12:30:48|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:48|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:48|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:49|1|rotctld_socket_rw: SIZE ERROR -1 / 15
2023/06/01 12:30:49|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:49|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:49|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:49|1|rotctld_socket_rw: SIZE ERROR -1 / 15
2023/06/01 12:30:49|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:49|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:49|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:50|1|rotctld_socket_rw: SIZE ERROR -1 / 2
2023/06/01 12:30:50|1|rotctld_socket_rw: rotctld Socket Down
2023/06/01 12:30:50|1|…/src/gtk-rot-ctrl.c:rotctld_socket_close: Sent 2 bytes but sent -1.
2023/06/01 12:30:50|1|rot_ctrl_timeout_cb: MAX_ERROR_COUNT (5) reached. Disengaging device!

As told earlier, \n is a ‘new line’ character.
Gpredict should see:

90
30

Not
90\n30\n

No, only once after the “p” request

What port do I connect to when talking to hamlib? Using 4533 doesn’t seem to do anything

Your program is supposed to replace hamlib, and listen on the port you defined in gpredict

I can’t replace hamlib, I don’t know the format that my celestron expects to hear. Hamlib takes care of that for me. I’d be down to replace hamlib if I could find out what my telescope mount expects to hear though.

the -t option specifies the port number

It’s weird because if I set the hamlib port to 4533, and then set the rotator interface port in gpredict to 4530, they still communicate. AND my script doesn’t communicate with hamlib for some reason. I send something through port 4533 and nothin happens

Regarding the protocol, I think it’s best to implement both p and +p (extended) to be safe, one never can be certain which version is used by the programs. The extended is also pretty good so you can see that it actually did what was asked.
with telnet localhost 4533

p
250.00
90.00
+p
get_pos:
Azimuth: 250.00
Elevation: 90.00
RPRT 0

The same goes for P and +P

P 240 90
RPRT 0
+P250 90
set_pos: 250 90
RPRT 0

I did make my own simple python function to do this. be ware, it is oversimplified and does not work for all commands.

def hamlib_query(r, cmd):
    r.sendall(bytes(f'+{cmd}\n', encoding='ascii'))
    try:
        data = r.recv(1024).splitlines()
    except TimeoutError:
        return None
    if len(data) < 2:
        print(f'bad response: {data}')
        return None
    if data[-1] != b'RPRT 0':
        print(f'bad report: {data[-1]}')
        return None
    return data[-2].decode().split(':')[1].strip()
1 Like

When I send commands on the localhost:4533 hamlib doesn’t seem to be receiving anything. I am encoding in utf-8, could this be a problem?

try running rotctld in foreground, it will tell you what it receives if it doesn’t recognize the commands.
there’s no newlines between the numbers when sent in the regular format, just space separated like P 0 45\n, and in ascii.
you can also run rigctld with a dummy rotor with rotctld -m 1 -t 4533 -vvvv and skip all the hardware, just for developing.

Hi mattthestrat02,
In order to convert AZ:EL coords to Ra/dec you may use Python libraries.
I have written an application in Python to operate a radiotelescope our association restored in Paris drived by Gpredict…
http://f6bvp.free.fr/tcp396.py
It needs some Python astronomy libraries called by the application and this module :
http://f6bvp.free.fr/coords.py
You may contacte me for additional infos.

Bernard, f6bvp / ai7bg

A post was merged into an existing topic: Starlink coordinates