The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

NexStarCtl - API to control NexStar compatible telescopes

SYNOPSIS

 use NexStarCtl;
 
 my $port = open_telescope_port("/dev/XXX"); 
 if (!defined $port) {
	print "Can not open communication port.\n";
	exit;
 }
 
 # check if the mount is aligned
 if (tc_check_align($port)) {
 	print "The telescope is aligned.\n";
 } else {
 	print "The telescope is not aligned.\n";
 }
 
 # Read the stored coordinates of the location
 my ($lon,$lat) = tc_get_location_str($port);
 if (! defined($lon)) {
 	print "Telescope did not respond\n";
 	close_telescope_port($port);
 	exit;
 }
 print "Location coordinates:\n LON=$lon\n LAT=$lat\n";

 my ($date,$time,$tz,$dst) = tc_get_time_str($port);
 # ...
 # Do some other stuff
 # ...
 
 close_telescope_port($port);

DESCRIPTION

This module implements the serial commands supported by the Celestron NexStar hand control. This applies to the NexStar GPS, NexStar GPS-SA, NexStar iSeries, NexStar SE Series, NexStar GT, CPC, SLT, Advanced-VX, Advanced-GT, and CGE mounts.

Communication to the hand control is 9600 bits/sec, no parity and one stop bit via the RS-232 port on the base of the hand control.

For extended example how to use this perl module look in to the distribution folder for nexstarctl/nexstarctl.pl. This program is a complete console tool to control NexStar telesctopes based on NexStarCtl module.

TELESCOPE COMMUNICATION

open_telescope_port(port_name)

Opens a communication port to the telescope by name (like "/dev/ttyUSB0") and returns it to be used in other functions. In case of error undef is returned.

read_telescope(port, len)

Reads data from the telescope. On error or in case less than len bytes are read undef is returned.

write_telescope(port, data)

Writes data to the telescope and the result of write is returned.

close_telescope_port(port)

Closes the communication port to the telescope.

TELESCOPE COMMANDS

tc_check_align(port)

If the telescope is aligned 1 is returned else 0 is returned. If no response received, undef is returned.

tc_goto_rade(port, ra, de)
tc_goto_rade_p(port, ra, de)

Slew the telescope to RA/DEC coordinates ra, de (in decimal degrees). Function tc_goto_rade_p uses precise GOTO. If RA is not in [0;360] function returns -1. If DEC is not in [-90;90] -2 is returned. If no response received, undef is returned.

tc_goto_azalt(port, az, alt)
tc_goto_azalt_p(port, az, alt)

Slew the telescope to AZ/ALT coordinates az, alt (in decimal degrees). Function tc_goto_azalt_p uses precise GOTO. If AZ is not in [0;360] function returns -1. If ALT is not in [-90;90] -2 is returned. If no response received, undef is returned.

tc_get_rade(port)
tc_get_rade_p(port)

Returns the the current telescope RA/DEC coordinates ra, de (in decimal degrees). Function tc_get_rade_p uses precise GET. If no response received, undef is returned.

tc_get_azalt(port)
tc_get_azalt_p(port)

Returns the the currents telescope AZ/ALT coordinates az, alt (in decimal degrees). Function tc_get_azalt_p uses precise GET. If no response received, undef is returned.

tc_sync_rade(port, ra, de)
tc_sync_rade_p(port, ra, de)

Syncs the telescope to RA/DEC coordinates ra, de (in decimal degrees). Function tc_goto_azalt_p uses precise sync. If RA is not in [0;360] function returns -1. If DEC is not in [-90;90] -2 is returned. If no response received, undef is returned.

tc_goto_in_progress(port)

Returns 1 if GOTO is in progress else 0 is returned. If no response received, undef is returned.

tc_goto_cancel(port)

Cancels the GOTO operation. On success 1 is returned. If no response received, undef is returned.

tc_echo(port, char)

Checks the communication with the telescope. This function sends char to the telescope and returns the echo received. If no response received, undef is returned.

tc_get_model(port)

This function returns the mount model as a number. See CELESTRON documentation. If no response received, undef is returned.

tc_get_version(port)

This function returns the mount version as a number. See CELESTRON documentation. If no response received, undef is returned.

tc_get_location(port)

This function returns the stored location coordinates lon, lat in decimal degrees. Negative longitude is WEST. Negative latitude is SOUTH. If no response received, undef is returned.

tc_get_location_str(port)

This function returns the stored location coordinates lon and lat as strings. If no response received, undef is returned.

tc_set_location(port,lon,lat)

This function sets the location coordinates lon, lat in decimal degrees. Negative longitude is WEST. Negative latitude is SOUTH. If the coordinates are invalid -1 is returned. If no response received, undef is returned.

tc_get_time(port)

This function returns the stored time (in unixtime format), timezone (in hours) and daylight saving time(0|1). If no response received, undef is returned.

tc_get_time_str(port)

This function returns the stored date, time (as strings), timezone (in hours) and daylight saving time(0|1). If no response received, undef is returned.

tc_set_time(port, time, timezone, daylightsaving)

This function sets the time (in unix time format), timezone (in hours) and daylight saving time(0|1). On success 1 is returned. If no response received, undef is returned. If the mount is known to have RTC (currently only CGE and AdvancedVX) the date/time is set to RTC too.

tc_get_tracking_mode(port)

Reads the tracking mode of the mount and returns one of the folowing: TC_TRACK_OFF, TC_TRACK_ALT_AZ, TC_TRACK_EQ_NORTH, TC_REACK_EQ_SOUTH. If no response received, undef is returned.

tc_set_tracking_mode(port, mode)

Sets the tracking mode of the mount to one of the folowing: TC_TRACK_OFF, TC_TRACK_ALT_AZ, TC_TRACK_EQ_NORTH, TC_REACK_EQ_SOUTH. If the mode is not one of the listed -1 is returned. If no response received, undef is returned.

tc_slew_fixed(port, axis, direction, rate)

Move the telescope the telescope around a specified axis in a given direction with fixed rate.

Accepted values for axis are TC_AXIS_RA_AZM and TC_AXIS_DE_ALT. Direction can accept values TC_DIR_POSITIVE and TC_DIR_NEGATIVE. Rate is from 0 to 9. Where 0 stops slewing and 9 is the fastest speed.

On success 1 is returned. If rate is out of range -1 is returned. If no response received, undef is returned.

tc_slew_variable(port, axis, direction, rate)

Move the telescope the telescope around a specified axis in a given direction with specified rate.

Accepted values for axis are TC_AXIS_RA_AZM and TC_AXIS_DE_ALT. Direction can accept values TC_DIR_POSITIVE and TC_DIR_NEGATIVE. Rate is the speed in arcsec/sec. For example 3600 represents 1degree/sec.

On success 1 is returned. If no response received, undef is returned.

get_model_name(model_id)

Return the name of the mount by the id from tc_get_model(). If the mount is not known undef is returned.

AUX COMMANDS

The following commands are not officially documented by Celestron. Please note that these commands are reverse engineered and may not work exactly as expected.

tc_get_autoguide_rate(port, axis)

Get autoguide rate for the given axis in percents of the sidereal rate.

Accepted values for axis are TC_AXIS_RA_AZM and TC_AXIS_DE_ALT.

On success current value of autoguide rate is returned in the range [0-99]. If no response received, undef is returned.

tc_set_autoguide_rate(port, axis, rate)

Set autoguide rate for the given axis in percents of the sidereal rate.

Accepted values for axis are TC_AXIS_RA_AZM and TC_AXIS_DE_ALT. Rate must be in the range [0-99].

On success 1 is returned. If rate is out of range -1 is returned. If no response received, undef is returned.

tc_get_backlash(port, axis, direction)

Get anti-backlash values for the specified axis in a given direction.

Accepted values for axis are TC_AXIS_RA_AZM and TC_AXIS_DE_ALT. Direction can accept values TC_DIR_POSITIVE and TC_DIR_NEGATIVE.

On success current value of backlash is returned in the range [0-99]. If no response received, undef is returned.

tc_set_backlash(port, axis, direction, backlash)

Set anti-backlash values for the specified axis in a given direction.

Accepted values for axis are TC_AXIS_RA_AZM and TC_AXIS_DE_ALT. Direction can accept values TC_DIR_POSITIVE and TC_DIR_NEGATIVE. Backlash must be in the range [0-99].

On success 1 is returned. If backlash is out of range -1 is returned. If no response received, undef is returned.

tc_pass_through_cmd(port, msg_len, dest_id, cmd_id, data1, data2, data3, res_len)

Send a pass through command to a specific device. This function is meant for an internal library use and should not be used, unless you know exactly what you are doing. Calling this function with wrong parameters can be dangerous and can break the telescope!

PERIODIC ERROR CORRECTION FUNCTIONS

The following commands are not officially documented by Celestron. Please note that these commands are reverse engineered and may not work exactly as expected.

pec_index_found(port)

Determine if the position index is found and the mount will know from where to start PEC data playback.

If the index is found 1 is returned. If it is not found 0 is returned. In case of an error the function returs undef.

pec_seek_index(port)

This command will move the mount slightly until the position index is found, so that the PEC playback can be started from the correct position. The telescope will not return to the original position when the index is found. The completion of the operation can be checked with pec_index_found().

On success 1 is returned. In case of an error undef is returned.

pec_record(port, action)

Start or stop the recording of periodic error correction data. The action parameter can be PEC_START or PEC_STOP to start or stop the recording. The completion of the recording can be monitored with pec_record_complete(). The data is collected by the mount from the user or auto-guider corrections made during the recording process. This recording can take 10-15 minutes depending on the type of the mount.

On success 1 is returned. If a wrong parameter is provided -1 is returned. In case of an error undef is returned.

pec_record_complete(port)

Check the completion of pec_record().

If recording is complete 1 is returned. If recording is still in progress 0 is returned. In case of an error undef is returned.

pec_playback(port, action)

Start or stop PEC playback. The action parameter can be PEC_START or PEC_STOP to start or stop PEC playback respectively.

On success 1 is returned. If a wrong parameter is provided -1 is returned. In case of an error undef is returned.

pec_get_playback_index(port)

Get the index of the PEC data for the curent mount position in the range form 0 to the value returned by pec_get_data_len() minus 1.

If the index position is not found yet, the function will always return 0. On error undef is returned.

pec_get_data_len(port)

Get the length of the internal register array in which the PEC data is stored.

On error undef is returned.

pec_set_data(port, data)

Upload the periodic error correction data to the mount. The data parameter is a reference to an array with size that matches the value returned by pec_get_data_len(). The values must be in arc seconds.

On success 1 is returned. If the size of the data array does not match the mount data size -1 is returned. If any of the PEC values is too big and can not fit in the internal data format -2 is returned. On other error undef is returned.

pec_get_data(port)

Download the periodic error correction data from the mount. An array with the correction values is returned. The size of the array is equal to the value returned by pec_get_data_len(). The values are in arc seconds.

On error undef is returned.

UTILITY FUNCTIONS

notnum(n)

If "n" is a real number returns 0 else it returns 1.

precess(ra0, dec0, equinox0, equinox1)

Precesses coordinates ra0 and dec0 from equinox0 to equinox1 and returns the caclculated ra1 and dec1. Where ra and dec should be in decimal degrees and equinox should be in years (and fraction of the year).

round(n)

Returns the rounded number n.

d2hms(deg)

Converts deg (in decimal degrees) to string in hours, minutes and seconds notion (like "12h 10m 44s").

d2dms(deg)

Converts deg (in decimal degrees) to string in degrees, minutes and seconds notion (like "33:20:44").

d2dms(deg)

converts deg (in decimal degrees) to string in degrees and minutes notion (like "33:20").

dms2d(string)

converts string of the format "dd:mm:ss" to decimal degrees. If the string format is invalid format, undef is returned.

hms2d(string)

Converts string of the format "hh:mm:ss" to decimal degrees. If the string format is invalid format, undef is returned.

nex2dd(string)

Converts NexStar hexadecimal coordinate string (in fraction of a revolution) of the format "34AB,12CE" to two decimal degree coordinates.

pnex2dd(string)

Converts precision NexStar hexadecimal coordinate string (in fraction of a revolution) of the format "12AB0500,40000500" to two decimal degree coordinates.

dd2nex(deg1,deg2)

Converts coordinates deg1 and deg2 (in decimal degrees) to NexStar hexadecimal coordinate string (in fraction of a revolution) of the format "34AB,12CE".

dd2nex(deg1,deg2)

Converts coordinates deg1 and deg2 (in decimal degrees) to precise NexStar hexadecimal coordinate string (in fraction of a revolution) of the format "12AB0500,40000500".

SEE ALSO

For more information about the NexStar commands please refer to the original protocol specification described here: http://www.celestron.com/c3/images/files/downloads/1154108406_nexstarcommprot.pdf

Some of the undocumented commands are described here: http://www.paquettefamily.ca/nexstar/NexStar_AUX_Commands_10.pdf

AUTHOR

Rumen Bogdanovski, <rumen@skyarchive.org>

COPYRIGHT AND LICENSE

Copyright (C) 2013-2014 by Rumen Bogdanovski

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.4 or, at your option, any later version of Perl 5 you may have available.

The author assumes no liability or responsibility for damage or injury to persons or property arising from any use of this product. Use it at your own risk.