Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 692b29f

Browse files
committed
Fixed lib-common update errors, added IMU to commands
1 parent 0034fd3 commit 692b29f

File tree

5 files changed

+73
-44
lines changed

5 files changed

+73
-44
lines changed

manual_tests/main_test/main_test.c

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ void print_therm_temp(uint16_t raw_data) {
8686
print(" 0x%.3X = %.2f C\n", raw_data, adc_raw_data_to_therm_temp(raw_data));
8787
}
8888

89-
void print_imu_data(uint16_t raw_data) {
90-
print(" 0x%.4X\n", raw_data);
89+
void print_imu_gyro(uint16_t raw_data) {
90+
print(" 0x%.4X = %.3f rad/s\n", raw_data, imu_raw_data_to_gyro(raw_data));
9191
}
9292

9393
void process_eps_hk_tx_msg(uint8_t* tx_msg) {
@@ -154,41 +154,29 @@ void process_eps_hk_tx_msg(uint8_t* tx_msg) {
154154
print("Heater Setpoint 2:");
155155
print_therm_temp(raw_data);
156156
break;
157-
case CAN_EPS_HK_IMU_ACC_X:
158-
print("Acc X:");
159-
print_imu_data(raw_data);
157+
case CAN_EPS_HK_GYR_UNCAL_X:
158+
print("Gyro (Uncal) X:");
159+
print_imu_gyro(raw_data);
160160
break;
161-
case CAN_EPS_HK_IMU_ACC_Y:
162-
print("Acc Y:");
163-
print_imu_data(raw_data);
161+
case CAN_EPS_HK_GYR_UNCAL_Y:
162+
print("Gyro (Uncal) Y:");
163+
print_imu_gyro(raw_data);
164164
break;
165-
case CAN_EPS_HK_IMU_ACC_Z:
166-
print("Acc Z:");
167-
print_imu_data(raw_data);
165+
case CAN_EPS_HK_GYR_UNCAL_Z:
166+
print("Gyro (Uncal) Z:");
167+
print_imu_gyro(raw_data);
168168
break;
169-
case CAN_EPS_HK_IMU_GYR_X:
170-
print("Gyr X:");
171-
print_imu_data(raw_data);
169+
case CAN_EPS_HK_GYR_CAL_X:
170+
print("Gyro (Cal) X:");
171+
print_imu_gyro(raw_data);
172172
break;
173-
case CAN_EPS_HK_IMU_GYR_Y:
174-
print("Gyr Y:");
175-
print_imu_data(raw_data);
173+
case CAN_EPS_HK_GYR_CAL_Y:
174+
print("Gyro (Cal) Y:");
175+
print_imu_gyro(raw_data);
176176
break;
177-
case CAN_EPS_HK_IMU_GYR_Z:
178-
print("Gyr Z:");
179-
print_imu_data(raw_data);
180-
break;
181-
case CAN_EPS_HK_IMU_MAG_X:
182-
print("Mag X:");
183-
print_imu_data(raw_data);
184-
break;
185-
case CAN_EPS_HK_IMU_MAG_Y:
186-
print("Mag Y:");
187-
print_imu_data(raw_data);
188-
break;
189-
case CAN_EPS_HK_IMU_MAG_Z:
190-
print("Mag Z:");
191-
print_imu_data(raw_data);
177+
case CAN_EPS_HK_GYR_CAL_Z:
178+
print("Gyro (Cal) Z:");
179+
print_imu_gyro(raw_data);
192180
break;
193181
default:
194182
return;
@@ -353,12 +341,13 @@ int main(void) {
353341
WDT_ENABLE_SYS_RESET(WDTO_8S);
354342

355343
init_eps();
344+
set_uart_baud_rate(UART_BAUD_115200);
356345

357346
print("\n\n\nStarting commands test\n\n");
358347

359348
// Change these as necessary for testing
360349
sim_local_actions = false;
361-
sim_obc = false;
350+
sim_obc = true;
362351
print_can_msgs = true;
363352

364353
print("sim_local_actions = %u\n", sim_local_actions);

manual_tests/main_test/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
PROG = main_test
22
# SRC should only include necessary files
3-
SRC = $(addprefix ../../src/,can_commands.c can_interface.c devices.c general.c shunts.c)
3+
SRC = $(addprefix ../../src/,can_commands.c can_interface.c devices.c general.c imu.c shunts.c)
44
include ../makefile

src/can_commands.c

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,52 @@ void handle_rx_hk(uint8_t* rx_msg) {
7979
}
8080
}
8181

82-
else if ((CAN_EPS_HK_IMU_ACC_X <= field_num) &&
83-
(field_num <= CAN_EPS_HK_IMU_MAG_Z)) {
84-
// TODO - get IMU data
85-
data = random() & 0x7FFF;
82+
else if ((CAN_EPS_HK_GYR_UNCAL_X <= field_num) &&
83+
(field_num <= CAN_EPS_HK_GYR_UNCAL_Z)) {
84+
if (sim_local_actions) {
85+
data = random() & 0x7FFF;
86+
} else {
87+
uint16_t uncal_x = 0, uncal_y = 0, uncal_z = 0;
88+
get_imu_uncal_gyro(&uncal_x, &uncal_y, &uncal_z, NULL, NULL, NULL);
89+
90+
switch (field_num) {
91+
case CAN_EPS_HK_GYR_UNCAL_X:
92+
data = (uint32_t) uncal_x;
93+
break;
94+
case CAN_EPS_HK_GYR_UNCAL_Y:
95+
data = (uint32_t) uncal_y;
96+
break;
97+
case CAN_EPS_HK_GYR_UNCAL_Z:
98+
data = (uint32_t) uncal_z;
99+
break;
100+
default:
101+
break;
102+
}
103+
}
104+
}
105+
106+
else if ((CAN_EPS_HK_GYR_CAL_X <= field_num) &&
107+
(field_num <= CAN_EPS_HK_GYR_CAL_Z)) {
108+
if (sim_local_actions) {
109+
data = random() & 0x7FFF;
110+
} else {
111+
uint16_t cal_x = 0, cal_y = 0, cal_z = 0;
112+
get_imu_cal_gyro(&cal_x, &cal_y, &cal_z);
113+
114+
switch (field_num) {
115+
case CAN_EPS_HK_GYR_CAL_X:
116+
data = (uint32_t) cal_x;
117+
break;
118+
case CAN_EPS_HK_GYR_CAL_Y:
119+
data = (uint32_t) cal_y;
120+
break;
121+
case CAN_EPS_HK_GYR_CAL_Z:
122+
data = (uint32_t) cal_z;
123+
break;
124+
default:
125+
break;
126+
}
127+
}
86128
}
87129

88130
// If the message type is not recognized, return before enqueueing

src/can_commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "can_interface.h"
1212
#include "devices.h"
1313
#include "general.h"
14+
#include "imu.h"
1415

1516
extern queue_t can_rx_msg_queue;
1617
extern queue_t can_tx_msg_queue;

src/general.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ void init_eps(void) {
66
// UART
77
init_uart();
88

9-
// TODO - remove and call init_imu()
10-
// Set the IMU CSn (PD0) high (because it doesn't have a pullup resistor)
11-
// so it doesn't interfere with the MOSI/MISO lines
12-
init_cs(PD0, &DDRD);
13-
set_cs_high(PD0, &PORTD);
14-
159
// SPI
1610
init_spi();
1711

@@ -27,6 +21,9 @@ void init_eps(void) {
2721
// Shunts
2822
init_shunts();
2923

24+
// IMU
25+
init_imu();
26+
3027
// Queues
3128
init_queue(&can_rx_msg_queue);
3229
init_queue(&can_tx_msg_queue);

0 commit comments

Comments
 (0)