FB_BA_CalcSunPos
The function block FB_BA_CalcSunPos is used to calculate the position of the sun by specifying the date, time, longitude and latitude.
The position of the sun for a given point in time can be calculated according to common methods with a defined accuracy. The present function block is sufficient for applications with moderate requirements. 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; 0° means that the sun is in the horizontal plane of the location; a value of 90° means that the is perpendicular to the observer. The other angle indicates the direction at which the sun is positioned. 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 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 fSunElv, the sun is invisible. This can be used to determine sunrise and sunset.
Inputs
VAR_INPUT
fDegLngd : REAL;
fDegLatd : REAL;
tUTC : TIMESTRUCT;
END_VAR
Name | Type | Description |
---|---|---|
fDegLngd | REAL | Longitude [°] |
fDegLatd | REAL | Latitude [°] |
tUTC | Current time as Coordinated Universal Time. The function block FB_BA_GetTime can be used to read this time from a target system. |
Outputs
VAR_OUTPUT
fSunAzm : REAL;
fSunElv : REAL;
END_VAR
Name | Type | Description |
---|---|---|
fSunAzm | REAL | Sun direction (northern hemisphere: 0° north ... 90° east ... 180° south ... 270° west ... / southern hemisphere: 0° south ... 90° east ... 180° north ... 270° west ...). |
fSunElv | REAL | Sun elevation (0° horizontal ... 90° perpendicular). |
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT from v3.1.4024.22 | Tc3_BA2 from v5.2.5.0 |