en:lesson02

# 02 Lesson. Introducing sensors

## Angular velocity sensor (AVS)

Function of angular velocity sensor Angular velocity sensor is used for measuring of angular speed of rotating object. Angular speed measuring is necessary so that it would be possible to stop the rotating satellite – to stabilize it. Using angular velocity sensor it is also possible to make satellite rotate at a certain speed.

## Operation principle of angular velocity sensor

The main measuring component of angular velocity sensor is a special microelectromechanical gyroscope (MEMS). It is not a conventional gyroscope in which a disk is rotating at a high speed but a miniature vibrating gyroscope. There is a ring inside MEMS vibrating along one plane direction. If such gyroscope is put on a rotating platform the planar surface of which coincides with the plane direction of ring vibration then the Coriolis force will start affecting it in proportion to the speed of platform rotation. Coriolis force is measured using piezoelectric elements that output the voltage in proportion to applied force.

After determining volume of Coriolis force and having data on the speed of vibration it is possible to calculate the angular velocity and its fluctuation (angular acceleration).

### Testing of operational performance of angular velocity sensor

Connect the angular velocity sensor to power-supply unit and to onboard computer. Open Notepad++ and write the following program.

Python code.

hyro_test.py
def control(): # Main program function in which other functions are called

hyro_result = [0,0,0,0] # Initializing hyro_result
num = 1 # Number of angular velocity sensor
print "Enable angular velocity sensor №", num
hyro_turn_on(num) # Turning angular velocity sensor on
sleep(1) # Waiting for 1 second for sensor to turn on
print "Get RAW data from angular velocity sensor"

for i in range(10):  # Reading the indication for 10 times
hyro_result = hyro_request_raw(num) # recording function answer
# hyro_request_raw to variable hyro_result
if not hyro_result[0]: # if sensor does not return error message,
print "state:", hyro_result[0], "x_raw =", hyro_result[1], \
"y_raw =", hyro_result[2], "z_raw =", hyro_result[3]
# Data output
elif hyro_result[0] == 1: # if sensor returns error message 1
print "Fail because of access error, check the connection"
elif hyro_result[0] == 2: # if sensor returns error message 2
print "Fail because of interface error, check your code"

sleep(1) # Indications are read one time per second

print "Disable angular velocity sensor №", num
hyro_turn_off(num)   # Turning angular velocity sensor off

С code.

hyro_test.c
#include "libschsat.h"

int control(){
uint16_t num = 1;  	// Number of angular velocity sensor
int16_t hyro_result[] = {0, 0, 0, 0};
printf("Enable angular velocity sensor № %d", num);
hyro_turn_on(num); 						// Turning angular velocity sensor on
Sleep (1);							// Waiting for 1 second for sensor to turn on
printf("\nGet RAW data from angular velocity sensor\n");

int i;
for (i = 0; i < 10; i++) { 		// Reading the indication for 10 times
hyro_result[0] = hyro_request_raw(num,& hyro_result[1],& hyro_result[2],& hyro_result[3]);

if (!hyro_result[0])
{
printf("state: %d", i);
printf(" x_raw = %d", hyro_result[1]);
printf(" y_raw = %d", hyro_result[2]);
printf(" z_raw = %d\n", hyro_result[3]);

}
else if (hyro_result[0] == 1)
{
printf("Fail because of access error, check the connection");
}
else if (hyro_result[0] == 2)
{
printf("Fail because of interface error, check your code");
}
Sleep(1);

}
printf("\nDisable angular velocity sensor № %d\n", num);
hyro_turn_off(num);
return 0;
}

Run the program and test the operation of angular velocity sensor.

### Code analysis

Please note that after # symbol the comments are written that do not affect the program operation. The program starts running from output of function control(). Then we create the list hyro_result for receiving from sensor the data and variable num storing the sensor number. Then operator print outputs the message that the sensor is turned on. Then function hyro_turn_on(num) turns on the sensor with the specified number. Function sleep(1) suspends the program execution for 1 second. After that in cycle for i in range(10): we read and output the indication of sensor for 10 times. Indicatioin of sensor are read with the help of function hyro_request_raw(num).

## Magnetometer

### Function of magnetometer

Information on orientation is received by the satellite from angular velocity sensor and from magnetometer. Information on angle is needed to rotate the satellite in the necessary direction and information on angular velocity is needed to stabilize the satellite i.e. to stop the angular rotation. The driving moment is created with the help of reaction wheel.

### Operation principle of magnetometer

Operation of magnetometer is based on application of magnetoresistive effect when electrical resistance of a conductor is fluctuating in correspondence with magnetic fields pattern direction. Sensor operation is based on a layer of permalloy (special nickel-iron alloy) possessing a strong magnetoresistive effect. Electrical resistance of permalloy usually fluctuating within the range of ±5 % depending on force and pattern direction of magnetic field.

Therefore measuring the electric current force flowing through the layer of permalloy at the permanent current of +5V it is possible to determine the direction of magnetic fields pattern. To measure the magnetic field pattern direction by all three axes three little sensors are utilized oriented along axes X, Y and Z , installed in one microchip.

### Checking of magnetometer functional capability

Open Notepad++ and write the following program.

Python code.

mag_test.py
def control(): # Main function of program from which other functions are called
mgn_result = [0,0,0,0] # Initializing mgn_result
num = 1  # number of magnetometer
print "Enable magnetometer №", num
magnetometer_turn_on(num)
sleep(1)
print "Get RAW data from magnetometer"
for i in range(10):
mgn_result = magnetometer_request_raw(num)
if not mgn_result[0]: # if sensor returns an error message,
print "state:", mgn_result[0], "x_raw =", mgn_result[1], \
"y_raw =", mgn_result[2], "z_raw =", mgn_result[3]
# Please note the line break symbol!
elif mgn_result[0] == 1:
print "Fail because of access error, check the connection"
elif mgn_result[0] == 2:
print "Fail because of interface error, check your code"
sleep(1)
print "Disable magnetometer №", num
magnetometer_turn_off(num)

С code.

mag_test.c
#define LSS_OK 0
#define LSS_ERROR 1
#define LSS_BREAK 2

#include <stdio.h>
#include <stdint.h>
#include "libschsat.h"
int control() // Main function of program from which other functions are called
{
int16_t mgn_result[] = {0,0,0,0}; // Initializing mgn_result
uint16_t num = 1;	// number of magnetometer
int i;
printf("Rnable magnetometer №%d\n", num);
magnetometer_turn_on(num);
Sleep(1);
printf("Get RAW data from magnetometer\n");
for (i = 0; i < 1000; i++)
{
mgn_result[0] = magnetometer_request_raw(num,& mgn_result[1],& mgn_result[2],& mgn_result[3]);
if (!mgn_result[0])// if sensor returns an error message,
{
printf("\nstate:%d, \nx_raw =%d,\ny_raw =%d, \nz_raw =%d\n",i, mgn_result[1], mgn_result[2], mgn_result[3]); //Please note the line break symbol!
}
else if (mgn_result[0] == 1){
printf("Fail because of access error, check the connection");
}
else if (mgn_result[0] == 2){
printf("Fail because of interdace error, check your code");
}
Sleep(0.1);
}
printf("Disable magnetometer №%d\n", num);
magnetometer_turn_off(num);
return 0;
}

Run the program and check the magnetometer functional capability.

### Code analysis

Program starts from control() function call. Then we create the list mgn_result to get the data from sensor and variable num, storing the number of magnetometer. Then operator print outputs the message on switching on of sensor. After that function magnetometer_turn_on(num) switches on the magnetometer with indicated number. Function sleep(1) suspends the program execution for 1 second. Then in cycle for i in range(10): we read and output the indication of magnetometer for 10 times. Indications of magnetometer are read with the help of function magnetometer_request_raw(num).

## Sun Sensors

### Function of Sun sensors

Function of sun sensors is to determine the location of satellite in relation to the Sun. As the position of the Sun in relation to the Earth at any given moment of time is known fairly precisely, then as it follows from it is possible to determine the position of satellite in relation to the Earth.

### Operation principle of Sun sensors

The basis of Sun sensor is a photodetector measuring the brightness of light. The most popular types of photodetectors are photoresistors cells and photodiodes. Photoresistor consists of material, the resistance of which fluctuates depending on the intensity of impinging light.

Unlike photoresistor, photodiode outputs voltage under the action of light. Photodiode detectors can be of various types — LEP (Latheral Effect Photodiode), QD-photodiode (Quadrant Detector) or matrix type.

LEP photodiode is a single photodiode with large sensitive surface.

QD-photodiode consists of four independent photodiodes located symmetrically in relation to the center of sensitive surface.

Calculation of the spot position on the surface of QD-photodiode фотодиода results from correlation of output currents of photodiodes.

Matrix sensor incorporates a large number of photodiodes and allows to determine the position of the Sun more precisely.

### Checking of operational capability of sun sensors

Start connecting sun sensors in turn to power-supply unit and to onboard computer and check the operational capability.

Open Notepad++ and write the following program.

Python code.

sun_test.py
def control(): # Main function of program from which other functions are called
sun_result = [0,0,0] # Initializing sun_result
num = 1
print "Enable sun sensor №", num
sun_sensor_turn_on(num)
sleep(1)
print "Get RAW data from sun sensor"

for i in range(10):
sun_result = sun_sensor_request_raw(num)
if not sun_result[0]: # if sensor returns error message,
print "state:", sun_result[0], "raw =", sun_result[1], \
sun_result[2]
elif sun_result[0] == 1:
print "Fail because of access error, check the connection"
elif sun_result[0] == 2:
print "Fail because of interface error, check your code"

sleep(1)

print "Disable sun sensor №", num
sun_sensor_turn_off(num)

С code.

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(){ // Main function
uint16_t sun_result[] = {0, 0, 0}; // Initializing sun_result
uint16_t num = 1; // number of sun sensor
printf("Enable sun sensor №%d\n", num);
sun_sensor_turn_on(num); // turn the sensor on
Sleep(1); // wait 1 second
printf("Get RAW data from sun sensor №%d\n", num);
int i;
for (i = 0; i < 10; i++) // read the sensor 10 times
{
sun_result[0] = sun_sensor_request_raw(num,& sun_result[1],& sun_result[2]);
if (!sun_result[0]){ // if the sensor did not return an error message,
printf("state: %d raw = %d, %d\n", i, sun_result[1], sun_result[2]);
}

else if (sun_result[0] == 1) { // if the sensor did not return an error message 1
printf("Fail because of access error, check the connection\n");
}
else if (sun_result[0] == 2) { // if the sensor did not return an error message 2
printf("Fail because of interface error, check you code\n");
}
Sleep(1); // wait 1 second

}
printf("Disable sun sensor №%d\n", num);
sun_sensor_turn_off(num); // turn sun sensor off
return 0;
}

Run the program and test sun sensor operation.

Test in turn all 4 sun sensors.

### Code analysis

Program starts from declaration of function control().

Then we create the list sun_result to receive data from sensor and variable num, storing the magnetometer number. The operator print returns the message on turning on of sensor. Then function sun_sensor_turn_on(num) turns on the magnetometer with indicated number. Function sleep(1) suspends the program execution for 1 second. Then in cycle for i in range(10): we read and return the value of magnetometer output for 10 times. Indications of magnetometer are read with the help of function sun_sensor_request_raw(num).