Skip to main content

User API in C++

This section presents a set of user-defined functions implemented in the libschsat.h library.

Functions

Angular velocity sensor

Get the DUS readings.

SchSatApi int gyro_request_raw (uint16_t num, float *pRAW_dataX, float *pRAW_dataY, float *pRAW_dataZ)

Set the zero offset of the DUS.

SchSatApi int gyro_set_offset (uint16_t num, float offset_X, float offset_Y, float offset_Z)

Send the DUS readings over VHF.

SchSatApi int gyro_push_data_uhf ()

Magnetometer

Get magnetometer readings.

SchSatApi int magnetometer_request_raw (uint16_t num, float *pRAW_dataX, float *pRAW_dataY, float *pRAW_dataZ)

Set the zero offset of the magnetometer.

SchSatApi int magnetometer_set_offset(uint16_t num,int16_t offset_X,int16_t offset_Y,int16_t offset_Z);

Send the magnetometer readings over VHF.

SchSatApi int magnetometer_push_data_uhf ()

Set the telemetry period of the magnetometer and angular velocity sensor.

SchSatApi int magnetometer_gyro_set_telemetry_period (const uint16_t num, const uint16_t period)

Flywheel

Get the rotation speed of the flywheel.

SchSatApi int motor_request_speed (uint16_t num, float *pRPM)

Set the rotation speed of the flywheel.

SchSatApi int motor_set_speed (uint16_t num, float RPM)

Set the flywheel telemetry period.

SchSatApi int motor_set_telemetry_period (const uint16_t num, const uint16_t period)

Solar sensors

Get the readings of the solar sensor.

SchSatApi int sunsensor_get_raw (uint16_t num, int32_t *angle)

Send the readings of the solar sensor via VHF.

SchSatApi int sunsensor_push_data_uhf (uint16_t num)

Set the telemetry period of the solar sensor.

SchSatApi int sunsensor_set_telemetry_period (const uint16_t num, const uint16_t period)

UniCAN

Get the UniCAN message.

SchSatApi int recieve_unican_message (const uint16_t address_from, const uint16_t msg_id, uint8_t *data, const uint16_t msg_size, const uint16_t timeout)

Send a message to UniCAN.

SchSatApi int send_unican_message (const uint16_t address_to, const uint16_t msg_id, uint8_t *data, const uint16_t msg_size)

Camera

Send the picture to the receiving station.

SchSatApi int transmitter_transmit_photo (uint16_t num)

Take a picture with the onboard camera.

SchSatApi int camera_take_photo (uint16_t num)
tip

Attention! For the functions to work correctly, the file with the user program must contain the line above the user code: #include "libschsat.h".

Detailed description of the functions

Get the DUS readings.

SchSatApi int gyro_request_raw (uint16_t num, float * pRAW_dataX, float * pRAW_dataY, float * pRAW_dataZ)

The function receives up-to-date data from a given angular velocity sensor and writes it to the variables pRAW_dataX, pRAW_dataY, pRAW_dataZ.

The values are given in degrees/sec.

Arguments

[in] num device ID
[out] pRAW_dataX Angular velocity around the X axis, deg/sec
[out] pRAW_dataY Angular velocity around the Y axis, deg/sec
[out] pRAW_dataZ Angular velocity around the Z axis, deg/sec
float gyro_x = 0, gyro_y = 0, gyro_z = 0;
if (gyro_request_raw(0, &gyro_x, &gyro_y, &gyro_z) != 0) {
puts ("Gyro data ERROR"); 4 }
printf ("Angular rate: X %f, Y %f, Z %f\n", gyro_x, gyro_y, gyro_z);

Set the zero offset of the DUS.

SchSatApi int gyro_set_offset ( uint16_t num, float offset_X, float offset_Y, float offset_Z)

The function sets a constant offset of the DUS indicators combining physical and logical zero. The values of the arguments are in units of DUS (deg/sec).

Arguments

[in] num device ID
[in] offset_X Zero velocity offset around the X axis, deg/sec
[in] offset_Y Offset of the velocity zero around the Y axis, deg/sec
[in] offset_Z Zero velocity offset around the Z axis, deg/sec

Send the DUS readings over VHF.

SchSatApi int gyro_push_data_uhf ( )

The function sends up-to-date data from the angular velocity sensor via VHF communication. The values are given in degrees/sec.

Get magnetometer readings.

SchSatApi int magnetometer_request_raw ( uint16_t num, float * pRAW_dataX, float * pRAW_dataY, float * pRAW_dataZ )

The function receives up-to-date data from a given magnetometer and stores it in the variables pRAW_dataX, pRAW_dataY, pRAW_dataZ. The values are presented in nT.

Arguments

[in] num device ID (currently not implemented, num can be anything)
[out] pRAW_dataX Magnetic field on the X-axis, nT
[out] pRAW_dataY Magnetic field along the Y axis, nT
[out] pRAW_dataZ Magnetic field along the Z axis, nT
float mag_x = 0, mag_y = 0, mag_z = 0;
if (magnetometer_request_raw(0, &mag_x, &mag_y, &mag_z) != 0) {
puts ("Magnetometer data ERROR"); }
printf ("Magfield: X %f, Y %f, Z %f\n", mag_x, mag_y, mag_z);

Set the zero offset of a given magnetometer.

SchSatApi int magnetometer_set_offset ( uint16_t num, int16_t offset_X, int16_t offset_Y, int16_t offset_Z)

The function sets a constant offset of the magnetometer indicators combining physical and logical zero. The values of the arguments are in magnetometer units (nT).

tip

Attention! The zero offset is set in int16_t and can have a value from -32768 to +32767. If this range is not enough, additional preprocessing of the values in the user program is possible.

Arguments

[in] num device ID
[in] offset_X The zero offset of the magnetic field along the X axis, nT
[in] offset_Y The zero offset of the magnetic field along the Y axis, nT
[in] offset_Z The zero offset of the magnetic field along the Z axis, nT

Send the magnetometer readings over VHF.

SchSatApi int magnetometer_push_data_uhf ( )

The function sends up-to-date data from the magnetometer via VHF communication. The values are presented in nT.

Set the telemetry period of the magnetometer and angular velocity sensor.

SchSatApi int magnetometer_gyro_set_telemetry_period ( const uint16_t num, const uint16_t period )

The function sets the period for sending telemetry by the specified magnetometer and DUS. The period value is set in ms and should be in the range of 50..5000ms.

tip

Attention! Too low a telemetry period on a large number of devices may cause overload of the CAN bus.

Arguments

[in] num device ID
[in] period telemetry period, ms

Get the rotation speed of the flywheel.

SchSatApi int motor_request_speed ( uint16_t num, float * pRPM )

The function returns the angular velocity of rotation of a certain control motor, the flywheel. The value is written to the pRPM variable. Units of measurement: rpm.

Arguments

[in] num device ID
[out] pRPM angular rotation speed, rpm
``

### Set the rotation speed of the flywheel.

```cpp
SchSatApi int motor_set_speed ( uint16_t num, float RPM )

The function sets the angular rotation speed of a certain control motor, the flywheel. As arguments, the function takes the serial number of the flywheel and the speed in rpm.

Arguments

[in] num device ID
[in] RPM angular rotation speed, rpm
``

### Set the flywheel telemetry period.

```cpp
SchSatApi int motor_set_telemetry_period ( const uint16_t num, const uint16_t period )

The function sets the period for sending telemetry by the specified flywheel. The period value is set in ms and should be in the range of 50..5000ms.

tip

Attention! Too low a telemetry period on a large number of devices may cause overload of the CAN bus.

Arguments

[in] num device ID
[in] period telemetry period, ms

Get the readings of the solar sensor.

SchSatApi int sunsensor_get_raw ( uint16_t num, int32_t * angle )

The function receives up-to-date data from a given solar sensor and stores it in the angle variable. The values are shown in degrees. The angle is measured from the normal to the sensor plane. If the sensor is not illuminated by the sun, the function returns the value -180.

Arguments

[in] num device ID
[out] angle the angle between the normal of the sensor plane and the vector in the sun, °.
int32_t angle = 0;
if (sunsensor_get_raw(0, &angle) != 0) {
puts ("Magnetometer data ERROR\n");
}
printf ("Angle to the sun #0: %d\n", angle);

Send the readings of the solar sensor via VHF.

SchSatApi int sunsensor_push_data_uhf ( uint16_t num )

The function sends up-to-date data from a given solar sensor via VHF communication. The data format is the components of a vector of length 1e+9 directed at a light source. If the light source is out of the field of view of the specified sensor, a zero vector with a data invalidity flag is transmitted.

Arguments

[in] num device ID

Set the telemetry period of the solar sensor.

SchSatApi int sunsensor_set_telemetry_period ( const uint16_t num, const uint16_t period )

The function sets the period for sending telemetry by a specified solar sensor. The period value is set in ms and should be in the range of 50..5000ms. Attention! Too low a telemetry period on a large number of devices can cause an overload of the CAN bus.

Arguments

[in] num device ID
[in] period telemetry period, ms

Get the UniCAN message.

SchSatApi int recieve_unican_message ( const uint16_t address_from, const uint16_t msg_id, uint8_t * data, const uint16_t msg_size, const uint16_t timeout )

If the message length is zero (msg_size == 0) *data must be NULL.

Arguments

[in] address_from Identifier of the sending device
[in] msg_id Message ID
[out] *data Pointer to the buffer for the received data in the uint8_t format*
[in] msg_size The size of the data in bytes
[in] timeout Message timeout in milliseconds
``

### Send a message to UniCAN.

```cpp
SchSatApi int send_unican_message ( const uint16_t address_to, const uint16_t msg_id, uint8_t * data, const uint16_t msg_size )
```cpp
Arguments
```cpp
[in] address_to ID of the receiving device
[in] msg_id Message ID
[in] *data Pointer to data in uint8_t format *
[in] msg_size The size of the data in bytes

Send the picture to the receiving station.

SchSatApi int transmitter_transmit_photo ( uint16_t num )
SchSatApi int push_photo_terra2 ( uint8_t photoNum )
SchSatApi int push_thumbs_terra2 ( uint8_t numFrom )

Arguments

[in] num the numeric identifier of the photo (8/16-bit unsigned) or thumbnail from which the transfer will begin

Take a picture with the onboard camera.

SchSatApi int camera_take_photo ( uint16_t num )

The camera takes a picture and stores it in the satellite's memory.

Arguments

[in] num numeric photo identifier (16-bit unsigned)
``

### The delay function is accurate to milliseconds.

```cpp
SchSatApi void mSleep(int msec)

The argument

[in] msec - Delay time in ms

The delay function is accurate to seconds.

SchSatApi void Sleep(int sec)

The argument

[in] sec - Delay time in seconds
``