Spaceshot Flight Software
The Illinois Space Society's Homemade Rocket Firmware
telemetry.h
1 #include <ChRt.h>
2 #include <RH_RF95.h>
3 #include <SPI.h>
4 #include <ServoControl.h>
5 
6 #include <array>
7 
8 #include "FifoBuffer.h"
9 #include "SD.h"
10 #include "pins.h"
11 #include "sensors.h"
12 
13 // Make sure to change these pinout depending on wiring
14 // Don't forget to change the ini file to build the correct main file
15 
16 // Change to 434.0 or other frequency, must match RX's freq!
17 #define RF95_FREQ 434.0
18 
19 #define MAX_CMD_LEN 10
20 
22  systime_t timestamp; //[0, 2^32]
23 
24  uint16_t barometer_pressure; //[0, 4096]
25  int16_t highG_ax; //[128, -128]
26  int16_t highG_ay; //[128, -128]
27  int16_t highG_az; //[128, -128]
28  int16_t gyro_x; //[-4096, 4096]
29  int16_t gyro_y; //[-4096, 4096]
30  int16_t gyro_z; //[-4096, 4096]
31 
32  uint8_t flap_extension; //[0, 256]
33  uint8_t barometer_temp; //[0, 128]
34 };
35 
37  TelemetryDataLite datapoints[4];
38  float gps_lat;
39  float gps_long;
40  float gps_alt;
41  float gnc_state_x;
42  float gnc_state_vx;
43  float gnc_state_ax;
44  float gns_state_apo;
45  int16_t response_ID; //[0, 2^16]
46  int8_t rssi; //[-128, 128]
47  int8_t datapoint_count; //[0,4]
48  uint8_t voltage_battery; //[0, 16]
49  uint8_t FSM_State; //[0,256]
50 };
51 
52 // Data transmitted from rocket to ground station
54  float gps_lat;
55  float gps_long;
56  float gps_alt;
57  float barometer_alt;
58  float barometer_temp;
59  float barometer_pressure;
60  // KX134 (highg) IMU DATA
61  float KX_IMU_ax; // acceleration (in G's)
62  float KX_IMU_ay;
63  float KX_IMU_az;
64  // H3LIS331DL (highg) IMU DATA
65  float H3L_IMU_ax;
66  float H3L_IMU_ay;
67  float H3L_IMU_az;
68  // LSM9DS1 (lowg) IMU DATA
69  float LSM_IMU_ax; // acceleration (in G's)
70  float LSM_IMU_ay;
71  float LSM_IMU_az;
72  float LSM_IMU_gx; // Gyro data (in degrees/sec)
73  float LSM_IMU_gy;
74  float LSM_IMU_gz;
75  float LSM_IMU_mx;
76  float LSM_IMU_my;
77  float LSM_IMU_mz;
78 
79  float flap_extension;
80  float voltage_battry;
81 
82  float state_x;
83  float state_vx;
84  float state_ax;
85  float state_apo;
86 
87  int FSM_state;
88  char sign[8] = "HITHERE";
89  int rssi;
90  float battery_voltage;
91  int response_ID;
92 };
93 
94 // Commands transmitted from ground station to rocket
95 enum CommandType { SET_FREQ, SET_CALLSIGN, ABORT, TEST_FLAPS, EMPTY };
96 
98  CommandType command;
99  int cmd_id;
100  union {
101  char callsign[8];
102  float freq;
103  bool do_abort;
104  };
105  std::array<char, 6> verify;
106 };
107 
109  bool should_change{};
110  float new_freq{};
111 };
112 
113 class Telemetry {
114  public:
115  Telemetry();
116  void transmit(const sensorDataStruct_t&);
117  void handle_command(const telemetry_command& cmd);
118  bool abort = false;
119  void buffer_data(const sensorDataStruct_t&);
120 
121  private:
122  FifoBuffer<TelemetryDataLite, 4> buffered_data;
123  int packetnum;
124  telemetry_data d;
125  RH_RF95 rf95;
126 
127  File read_file;
128  File write_file;
129 
130  // Initializing command ID
131  int last_command_id = -1;
132 
133  // Initializing callsign
134  char callsign[8] = "NO SIGN";
135  command_handler_struct freq_status = {};
136 
137  TelemetryPacket make_packet(const sensorDataStruct_t&);
138 };
Definition: telemetry.h:113
void handle_command(const telemetry_command &cmd)
This function handles commands sent from the ground station to TARS. The effects of this function dep...
Definition: telemetry.cpp:99
void transmit(const sensorDataStruct_t &)
This function transmits data from the struct provided as the parameter (data collected from sensor su...
Definition: telemetry.cpp:145
Sensor (Low-G, High-G and GPS) struct definitions.
Definition: telemetry.h:21
Definition: telemetry.h:36
Definition: telemetry.h:108
A struct to hold all of the data that could come from any of the sensors.
Definition: dataLog.h:100
Definition: telemetry.h:97
Definition: telemetry.h:53