Skip to content

Commit e9cd69a

Browse files
committed
Squashed Commit: Clang Workflow
clang format workflow clang-format rm invalid option fix format options run format with new settings manual fix for macro disable sort includes Add OpenRocket flight data standardization for integration testing (#11) * Standardized data format to OpenRocket output CSV * Ignore data files and OpenRocket * Standardized data format to OpenRocket output CSV * Ignore data files and OpenRocket Add support for pyro board SPI through native_sim (#12) * Standardized data format to OpenRocket output CSV * Ignore data files and OpenRocket * Add integration test steps to README * Add integration test steps to README * Added pyro board SPI support for native_sim fix new sim baro
1 parent 8f0c860 commit e9cd69a

36 files changed

Lines changed: 1054 additions & 984 deletions

File tree

.clang-format

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
BasedOnStyle: LLVM
3+
ColumnLimit: 100
4+
IndentWidth: 4
5+
InsertNewlineAtEOF: true
6+
AlignEscapedNewlines: Left
7+
AllowShortBlocksOnASingleLine: Never
8+
AllowShortCaseLabelsOnASingleLine: false
9+
AllowShortEnumsOnASingleLine: false
10+
AllowShortFunctionsOnASingleLine: None
11+
AllowShortIfStatementsOnASingleLine: Never
12+
AllowShortLoopsOnASingleLine: false
13+
BreakBeforeBraces: Linux
14+
InsertBraces: true
15+
IndentGotoLabels: false
16+
SortIncludes: false
17+
ReflowComments: true

.github/workflows/style-check.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Linter
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
clang-format:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v3
12+
13+
- name: Which Clang-Format
14+
run: |
15+
which clang-format
16+
clang-format --version
17+
18+
- name: Run clang-format check
19+
run: |
20+
echo "Checking C code style..."
21+
failed=0
22+
files=$(find . -name '*.c' -o -name '*.h')
23+
for f in $files; do
24+
diff_output=$(diff -u "$f" <(clang-format -style=file "$f") || true)
25+
if [ -n "$diff_output" ]; then
26+
echo "Style issues in $f:"
27+
echo "$diff_output"
28+
failed=1
29+
fi
30+
done
31+
if [ $failed -eq 1 ]; then
32+
echo "Some files do not match the style. Fix with clang-format."
33+
exit 1
34+
else
35+
echo "Style check passed"
36+
fi

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
**/build/
22
.DS_Store
33
twister-out*
4-
.cache
4+
.cache
5+
6+
data/
7+
*.jar
8+
*.ork

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ TODO
3434
- Zephyr Documentation: https://docs.zephyrproject.org/latest/index.html
3535
- Highly recommend watching this tutorial series (Videos 9, 10, and 11 shouldnt be necessary for this project): https://www.youtube.com/playlist?list=PLEBQazB0HUyTmK2zdwhaf8bLwuEaDH-52
3636

37+
## Integration Testing
38+
### Zephyr's Native Sim
39+
#### Getting the data
40+
1. Follow the installation instruction for OpenRocket: https://openrocket.readthedocs.io/en/latest/setup/installation.html
41+
2. Boot up OpenRocket and load the .ork file
42+
3. Under Flight Simulations, open a previous simulation by double clicking on the row
43+
4. Under Export Data, click "select all" and ensure that only the "Include field descriptions" option is checked.
44+
5. Click Export and save your csv file
45+
46+
#### Running the integration test
47+
1. Ensure you're in the virtual environment using inside `FALCON/`:
48+
- `source .venv/bin/activate` (MacOS/Linux) or `.venv\Scripts\activate.bat` (Windows)
49+
2. Build FALCON using Zephyr's built in native_sim board:
50+
- `west build -b native_sim/native/64 app/apps/rockets/cloudburst -- -DDTC_OVERLAY_FILE="$(pwd)/boards/native_sim.overlay" -DDATA_FILE="$(pwd)/<PATH>/<DATA_FILE>.csv"`
51+
- Replace `PATH` and `DATA_FILE` with the location and name of your OpenRocket csv file
52+
3. Run the integration test:
53+
- For a realtime test, use `west build -t run`
54+
- To run at the maximum speed, use `./app/build/zephyr/zephyr.exe --no-rt`
55+
- To run at a custom speed, use `./app/build/zephyr/zephyr.exe --rt-ratio=2`
56+
57+
### QEMU (WIP)
58+
59+
3760
## Debugging
3861
### Terminal debugging:
3962
*Should work out of the box provided your zephyr environment is set up correctly*

apps/peripheral_tests/blinky_test/src/main.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66

77
#include <stdio.h>
8-
#include <zephyr/kernel.h>
98
#include <zephyr/drivers/gpio.h>
9+
#include <zephyr/kernel.h>
1010

1111
/* 1000 msec = 1 sec */
12-
#define SLEEP_TIME_MS 500
12+
#define SLEEP_TIME_MS 500
1313

1414
/* The devicetree node identifier for the "led0" alias. */
1515
#define LED0_NODE DT_ALIAS(led0)
@@ -22,28 +22,28 @@ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
2222

2323
int main(void)
2424
{
25-
int ret;
26-
bool led_state = true;
27-
28-
if (!gpio_is_ready_dt(&led)) {
29-
return 0;
30-
}
31-
32-
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
33-
if (ret < 0) {
34-
return 0;
35-
}
36-
37-
while (1) {
38-
ret = gpio_pin_toggle_dt(&led);
39-
if (ret < 0) {
40-
return 0;
41-
}
25+
int ret;
26+
bool led_state = true;
27+
28+
if (!gpio_is_ready_dt(&led)) {
29+
return 0;
30+
}
31+
32+
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
33+
if (ret < 0) {
34+
return 0;
35+
}
36+
37+
while (1) {
38+
ret = gpio_pin_toggle_dt(&led);
39+
if (ret < 0) {
40+
return 0;
41+
}
4242
printf("Toggling LED\n");
4343

44-
led_state = !led_state;
45-
printf("LED state: %s\n", led_state ? "ON" : "OFF");
46-
k_msleep(SLEEP_TIME_MS);
47-
}
48-
return 0;
44+
led_state = !led_state;
45+
printf("LED state: %s\n", led_state ? "ON" : "OFF");
46+
k_msleep(SLEEP_TIME_MS);
47+
}
48+
return 0;
4949
}

apps/peripheral_tests/sd_test/src/main.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <zephyr/kernel.h>
1+
#include <ff.h>
22
#include <zephyr/device.h>
3-
#include <zephyr/storage/disk_access.h>
43
#include <zephyr/fs/fs.h>
4+
#include <zephyr/kernel.h>
55
#include <zephyr/logging/log.h>
6-
#include <ff.h>
6+
#include <zephyr/storage/disk_access.h>
77

88
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
99

@@ -14,18 +14,16 @@ LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
1414
static FATFS fat_fs;
1515

1616
static struct fs_mount_t fatfs_mnt = {
17-
.type = FS_FATFS,
18-
.mnt_point = MOUNT_POINT,
19-
.fs_data = &fat_fs
20-
};
17+
.type = FS_FATFS, .mnt_point = MOUNT_POINT, .fs_data = &fat_fs};
2118

22-
void write_test_log(void) {
19+
void write_test_log(void)
20+
{
2321
struct fs_file_t file;
2422
int ret;
2523
fs_file_t_init(&file);
2624

2725
// Open or create a file for writing
28-
ret = fs_open(&file, MOUNT_POINT "/log.txt", FS_O_CREATE |FS_O_WRITE);
26+
ret = fs_open(&file, MOUNT_POINT "/log.txt", FS_O_CREATE | FS_O_WRITE);
2927
if (ret) {
3028
LOG_ERR("Failed to open file: %d", ret);
3129
return;
@@ -44,7 +42,8 @@ void write_test_log(void) {
4442
fs_close(&file);
4543
}
4644

47-
void mount_sd_card(void) {
45+
void mount_sd_card(void)
46+
{
4847
int ret;
4948

5049
// Initialize the SDMMC disk
@@ -65,7 +64,8 @@ void mount_sd_card(void) {
6564
}
6665
}
6766

68-
int main(void) {
67+
int main(void)
68+
{
6969
LOG_INF("SD Test Application Started");
7070

7171
// Mount the SD card
@@ -75,10 +75,10 @@ int main(void) {
7575
write_test_log();
7676

7777
int res = fs_unmount(&fatfs_mnt);
78-
if (res != 0) {
79-
printk("Error unmounting disk\n");
80-
return res;
81-
}
78+
if (res != 0) {
79+
printk("Error unmounting disk\n");
80+
return res;
81+
}
8282

8383
return 0;
8484
}

apps/peripheral_tests/sensor_test/src/main.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include <zephyr/kernel.h>
21
#include <zephyr/device.h>
32
#include <zephyr/devicetree.h>
43
#include <zephyr/drivers/sensor.h>
4+
#include <zephyr/kernel.h>
55
#include <zephyr/logging/log.h>
66

77
LOG_MODULE_REGISTER(sensor_test, LOG_LEVEL_INF);
@@ -65,12 +65,11 @@ int main(void)
6565
sensor_channel_get(baro_dev, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
6666

6767
LOG_INF("Pressure: %.2f mPa, Temperature: %.2f degC",
68-
sensor_value_to_double(&pressure),
69-
sensor_value_to_double(&temperature));
68+
sensor_value_to_double(&pressure), sensor_value_to_double(&temperature));
7069
} else {
7170
LOG_ERR("Failed to fetch data from barometer sensor");
7271
}
73-
}
72+
}
7473
#endif
7574

7675
#if TEST_GYRO_SENSOR
@@ -81,8 +80,7 @@ int main(void)
8180
sensor_channel_get(gyro_dev, SENSOR_CHAN_GYRO_Z, &gyro_z);
8281

8382
LOG_INF("Gyroscope (rad/s): X=%.2f, Y=%.2f, Z=%.2f",
84-
sensor_value_to_double(&gyro_x),
85-
sensor_value_to_double(&gyro_y),
83+
sensor_value_to_double(&gyro_x), sensor_value_to_double(&gyro_y),
8684
sensor_value_to_double(&gyro_z));
8785
} else {
8886
LOG_ERR("Failed to fetch data from gyroscope");
@@ -98,8 +96,7 @@ int main(void)
9896
sensor_channel_get(accel_dev, SENSOR_CHAN_ACCEL_Z, &accel_z);
9997

10098
LOG_INF("Acceleration (m/s^2): X=%.2f, Y=%.2f, Z=%.2f",
101-
sensor_value_to_double(&accel_x),
102-
sensor_value_to_double(&accel_y),
99+
sensor_value_to_double(&accel_x), sensor_value_to_double(&accel_y),
103100
sensor_value_to_double(&accel_z));
104101
} else {
105102
LOG_ERR("Failed to fetch data from accelerometer");
@@ -111,4 +108,4 @@ int main(void)
111108
k_sleep(K_MSEC(1000));
112109
}
113110
return 0;
114-
}
111+
}

apps/rockets/cloudburst/src/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#include "data.h"
12
#include <zephyr/kernel.h>
23
#include <zephyr/logging/log.h>
3-
#include "data.h"
44

55
LOG_MODULE_REGISTER(data, LOG_LEVEL_INF);
66

apps/rockets/cloudburst/src/data.h

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
#include <stdint.h>
55

6-
typedef enum
7-
{
6+
typedef enum {
87
FLIGHT_STATE_STANDBY = 0,
98
FLIGHT_STATE_ASCENT,
109
FLIGHT_STATE_MACH_LOCK,
@@ -14,40 +13,36 @@ typedef enum
1413
} flight_state_id_t;
1514

1615
// Data structures for sensor data
17-
struct imu_data
18-
{
16+
struct imu_data {
1917
float accel[3]; // Acceleration in m/s²
2018
float gyro[3]; // Angular velocity in rad/s
2119
int64_t timestamp; // Timestamp in milliseconds
2220
};
2321

2422
// Per-barometer sensor data
25-
struct baro_sensor_data
26-
{
27-
float pressure; // Pressure in Pa
28-
float temperature; // Temperature in °C
29-
float altitude; // Altitude in meters (from pressure + temp)
30-
float nis; // Normalized innovation squared
31-
uint8_t faults; // Accumulated fault count
32-
bool healthy; // Health status (accepted/rejected)
23+
struct baro_sensor_data {
24+
float pressure; // Pressure in Pa
25+
float temperature; // Temperature in °C
26+
float altitude; // Altitude in meters (from pressure + temp)
27+
float nis; // Normalized innovation squared
28+
uint8_t faults; // Accumulated fault count
29+
bool healthy; // Health status (accepted/rejected)
3330
};
3431

3532
// Combined barometer data (shared with other threads)
36-
struct baro_data
37-
{
38-
struct baro_sensor_data baro0; // Barometer 0
39-
struct baro_sensor_data baro1; // Barometer 1
33+
struct baro_data {
34+
struct baro_sensor_data baro0; // Barometer 0
35+
struct baro_sensor_data baro1; // Barometer 1
4036

41-
float altitude; // Kalman-filtered altitude estimate in meters
42-
float alt_variance; // Kalman filter variance (P)
43-
float velocity; // Vertical velocity estimate (m/s)
44-
float vel_variance; // Velocity variance (P11)
37+
float altitude; // Kalman-filtered altitude estimate in meters
38+
float alt_variance; // Kalman filter variance (P)
39+
float velocity; // Vertical velocity estimate (m/s)
40+
float vel_variance; // Velocity variance (P11)
4541

46-
int64_t timestamp; // Timestamp in milliseconds
42+
int64_t timestamp; // Timestamp in milliseconds
4743
};
4844

49-
struct state_data
50-
{
45+
struct state_data {
5146
flight_state_id_t state;
5247
float ground_altitude;
5348
int64_t timestamp;

apps/rockets/cloudburst/src/log_format.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include "data.h"
55
#include <stdint.h>
66

7-
struct log_frame
8-
{
7+
struct log_frame {
98
int64_t log_timestamp;
109

1110
struct imu_data imu;

0 commit comments

Comments
 (0)