Commit Graph

2187 Commits

Author SHA1 Message Date
Don Cross
c247250df7 C Windows: use GetSystemTimePreciseAsFileTime.
It turns out that GetSystemTimeAsFileTime only returns
time with millisecond resolution.
In order to get microsecond resolution in Astronomy_CurrentTime(),
I had to switch to GetSystemTimePreciseAsFileTime for Windows.

Example output from unit test:

C Test_AstroTime: PASS - realtime increment = 3.143e-07 seconds after 1 iterations.
2023-08-28 14:32:43 -04:00
Don Cross
dd0245cbf8 C: Astronomy_GetCurrentTime supports microsecond resolution.
This is a follow-up to work provided by:
Eric Wheeler, KJ7LNW <astronomy-git@z.ewheeler.org>

Before now, the C function Astronomy_GetCurrentTime returned
the current time from the system clock, but only with whole
second resolution. Now it supports microsecond resolution on
Linux/Unix, Mac OS, and Windows.

For unsupported platforms, a compiler error will occur
to indicate that microsecond resolution is not available.
However, it is possible to define one of the following two
preprocessor symbols to work around the compiler error:

1. ASTRONOMY_ENGINE_NO_CURRENT_TIME
   Excludes the function Astronomy_CurrentTime from the build.
   If your project does not need to obtain the current time,
   or your hardware platform does not provide current date
   and time in the first place, this is likely the better option.

2. ASTRONOMY_ENGINE_WHOLE_SECOND
   If your project does need to use the current date and time
   for astronomy calculations, and it can tolerate whole
   second resolution, this option provides a version of
   Astronomy_CurrentTime that uses a call to `time(NULL)`.

Notes:

- Added unit test to confirm at least millisecond resolution.
  Because these tests have to run on GitHub Actions cloud platform,
  and those systems can be heavily CPU-loaded, I want to be tolerant
  of resolution and avoid false failures.

- Added detection of Mac platform.

- Added preprocessor options documented above.

- On Windows, use ULARGE_INTEGER and eliminated one integer division.

- Added comments and developer documentation.

- Converted tabs to spaces in astronomy.c, for consistent code format.
2023-08-28 12:24:20 -04:00
Eric Wheeler
311a0cca59 Support microsecond time resolution
This patch adds support for microsecond time resolution on the UNIX and
WIN32 platforms.

Implementation details:

Previously, the `Astronomy_CurrentTime()` function used `time(NULL)` to
get the current time, thus providing 1-second resolution.  This patch
uses `gettimeofday()` for UNIX and `GetSystemTimeAsFileTime()` for WIN32
platforms.  If neither are supported, it will fall back to `time()` and
issue a #warning.  (Note that windows.h defines ARRAYSIZE, which may or
may not be compatible.  Thus, the internal define `ARRAYSIZE` is renamed
to `ASTRO_ARRAYSIZE`.)

The UNIX code was tested in Linux, and in arm-eabi-none under newlib.
The WIN32 code was tested using MinGW/64 under WINE.

Use case:

One-second resolution is enough in most cases.  However, there are cases
where higher resolutions are desirable.  For example:

We are using the astronomy.c library to control a mechanical rotor to
track celestial objects (planets, stars, and satellites).  The rotor
controller uses a PID controller with 100 tick/sec updates, and tracks
the velocity of the azimuth and elevation angles from the previous tick.
With 1-second resolution, the PID controller jerks and oscillates once
per second as it adjusts to the new position.  With at least
10-millisecond resolution (100/sec), it can calculate the per-tick
velocity change and track smoothly with far less jitter.

More information about the project:
	Source using astronomy.c:
	    https://github.com/KJ7NLL/space-ham

	Lego-controlled az/el:
	    https://youtu.be/vrlw4QPKMRY

	Lego-controlled telescope focus:
	    https://youtu.be/p-5dOQG95xg

	APID+SMC control algorithm:
		https://doi.org/10.1016/j.precisioneng.2022.01.006

Signed-off-by: Eric Wheeler, KJ7LNW <astronomy-git@z.ewheeler.org>
Tested-by: Zeke Wheeler, KJ7NLL <kj7nll@gmail.com>
2023-08-27 18:22:58 -07:00
Don Cross
8dc66a8610 Fixed search failure in moon_north_south.js demo.
It was possible for certain starting times to have a search
failure in this demo, because it could place more than
one zero-crossing of the function in the same time interval.
So now we iterate over an interval of 10 days at a time
until we find the solution.
2023-08-23 13:55:35 -04:00
Don Cross
4007023422 Forgot to include JPL Horizons batch data.
I wanted to record the exact settings I used
to generate the JPL Horizons data used to verify
my calculations of the Moon's extreme declinations.
2023-08-22 21:33:07 -04:00
Don Cross
cea0158558 Added JS demo: moon_north_south.
This demo shows how to search for the next time
the Moon reaches extreme ecliptic latitude or
extreme declination. In other words, it finds
when the Moon reaches the farthest north or south,
expressed in either ecliptic coordinates or equatorial
coordinates.

Both angles are measured using the Earth's equator of date.
2023-08-22 21:30:40 -04:00
Don Cross
63ed3746b2 Misc fixes for Raspberry Pi 4 build.
On the Raspberry Pi 4, using latest versions of cppcheck
and pylint, a few more minor fixes were needed for eliminating
warnings.

Also had to soften a tolerance for the Kotlin unit tests.
2023-06-19 16:28:34 -04:00
Don Cross
7cf1a7eb7d Minor tweaks for cppcheck. Use const pointers for grav sim.
Slightly different cppcheck dev 2.11 behaviors have added
another warning that I don't care about. I don't want to
have to convert callback pointers to const, then cast them
to const.

However, it did find a couple of useful cases I fixed in
astronomy.c where GravSim parameters could be made const.
2023-06-19 12:37:39 -04:00
Don Cross
bb27adfdfa Update C# demo/test projects to dotnet core 7. 2023-06-18 21:04:33 -04:00
Don Cross
fda8426972 Another attempt to build altazsearch.cpp on Mac OS. 2023-06-18 17:44:02 -04:00
Don Cross
890fcf8d3e Fix build problem for altazsearch.cpp on Mac.
The following build error occurred in Mac OS:

Compiling altazsearch.cpp
clang: error: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Werror,-Wdeprecated]

Added options to explicitly perform mixed C/C++ programming.
2023-06-18 17:05:07 -04:00
Don Cross
33de407723 Added C++ demo for alt/az window search.
See the following discussion for context:

https://github.com/cosinekitty/astronomy/discussions/308

Added a demo program that shows how to search for when
a body enters a window defined in terms of an observer's
horizontal frame of reference, given a range of altitudes
and a range of azimuths.
2023-06-18 16:14:52 -04:00
Don Cross
9495e4e45f Fixed warning in top2013.c: unnecessary variable assignment.
The newer version of cppcheck reported that I was assigning
a value to a variable that was never used before another
assignment occurred. Fixed this to eliminate the warning.
2023-06-16 21:19:17 -04:00
Don Cross
e3fc95a2fb Use fixed version of star data in Windows build. 2023-04-10 21:35:30 -04:00
Don Cross
04afcf6e91 Handle another update to hygdata_v3.csv.
The star database changed again, which causes my hash check
to fail. This time I locked on to the specific commit of the
file, so my build process won't break if it is changed again.
2023-04-10 19:56:14 -04:00
dependabot[bot]
37f7d9f4b3 Bump xml2js from 0.4.19 to 0.5.0 in /generate/hydrogen
Bumps [xml2js](https://github.com/Leonidas-from-XIV/node-xml2js) from 0.4.19 to 0.5.0.
- [Release notes](https://github.com/Leonidas-from-XIV/node-xml2js/releases)
- [Commits](https://github.com/Leonidas-from-XIV/node-xml2js/compare/0.4.19...0.5.0)

---
updated-dependencies:
- dependency-name: xml2js
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-10 21:54:38 +00:00
Don Cross
5faccc9920 cppcheck: verify more source files. 2023-03-26 06:59:27 -04:00
Don Cross
69311b3ccf Adjusted cppcheck options and fixed more warnings. 2023-03-26 06:47:09 -04:00
Don Cross
37a0c44c9b Fixed uninitialized struct in C tests. 2023-03-25 15:34:03 -04:00
Don Cross
501c19015b Run cppcheck. Fixed errors in C code found by cppcheck. 2023-03-25 14:46:42 -04:00
Don Cross
9ab7767a57 Document camera demos and include image to explain the angles. 2023-03-25 11:40:02 -04:00
Don Cross
0be053325a Fixed bug in camera.py demo: incorrect angle for sunlit side of Moon. 2023-03-24 22:06:45 -04:00
Don Cross
f424bc14b5 Fixed bug in camera.js demo: incorrect angle for sunlit side of Moon. 2023-03-24 22:00:45 -04:00
Don Cross
da900c6793 Fixed C# camera demo bug: incorrect sunlit angle of Moon. 2023-03-24 21:55:07 -04:00
Don Cross
591ad2b11a Fixed bug in demo: camera.c
The camera demos all have a bug where I was calculating
the angle of the sunlit side of the Moon incorrectly.
The arguments to atan2 were backwards.
Added test data for Florida, New Zealand, and Canada
that are backed up by photographic evidence and
my first-hand observation.
2023-03-24 21:46:41 -04:00
Don Cross
0bd0df2cfa Use updated version of star database.
The star database file hygdata_v3.csv has been updated.
Updated the expected checksum for it.

Reworked the downloader to check for checksum disagreement.
If checksum doesn't match, delete the file and download,
then try the checksum again.
This change will automatically fix obsolete files that have already
been downloaded on contributor's development systems.
2023-03-22 15:05:00 -04:00
Don Cross
d3a2596e4c Exclude Any type from Python documentation.
Now that we use Python type hints, I discovered that
Python 3.11.2 includes the placeholder type `Any`
in the metadata reflected by `importlib`.
In order to generate consistent documentation with
older versions of Python, I exclude `Any` if it is present.

This change affects only the documentation and has
no effect on the Astronomy Engine package itself.
2023-03-22 12:23:10 -04:00
Don Cross
bd2db6a380 Version 2.1.17: add metersAboveGround parameter to SearchRiseSet. v2.1.17 2023-03-13 21:40:01 -04:00
Don Cross
c85881c25b Python: added metersAboveGround parameter to SearchRiseSet. 2023-03-13 20:42:46 -04:00
Don Cross
6c59d14bd4 Python: added Atmosphere function. 2023-03-13 16:16:53 -04:00
Don Cross
8c55fbad79 JS: Added metersAboveGround parameter to SearchRiseSet. 2023-03-13 13:06:37 -04:00
Don Cross
66cd0147b5 JS: Added Atmosphere function. 2023-03-13 09:54:54 -04:00
Don Cross
5e2292dfa6 Kotlin: added metersAboveGround parameter to searchRiseSet. 2023-03-12 22:10:50 -04:00
Don Cross
de8521fa49 Kotlin: atmosphere function. 2023-03-12 14:34:14 -04:00
Don Cross
09016badda C#: use my own hypot function internally. 2023-03-12 12:16:24 -04:00
Don Cross
6c3a7ab753 C#: Atmosphere, metersAboveGround in SearchRiseSet. 2023-03-12 11:17:47 -04:00
Don Cross
7bb9d02053 C#: Atmosphere function. 2023-03-11 20:23:20 -05:00
Don Cross
cdd75c7810 C SearchRiseSetEx: moved metersAboveGround parameter to end.
Because I plan on adding metersAboveGround as a parameter
that defaults to 0.0 in the other languages, and I want
the language implementations to be reasonably consistent,
I moved the metersAboveGround parameter to the end of
the parameter list for the C version of SearchRiseSetEx.
2023-03-11 18:50:57 -05:00
Don Cross
9a0151d9d4 C: Added unit tests for Atmosphere function. 2023-03-06 14:15:30 -05:00
Don Cross
c275922c0e C: rise/set now corrects for height above ground.
I realized I had to rework the RiseSetEx function so that
it accepts a height above ground level, rather than a generic
altitude angle correction, because atmospheric effects are
important both for the horizon dip angle and for the amount
of refraction at ground level.

The atmosphere calculations were interesting enough that
I made them public as a new function Astronomy_Atmosphere.
This returns the idealized temperature, pressure, and relative
density of air at the given elevation above/below sea level.
2023-03-05 22:05:40 -05:00
Don Cross
cc7d9f5bc9 C: Implemented horizon dip calculation for observer above ground.
This is the first step toward calculating body rise/set times
for an observer that is significantly above the ground.
It figures out the angular correction of the horizon
using both parallax and refractive correction of a light
ray from the horizon to the observer's eye.
2023-03-05 13:56:26 -05:00
Don Cross
543ffa358a Version 2.1.16 v2.1.16 2023-02-26 18:02:18 -05:00
Don Cross
1de31cf21f C#: Implemented Observer.ToString(). 2023-02-26 17:08:07 -05:00
Don Cross
2fcaf27995 Python: verify several thousand calendar dates. 2023-02-26 13:17:21 -05:00
Don Cross
ce0acf6d44 Kotlin: support calendar dates for years -999999 to +999999.
Enhanced the Time class to correctly calculate calendar
dates for the year range -999999 to +999999.

Made unit tests in C, C#, and Kotlin all exercise
the full year range, for February 28 and March 1 in each year,
to make sure we cover before and after each potential leap day.
2023-02-26 12:54:57 -05:00
Don Cross
16727b85c8 C: force use of 64-bit integers in calendar functions.
The C functions for calculating calendar dates used the
type `long` to perform calculations that require 64-bit
integers. However, in some C compilers, `long` is still
32 bits. This caused a failure in Windows for extreme
year values. So I now use the type `int64_t` to explicitly
require a 64-bit integer.
2023-02-26 10:31:27 -05:00
Don Cross
7e196a3c17 Fixed Windows batch files ignoring negative integer failure codes.
In many of my Windows batch files, I used the following
construct to detect failures:

    do_something
    if errorlevel 1 (
        echo.An error occurred in do_something
        exit /b 1
    )

I discovered that it is possible for a Windows program
to exit with a negative integer error code.
This causes the above construct to miss the failure
and the batch file blithely continues.

So I have replaced that construct with

    do_something || (
        echo.An error occurred in do_something
        exit /b 1
    )

This way, if the command exits with any nonzero error,
we correctly detect it as a failure.
2023-02-26 10:26:42 -05:00
Don Cross
503538da12 PY: Fixed calendar/time conversion functions for extreme year values.
Applying the same recent fixes to C and C# to the Python code.

I'm also changing my philosophy of representing times.
From now on, they will be truncated to the floor millisecond,
not rounded to the nearest millisecond. This means we don't reach
another calendar date until we have had 60 full seconds after
the last minute. Otherwise there is too much nasty logic for
rounding up calendar dates. I will follow suit across all languages.
2023-02-25 22:37:58 -05:00
Don Cross
e7d48c6ea7 C#: Fixed bugs with calendar dates with extreme year values.
Fixed problems converting AstroTime to calendar dates and back.
Also expose struct CalendarDateTime to outside callers,
for convenience dealing with Gregorian calendar dates.
2023-02-25 20:23:41 -05:00
Don Cross
1ac4ab2dba C: Fixed more problems with calendar date calculations.
With more rigorous testing, I discovered more bugs
in the C functions for converting calendar dates
to times and vice versa.

Astronomy_UtcFromTime():
When the year went before -4714, the value of the variable
`djd` went negative, causing the typecast `(long)djd` to
round toward zero instead of taking the true floor.
Changed this to `(long)floor(djd)`.

Astronomy_MakeTime():
Reworked the logic so that none of the integer divisions
involve negative values over the year range -999999..+999999.
2023-02-25 18:18:42 -05:00