FB_BA_CalcSunPos
Calculation of sun position based on the date, time, longitude and latitude.
Functional description
The position of the sun for a given point in time can be calculated according to common methods with a defined accuracy. For applications with moderate requirements, the present function block is sufficient. As the basis for this, the SUNAE algorithm was used, which represents a favorable compromise between accuracy and computing effort.
The position of the sun at a fixed observation point is normally determined by specifying two angles. One angle indicates the height above the horizon, where 0° means that the sun is in the horizontal plane of the observation site and 90° means that the sun is directly over the observer's head. The other angle indicates the direction in which the sun is standing. The SUNAE algorithm is used to distinguish whether the observer is standing on the northern hemisphere (longitude > 0 degrees) or on the southern hemisphere (longitude < 0 degrees) of the earth. If the observation point is in the northern hemisphere is, then a value of 0° is assigned for the northern sun direction and it then runs in the clockwise direction around the compass, i.e. 90° is east, 180° is south, 270° is west etc. If the point of observation is in the southern hemisphere, then 0° corresponds to the southern direction and it then runs in the counter clockwise direction, i.e. 90° is east, 180° is north, 270° is west etc.
The time has to be specified as coordinated universal time (UTC, Universal Time Coordinated, previously referred to as GMT, Greenwich Mean Time).
The latitude is the northerly or southerly distance of a location on the Earth’s surface from the equator, in degrees [°]. The latitude can assume values between 0° (at the equator) and ±90° (at the poles). A positive sign thereby indicates a northern direction and a negative sign a southern direction. The longitude is an angle that can assume values up to ±180° starting from the prime meridian 0° (an artificially determined North-South line). A positive sign indicates a longitude in an eastern direction and a negative sign in a western direction. Examples:
Location | Longitude | Latitude |
---|---|---|
Sydney, Australia | 151.2° | -33.9° |
New York, USA | -74.0° | 40.7° |
London, England | -0.1° | 51.5° |
Moscow, Russia | 37.6° | 55.7° |
Beijing, China | 116.3° | 39.9° |
Dubai, United Arab Emirates | 55.3° | 25.4° |
Rio de Janeiro, Brazil | -43.2° | -22.9° |
Hawaii, USA | -155.8° | 20.2° |
Verl, Germany | 8.5° | 51.9° |
If the function block FB_BA_CalcSunPos returns a negative value for the sun elevation lrSunElv, the sun is invisible. This can be used to determine sunrise and sunset.
Inputs/outputs
VAR_INPUT
lrDegLngd : LREAL;
lrDegLatd : LREAL;
stUTC : TIMESTRUCT;
lrDegLngd: longitude [°]
lrDegLatd: latitude [°]
stUTC: input of the current time as Coordinated Universal Time. The function block FB_BA_GetTime can be used to read this time from a target system.
VAR_OUTPUT
lrSunAzm : LREAL;
lrSunElv : LREAL;
lrSunAzm: sun direction (northern hemisphere: 0° north ... 90° east ... 180° south ... 270° west ... / southern hemisphere: 0° south ... 90° east ... 180° north ... 270° west ...)
lrSunElv: sun elevation (0° horizontal ... 90° vertical)
Requirements
Development environment | Target system | required library | required supplement |
---|---|---|---|
TwinCAT 2.11 R3/x64 | PC/CX | TcBA library from V1.0.0 | TS8040 | TwinCAT Building Automation from V1.0.0 |