User Tools

Site Tools


en:examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:examples [2017/11/23 20:10] (current)
writer created
Line 1: Line 1:
 +**1 Code recommended for checking the console and the web interface**
  
 +  #include <​stdio.h>​
 +  /*
 +  ** Lab 1: hello, world!
 +  */
 +  void control(void)
 +  {
 +  puts("​hello,​ world!"​);​
 +  }
 +
 +**2 Code recommended for testing the magnetometer**
 +
 +  #include "​libschsat.h"​
 +  ​
 +  /*
 +  ** Lab 2: get a raw data from a magnetometer
 +  */
 +  void control(void)
 +  {
 +  int i;
 +  const int num = 1; /* magnetometer #1 */  ​
 +  printf("​Enable magnetometer #​%d\n",​ num);  ​
 +  magnetometer_turn_on(num);  ​
 +  printf("​Get RAW data from magnetometer #​%d\n",​ num);  ​
 +  for (i = 0; i < 10; i++) {
 +  int16_t x, y, z;
 +  if (LSS_OK == magnetometer_request_raw(num,​ &x, &y, &z)) {
 +  printf("​%d:​ x=%d y=%d z=%d\n",​ i, x, y, z);
 +  } else {
 +  puts("​Fail!"​);​
 +  }
 +  Sleep(1);
 +  }
 +  printf("​Disable magnetometer #​%d\n",​ num);
 +    magnetometer_turn_off(num);​
 +  }
 +  ​
 +**3 Code recommended for checking the AVS**
 +  #include "​libschsat.h"​
 +  ​
 +  /*
 +  ** Lab 3: get a raw data from a hyro
 +  */
 +  void control(void)
 +  {
 +  int i;
 +  const int num = 1; /* hyro #1 */
 +  printf("​Enable hyro #​%d\n",​ num);
 +  hyro_turn_on(num);​
 +  printf("​Get RAW data from hyro #​%d\n",​ num);
 +  for (i = 0; i < 10; i++) {
 +  int16_t x, y, z;
 +  if (LSS_OK == hyro_request_raw(num,​ &x, &y, &z)) {
 +  printf("​%d:​ x=%d y=%d z=%d\n",​ i, x, y, z);
 +  } else {
 +  puts("​Fail!"​);​
 +  }
 +    Sleep(1);
 +  }
 +  printf("​Disable hyro #​%d\n",​ num);
 +  hyro_turn_off(num);​
 +  }
 +
 +**4 Code recommended for testing solar sensors**
 +
 +  #include "​libschsat.h"​
 +  ​
 +  /*
 +  ** Lab 4: get a raw data from a sun sensor
 +  */
 +  void control(void)
 +  {
 +  int i;
 +  const int num = 1; /* sun sensor #1 */
 +    printf("​Enable sensor #​%d\n",​ num);
 +  sun_sensor_turn_on(num);​
 +    printf("​Get RAW data from sun sensor #​%d\n",​ num);
 +  for (i = 0; i < 10; i++) {
 +  uint16_t value1;
 +  uint16_t value2;
 +  if (LSS_OK == sun_sensor_request_raw(num,​ &​value1,​ &​value2)) {
 +  printf("​%d:​ raw=%d ; %d\n", i, value1, value2);
 +  } else {
 +  puts("​Fail!"​);​
 +  }
 +  Sleep(1);
 +  }
 +  printf("​Disable sensor #​%d\n",​ num);
 +  sun_sensor_turn_off(num);​
 +  }
 +
 +**5 Code recommended for checking the flywheel control**
 +
 + #include "​libschsat.h"​
 + /*
 + ** Lab 5: manage motor'​s speed
 + */
 + void control(void)
 + {
 + const int num = 1; /* motor number #1 */
 + int16_t temp;
 + int16_t rpm = -3000; /* -3000 ... +3000 */
 + printf("​Enable motor #​%d\n",​ num);
 + motor_turn_on(num);​
 + printf("​Manage speed motor #​%d\n",​ num);
 + while (rpm <= 3000) {
 + printf("<<<​ Set speed to %d\n", rpm);
 + if (LSS_OK == motor_set_speed(num,​ rpm, &temp)) {
 + if (temp == rpm)
 + printf("​\t%d confirmed\n",​ rpm);
 + }
 + Sleep(1);​
 + if (LSS_OK == motor_request_speed(num,​ &temp)) {
 + printf("​Got speed %d >>>​\n",​ temp);
 + } else {
 + puts("​Fail! >>>"​);​
 + }
 + rpm += 500;
 + }
 + printf("<<<​ Set speed to 0\n");
 + if (LSS_OK == motor_set_speed(num,​ 0, &temp)) {
 + if (temp == 0)
 + printf("​\t%d confirmed\n",​ 0);
 + }
 + Sleep(1);
 + if (LSS_OK == motor_request_speed(num,​ &temp)) {
 + printf("​Got speed %d >>>​\n",​ temp);
 + } else {
 + puts("​Fail! >>>"​);​
 + }
 + Sleep(1);
 + motor_set_speed(num,​ 0, &temp);
 + Sleep(1);
 + printf("​Disable motor #​%d\n",​ num);
 + motor_turn_off(num);​
 + }
 +
 +**6 Code recommended for checking the camera and the transmitter**
 + #include "​libschsat.h"​
 +
 + /*
 + ** Lab 6: Camera capture demo
 + */
 + void control(void)
 + {
 + int i;
 +
 + if (LSS_OK == camera_turn_on()) {
 + for (i = 1; i < 10; i++) {
 + printf("​Take photo #​%d\n",​ i);
 + if (camera_take_photo(i)) {
 + puts("​\tFail!"​);​
 + }
 + }
 + }
 + else
 + puts("​\tFail!"​);​
 +
 + printf("​Turn-on transmitter #​1\n"​);​
 + if (LSS_OK == transmitter_turn_on(1)) {
 + for (i = 1; i < 10; i++) {
 + printf("​Transmit photo #​%d\n",​ i);
 + if (transmitter_transmit_photo(1,​ i)) {
 + puts("​\tFail!"​);​
 + }
 + }
 + } else {
 + puts("​\tFail!"​);​
 + }
 + printf("​Turn-off transmitter #​1\n"​);​
 + if (transmitter_turn_off(1))
 + puts("​\tFail!"​);​
 + }
 +
 +**8 Code recommended for checking the fan engine**
 +
 + #include "​libschsat.h"​
 + /*
 + ** Lab 8: manage fan motor'​s speed
 + */
 + void control(void)
 + {
 + const int num = 1; /* motor number #1 */
 + int16_t temp;
 + int16_t rpm = -3000; /* -3000 ... +3000 */
 + printf("​Enable fan #​%d\n",​ num);
 + fan_turn_on(num);​
 + printf("​Manage speed fan motor #​%d\n",​ num);
 + while (rpm <= 3000) {
 + printf("<<<​ Set speed to %d\n", rpm);
 + if (LSS_OK == fan_set_speed(num,​ rpm, &temp)) {
 + if (temp == rpm)
 + printf("​\t%d confirmed\n",​ rpm);
 + }
 + Sleep(1);​
 + if (LSS_OK == fan_request_speed(num,​ &temp)) {
 + printf("​Got speed %d >>>​\n",​ temp);
 + } else {
 + puts("​Fail! >>>"​);​
 + }
 + rpm += 500;
 + }
 + printf("<<<​ Set fan speed to 0\n");
 + if (LSS_OK == fan_set_speed(num,​ 0, &temp)) {
 + if (temp == 0)
 + printf("​\t%d confirmed\n",​ 0);
 + }
 + Sleep(1);
 + if (LSS_OK == fan_request_speed(num,​ &temp)) {
 + printf("​Got fan speed %d >>>​\n",​ temp);
 + } else {
 + puts("​Fail! >>>"​);​
 + }
 + Sleep(1);
 + fan_set_speed(num,​ 0, &temp);
 + Sleep(1);
 + printf("​Disable fan motor #​%d\n",​ num);
 + fan_turn_off(num);​
 + }
 +
 +**9 Code recommended for checking the telemetry transmitter**
 +
 + #include "​libschsat.h"​
 + /*
 + ** Lab 9: UHF transceiver demo.
 + */
 + void control(void)
 + {
 + const uint16_t tx_num = 2;
 + const uint16_t rx_num = 1;
 + const char hello[] = "​hello,​ world!";​
 + printf("​Enable transceiver #​%d\n",​ tx_num);
 + transceiver_turn_on(tx_num);​
 + Sleep(1);
 + bus_setup();​
 + printf("​Send data from #%d to #​%d\n",​ tx_num, rx_num);
 + if (LSS_OK != transceiver_send(tx_num,​ rx_num, (uint8_t *) hello, sizeof(hello)))
 + puts("​Fail!"​);​
 + printf("​Disable transceiver #​%d\n",​ tx_num);
 + transceiver_turn_off(tx_num);​
 + return;
 + }
 +
 +**10 Code recommended for testing coils**
 +
 + #include "​libschsat.h"​
 + /*
 + ** Lab 10: manage coil
 + */
 + void control(void)
 + {
 + const int num = 0; /* coil number #0 */
 + int16_t temp;
 + int16_t pwm = -32000; /* -32000 ... +32000 */
 + printf("​Enable coil #​%d\n",​ num);
 + coil_turn_on(num);​
 + printf("​Manage coil #​%d\n",​ num);
 + Sleep(1);
 + while (pwm <= 32000) {
 + printf("<<<​ Set value to %d\n", pwm);
 + if (LSS_OK == coil_set_value(num,​ pwm, &temp)) {
 + if (temp == pwm)
 + printf("​\t%d confirmed\n",​ pwm);
 + }
 + mSleep(100);​
 + pwm += 1000;
 + }
 + Sleep(1);
 + printf("<<<​ Set value to 0\n");
 + if (LSS_OK == coil_set_value(num,​ 0, &temp)) {
 + if (temp == 0)
 + printf("​\t%d confirmed\n",​ 0);
 + }
 + Sleep(1);
 + printf("​Disable coil #​%d\n",​ num);
 + coil_turn_off(num);​
 + }
en/examples.txt · Last modified: 2017/11/23 20:10 by writer