en:sun_subsys

# Solar Sensors

Virtual power draw: 45 mA

Solar sensors in spacecraft act as positioning sensors as they identify the spatial position of the satellite relative to the Sun. Quite often they are used as a rough positioning aid for turning solar cells of the satellite to face the Sun. It should be noted that solar sensors stop short of providing complete positioning information as the turning angle around “orbiter-Sun” direction remains uncertain.

The following function (in C) can be called to obtain raw measurement readings:

int sunsensor_request_raw(uint16_t num, uint16_t *pRAW_data1, uint16_t *pRAW_data2);

Readings come from two sensor elements observing the left and right hemispheres respectively. With either sensor receiving light the angle toward the Sun can be inferred from light intensity. With both sensors lit the more correct approach would be to use a ratio of light exposure on both sensors.

The sensor is calibrated for different conditions by computing angles from light exposure levels. Nevertheless, even uncalibrated, sensors of this design can be used for orientation toward the Sun by correlating light exposure of the left vs. right hemispheres of the sensor.

It should be noted that the alignment of individual sensing elements inside housings is far from ideal – just like real-world devices – making each sensor somewhat unique. This misalignment is the combined effect of imprecise housing machining to specified dimensions, imperfect mounting of electronics PCBs within housings and less than ideal sensor uniformity (as individual sensors still differ somewhat from each other).
Most errors of this kind persist throughout device lifetime, although there can also be errors that depend appreciably on external factors (such as temperature). In our case we assume that measurement errors of individual sensors are persistent and little affected by temperature, making their one-time calibration prior to use a viable option.

### Sample C Test Code for Solar Sensors

sun_test.c
#include <stdio.h>
#include <stdint.h>
#include "libschsat.h"
#define LSS_OK 0
#define LSS_ERROR 1
#define LSS_BREAK 2

int control(){ //Основная функция программы
uint16_t sun_result[] = {0, 0, 0}; // инициализируем sun_result
uint16_t num = 1; // номер солнечного датчика
printf("Enable sun sensor №%d\n", num);
sun_sensor_turn_on(num); //включаем датчик
Sleep(1); //Ждем включения 1 секунду
printf("Get RAW data from sun sensor №%d\n", num);
int i;
for (i = 0; i < 10; i++) //считываем показаия 10 раз
{
sun_result[0] = sun_sensor_request_raw(num,& sun_result[1],& sun_result[2]);/*проверить как работает, очень странно,  что работает
если не работает задать sun_result[0] */
if (!sun_result[0]){ //если датчик не вернул сообщение об ошибке,
printf("state: %d raw = %d, %d\n", i, sun_result[1], sun_result[2]);
}

else if (sun_result[0] == 1) { //если датчик вернул сообщение об ошибке 1
printf("Fail because of access error, check the connection\n");
}
else if (sun_result[0] == 2) { //если датчик вернул сообщение об ошибке 2
printf("Fail because of interface error, check you code\n");
}
Sleep(1); //показания считываются раз в секунду

}
printf("Disable sun sensor №%d\n", num);
sun_sensor_turn_off(num); //выключаем солнечный датчик
return 0;
}