Skip to content

Commit 4242e18

Browse files
clean up
1 parent 742b267 commit 4242e18

10 files changed

Lines changed: 52 additions & 60 deletions

File tree

src/ControlTasks/RadioControlTask.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void RadioControlTask::init()
1111
#ifdef VERBOSE
1212
Serial.println(F("Radio: Initializing ... "));
1313
#endif
14-
// initialize SX1278 with default settings
14+
// Initialize SX1278 with default settings
1515
code = radio.begin(constants::radio::freq, constants::radio::bw, constants::radio::sf, constants::radio::cr,
1616
constants::radio::sw, constants::radio::pwr, constants::radio::pl, constants::radio::gn);
1717
if (code == RADIOLIB_ERR_NONE) {
@@ -28,7 +28,7 @@ void RadioControlTask::init()
2828
#ifdef VERBOSE
2929
Serial.println(F("Radio: Setting CRC parameter ... "));
3030
#endif
31-
// set CRC parameter to true so it matches the CRC parameter on the TinyGS side
31+
// Set CRC parameter to true so it matches the CRC parameter on the TinyGS side
3232
code = radio.setCRC(true);
3333
if (code == RADIOLIB_ERR_NONE) {
3434
sfr::radio::start_progress++;
@@ -43,7 +43,7 @@ void RadioControlTask::init()
4343
#ifdef VERBOSE
4444
Serial.println(F("Radio: Setting forceLDRO parameter ... "));
4545
#endif
46-
// set forceLDRO parameter to true so it matches the forceLDRO parameter on the TinyGS side
46+
// Set forceLDRO parameter to true so it matches the forceLDRO parameter on the TinyGS side
4747
code = radio.forceLDRO(true);
4848
if (code == RADIOLIB_ERR_NONE) {
4949
sfr::radio::initialized = true;
@@ -60,7 +60,7 @@ void RadioControlTask::init()
6060

6161
bool RadioControlTask::transmit(uint8_t *packet, uint8_t size)
6262
{
63-
// blink LED during transmit
63+
// Blink LED during transmit
6464
if (millis() - sfr::gps::boot_time > constants::led::led_on_time) {
6565
digitalWrite(constants::led::led_pin, HIGH);
6666
}
@@ -82,7 +82,7 @@ bool RadioControlTask::transmit(uint8_t *packet, uint8_t size)
8282
#endif
8383

8484
if (code == RADIOLIB_ERR_NONE) {
85-
// the packet was successfully transmitted
85+
// The packet was successfully transmitted
8686
#ifdef VERBOSE
8787
Serial.println(F("success!"));
8888
Serial.print(F("[SX1278] Datarate:\t"));
@@ -93,10 +93,10 @@ bool RadioControlTask::transmit(uint8_t *packet, uint8_t size)
9393
} else {
9494
#ifdef VERBOSE
9595
if (code == RADIOLIB_ERR_TX_TIMEOUT) {
96-
// timeout occurred while transmitting packet
96+
// Timeout occurred while transmitting packet
9797
Serial.println(F("timeout!"));
9898
} else {
99-
// some other error occurred
99+
// Some other error occurred
100100
Serial.print(F("failed, code "));
101101
Serial.println(code);
102102
}
@@ -131,13 +131,13 @@ bool RadioControlTask::receive()
131131
} else {
132132
#ifdef VERBOSE
133133
if (code == RADIOLIB_ERR_RX_TIMEOUT) {
134-
// timeout occurred while waiting for a packet
134+
// Timeout occurred while waiting for a packet
135135
Serial.println(F("timeout!"));
136136
} else if (code == RADIOLIB_ERR_CRC_MISMATCH) {
137-
// packet was received, but is malformed
137+
// Packet was received, but is malformed
138138
Serial.println(F("CRC error!"));
139139
} else {
140-
// some other error occurred
140+
// Some other error occurred
141141
Serial.print(F("failed, code "));
142142
Serial.println(code);
143143
}
@@ -148,7 +148,7 @@ bool RadioControlTask::receive()
148148

149149
void RadioControlTask::execute()
150150
{
151-
// implements the state machine described in: https://github.com/Alpha-CubeSat/oop-chipsat-code/wiki
151+
// Implement the state machine described in https://github.com/Alpha-CubeSat/oop-chipsat-code/wiki
152152
switch (sfr::radio::mode) {
153153
case radio_mode_type::init: {
154154
#ifdef VERBOSE
@@ -177,24 +177,24 @@ void RadioControlTask::execute()
177177
#ifdef VERBOSE
178178
Serial.println(F("Radio: Downlink State"));
179179
#endif
180-
// downlink when slot reached
180+
// Downlink when slot reached
181181
if (!sfr::radio::downlinked_in_slot && millis() - sfr::radio::downlink_window_start >= constants::radio::transmit_slot_length * sfr::radio::downlink_slot) {
182182
executeDownlink();
183183
sfr::radio::downlinked_in_slot = true;
184184
}
185185

186-
// go into listen mode if listen period reached
186+
// Go into listen mode if listen period reached
187187
if (millis() - sfr::radio::listen_period_start >= constants::radio::listen_period) {
188188
sfr::radio::mode = radio_mode_type::listen;
189189

190190
#ifdef VERBOSE
191191
Serial.println(F("Radio: Listen Flag Downlink"));
192192
#endif
193-
// downlink with listen flag = true
193+
// Downlink with listen flag = true
194194
normalReportDownlink();
195195
sfr::radio::command_wait_start = millis();
196196
}
197-
// reset window and choose slot for next downlink
197+
// Reset window and choose slot for next downlink
198198
else if (millis() - sfr::radio::downlink_window_start >= sfr::radio::downlink_window_length) {
199199
downlinkSettings();
200200
}
@@ -204,7 +204,7 @@ void RadioControlTask::execute()
204204
#ifdef VERBOSE
205205
Serial.println(F("Radio: Listen State"));
206206
#endif
207-
// built in timeout is 100 LoRa symbols
207+
// Built in timeout is 100 LoRa symbols
208208
bool receive_success = receive();
209209
if (receive_success) {
210210
processUplink();
@@ -250,7 +250,7 @@ bool RadioControlTask::executeDownlink()
250250

251251
bool RadioControlTask::normalReportDownlink()
252252
{
253-
// see https://github.com/Alpha-CubeSat/oop-chipsat-code/wiki/2.-Telemetry for more info
253+
// See https://github.com/Alpha-CubeSat/oop-chipsat-code/wiki/2.-Telemetry for more info
254254
uint16_t lat = sfr::gps::latitude * 100;
255255
uint16_t lon = sfr::gps::longitude * 100;
256256
uint16_t alt = sfr::gps::altitude / 10;
@@ -300,7 +300,7 @@ uint8_t RadioControlTask::map_range(float value, int min_val, int max_val)
300300

301301
void RadioControlTask::processUplink()
302302
{
303-
// see https://github.com/Alpha-CubeSat/oop-chipsat-code/wiki/3.-Commands for more info
303+
// See https://github.com/Alpha-CubeSat/oop-chipsat-code/wiki/3.-Commands for more info
304304
switch (received[0]) {
305305
case constants::opcodes::no_op: // No-Op
306306
#ifdef VERBOSE

src/ControlTasks/RadioControlTask.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RadioControlTask
2121
void init();
2222

2323
/**
24-
* Resets the transmit window start time and picks a new slot
24+
* @brief Resets the transmit window start time and picks a new slot
2525
*/
2626
void downlinkSettings();
2727

src/MainControlLoop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void MainControlLoop::execute()
7474
gps_monitor.execute();
7575
radio_control_task.execute();
7676

77-
// turn off LED 5 seconds after boot
77+
// Turn off LED 5 seconds after boot
7878
if (millis() - sfr::gps::boot_time > constants::led::led_on_time) {
7979
digitalWrite(constants::led::led_pin, LOW);
8080
}

src/Monitors/GPSMonitor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void GPSMonitor::init()
99
digitalWrite(constants::gps::reset_pin, LOW);
1010
sfr::gps::on = true;
1111

12-
// writes NMEA output message type to SRAM and Flash
12+
// Writes NMEA output message type to SRAM and Flash
1313
uint8_t SetNMEA[] = {
1414
0xA0, 0xA1, 0x00, 0x03, 0x09, 0x01, 0x01, 0x09, 0x0D, 0x0A};
1515

@@ -19,7 +19,7 @@ void GPSMonitor::init()
1919

2020
void GPSMonitor::execute()
2121
{
22-
// turn on GPS after boot mode is over (30 seconds)
22+
// Turn on GPS after boot mode is over (10 seconds)
2323
if (!sfr::gps::on) {
2424
if (millis() - sfr::gps::boot_time > constants::gps::boot_time) {
2525
init();
@@ -35,7 +35,7 @@ void GPSMonitor::execute()
3535
serial_reads++;
3636
}
3737

38-
// read GPS values if they are valid
38+
// Read GPS values if they are valid
3939
if (gps.location.isUpdated() && gps.location.isValid()) {
4040
sfr::gps::latitude = gps.location.lat();
4141
sfr::gps::longitude = gps.location.lng();

src/Monitors/GPSMonitor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GPSMonitor
2727
SoftwareSerial ss = SoftwareSerial(constants::gps::rx_pin, constants::gps::tx_pin);
2828

2929
/**
30-
* Begins the software serial instance and configures the GPS receiver
30+
* @brief Begins the software serial instance and configures the GPS receiver
3131
*/
3232
void init();
3333
};

src/Monitors/IMUMonitor.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,32 @@ void IMUMonitor::execute()
1818
} else {
1919
sfr::imu::initialized = true;
2020
}
21-
2221
} else {
2322
capture_imu_values();
2423
}
2524
}
2625

2726
void IMUMonitor::capture_imu_values()
2827
{
29-
// check if the gyroscope, accelerometer, or magnetometer has new data available
28+
// Check if the gyroscope, accelerometer, or magnetometer has new data available
3029
if (IMU.gyroscopeAvailable()) {
3130
IMU.readGyroscope(
3231
sfr::imu::gyro_x,
3332
sfr::imu::gyro_y,
34-
sfr::imu::gyro_z); // data is in degrees/s
33+
sfr::imu::gyro_z); // Data is in degrees/s
3534
}
3635

3736
if (IMU.accelerationAvailable()) {
3837
IMU.readAcceleration(
3938
sfr::imu::acc_x,
4039
sfr::imu::acc_y,
41-
sfr::imu::acc_z); // data is in m/s^2
40+
sfr::imu::acc_z); // Data is in m/s^2
4241
}
4342

4443
if (IMU.magneticFieldAvailable()) {
4544
IMU.readMagneticField(
4645
sfr::imu::mag_x,
4746
sfr::imu::mag_y,
48-
sfr::imu::mag_z); // data in uT
47+
sfr::imu::mag_z); // Data in uT
4948
}
5049
}

src/constants.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace constants {
1212
constexpr int radio_di0_pin = 2;
1313
constexpr int radio_rst_pin = 5;
1414
constexpr int radio_busy_pin = 16;
15-
// TODO: Document units
16-
constexpr float freq = 437.4;
17-
constexpr float bw = 62.5;
18-
constexpr int sf = 10;
19-
constexpr int cr = 5;
20-
constexpr int sw = 18;
21-
constexpr int pwr = 20;
22-
constexpr int pl = 8;
23-
constexpr int gn = 0;
15+
16+
constexpr float freq = 437.4; // MHz
17+
constexpr float bw = 62.5; // kHz
18+
constexpr int sf = 10; // Between 7 and 12
19+
constexpr int cr = 5; // Between 5 and 8. 4/8 coding ratio. One redundancy bit for every data bit
20+
constexpr int sw = 18; // Sync-word (defines network). Default is 0d18
21+
constexpr int pwr = 20; // Between 2 and 17, or 20 for max power
22+
constexpr int pl = 8; // Payload length
23+
constexpr int gn = 0; // Gain
2424

2525
constexpr uint8_t max_alive_signal_dlinks = 3;
2626

@@ -35,14 +35,14 @@ namespace constants {
3535
constexpr uint32_t callsign_interval = 10 * constants::time::one_minute;
3636

3737
constexpr uint32_t transmit_slot_length = 700; // ms
38-
// TODO: Verify sensor data on alive signal
38+
// TODO: Verify sensor data on alive signal
3939
} // namespace radio
4040
namespace imu {
41-
constexpr int gyro_min = -245; // default gyro range is +/- 245 dps
41+
constexpr int gyro_min = -245; // Default gyro range is +/- 245 dps
4242
constexpr int gyro_max = 245;
43-
constexpr int acc_min = -20; // default accel range is +/- 2 G
43+
constexpr int acc_min = -20; // Default accel range is +/- 2 G
4444
constexpr int acc_max = 20;
45-
constexpr int mag_min = -100; // default mag range is +/- 4 guass -> 100 uT
45+
constexpr int mag_min = -100; // Default mag range is +/- 4 guass -> 100 uT
4646
constexpr int mag_max = 100;
4747
} // namespace imu
4848
namespace temperature {
@@ -63,12 +63,10 @@ namespace constants {
6363
constexpr uint8_t no_op = 0x00;
6464
constexpr uint8_t change_downlink_window = 0x11;
6565
} // namespace opcodes
66-
6766
namespace led {
6867
constexpr int led_pin = 9;
6968
constexpr uint32_t led_on_time = 5 * constants::time::one_second;
7069
} // namespace led
71-
72-
}; // namespace constants
70+
}; // namespace constants
7371

7472
#endif

src/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MainControlLoop mcl;
55

66
void setup()
77
{
8-
// configure watchdog timer
8+
// Set up watchdog timer
99
wdt_disable();
1010
wdt_enable(WDTO_8S);
1111
#ifdef VERBOSE
@@ -14,19 +14,19 @@ void setup()
1414

1515
sfr::gps::boot_time = millis();
1616

17-
// sets ChipSat LED high for debugging
17+
// Set ChipSat LED high for debugging
1818
pinMode(constants::led::led_pin, OUTPUT);
1919
digitalWrite(constants::led::led_pin, HIGH);
2020

21-
// cuts off power to GPS
21+
// Cut off power to GPS
2222
pinMode(constants::gps::reset_pin, OUTPUT);
2323
digitalWrite(constants::gps::reset_pin, HIGH);
2424

25-
// prevents current from leaking over GPS serial line (~79mA -> ~22mA)
25+
// Prevents current from leaking over GPS serial line (~79mA -> ~22mA)
2626
pinMode(constants::gps::tx_pin, OUTPUT);
2727
digitalWrite(constants::gps::tx_pin, LOW);
2828

29-
// seed random number gen with noise from unconnected analog pin
29+
// Seed random number gen with noise from unconnected analog pin
3030
randomSeed(analogRead(A0));
3131
}
3232

src/sfr.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#include "sfr.hpp"
22

33
namespace sfr {
4-
54
namespace imu {
5+
bool initialized = false;
66

77
float gyro_x, gyro_y, gyro_z;
88
float acc_x, acc_y, acc_z;
99
float mag_x, mag_y, mag_z;
1010

11-
bool initialized = false;
12-
1311
} // namespace imu
14-
1512
namespace temperature {
1613
float temp_c;
1714
} // namespace temperature
@@ -31,7 +28,6 @@ namespace sfr {
3128
uint8_t alive_signal_dlinks = 0;
3229

3330
// This must be a multiple of constants::radio::transmit_slot_length
34-
// Ideally window should be 10x the slot length
3531
uint32_t downlink_window_length = 3500; // ms
3632
uint32_t downlink_window_start;
3733
uint32_t listen_period_start;
@@ -45,5 +41,4 @@ namespace sfr {
4541
uint8_t invalid_uplinks = 0;
4642

4743
} // namespace radio
48-
49-
}; // namespace sfr
44+
}; // namespace sfr

src/sfr.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace sfr {
99
namespace imu {
10+
extern bool initialized;
11+
1012
extern float gyro_x;
1113
extern float gyro_y;
1214
extern float gyro_z;
@@ -19,7 +21,6 @@ namespace sfr {
1921
extern float mag_y;
2022
extern float mag_z;
2123

22-
extern bool initialized;
2324
} // namespace imu
2425
namespace temperature {
2526
extern float temp_c;
@@ -56,7 +57,6 @@ namespace sfr {
5657

5758
extern uint32_t boot_time;
5859
} // namespace gps
59-
60-
}; // namespace sfr
60+
}; // namespace sfr
6161

6262
#endif

0 commit comments

Comments
 (0)