Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
main.c File Reference
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for main.c:

Go to the source code of this file.

Classes

struct  map
 

Macros

#define NUM_TESTS   (sizeof(name_to_main) / sizeof(name_to_main[0]))
 

Functions

void lut_main ()
 
void wheel_speed_main ()
 
void torque_control_main ()
 
void apps_main ()
 
void bms_main ()
 
void run_all_tests ()
 
void run_test (const char *name)
 
int main (int argc, char **argv)
 

Variables

static map name_to_main []
 

Macro Definition Documentation

◆ NUM_TESTS

#define NUM_TESTS   (sizeof(name_to_main) / sizeof(name_to_main[0]))

Definition at line 30 of file main.c.

Function Documentation

◆ apps_main()

void apps_main ( )

Definition at line 13 of file AppsTest.c.

13 {
14 TEST(apps_init, {
15 Apps apps;
16 initApps(&apps, 0, 0, 1);
17 ASSERT_OK(apps.status == APPS_OK, "intial status");
18 })
19
20 TEST(normal_operation_0, {
21 APPS_DO(0, 0)
22 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
23 ASSERT_EQ(pos, 0, "position", "expected position");
24 })
25
26 TEST(normal_operation_50, {
27 APPS_DO(50, 50)
28 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
29 ASSERT_EQ(pos, 50, "position", "expected position");
30 })
31
32 TEST(normal_operation_100, {
33 APPS_DO(100, 100)
34 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
35 ASSERT_EQ(pos, 100, "position", "expected position");
36 })
37
38 TEST(normal_operation_50_60, {
39 APPS_DO(50, 60);
40 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
41 ASSERT_EQ(pos, 55, "position", "expected position");
42 })
43
44 TEST(normal_operation_55_56, {
45 APPS_DO(55, 56);
46 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
47 ASSERT_EQ(pos, 55.5, "position", "expected position");
48 })
49
50 TEST(edge_difference_0_10, {
51 APPS_DO(0, 10);
52 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
53 ASSERT_EQ(pos, 5, "position", "expected position");
54 })
55
56 TEST(edge_difference_50_60, {
57 APPS_DO(50, 60);
58 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
59 ASSERT_EQ(pos, 55, "position", "expected position");
60 })
61
62 TEST(edge_difference_90_100, {
63 APPS_DO(90, 100);
64 ASSERT(apps.status == APPS_OK, "status is expected", "status is not expected");
65 ASSERT_EQ(pos, 95, "position", "expected position");
66 })
67
68 TEST(edge_difference_0_1001, {
69 APPS_DO(0, 10.01);
70 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
71 ASSERT_EQ(pos, 0, "position", "expected position");
72 })
73
74 TEST(edge_difference_50_61, {
75 APPS_DO(50, 51);
76 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
77 ASSERT_EQ(pos, 0, "position", "expected position");
78 })
79
80 TEST(edge_difference_0_100, {
81 APPS_DO(0, 100);
82 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
83 ASSERT_EQ(pos, 0, "position", "expected position");
84 })
85
86 TEST(sensor_1_under, {
87 APPS_DO(-1, 50);
88 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
89 ASSERT_EQ(pos, 0, "position", "expected position");
90 })
91
92 TEST(sensor_1_over, {
93 APPS_DO(101, 50);
94 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
95 ASSERT_EQ(pos, 0, "position", "expected position");
96 })
97
98 TEST(sensor_2_under, {
99 APPS_DO(50, -1);
100 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
101 ASSERT_EQ(pos, 0, "position", "expected position");
102 })
103
104 TEST(sensor_2_over, {
105 APPS_DO(50, 101);
106 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
107 ASSERT_EQ(pos, 0, "position", "expected position");
108 })
109
110 TEST(sensors_under, {
111 APPS_DO(-1, -1);
112 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
113 ASSERT_EQ(pos, 0, "position", "expected position");
114 })
115
116 TEST(sensors_over, {
117 APPS_DO(101, 101);
118 ASSERT(apps.status == APPS_FAULT, "status is expected", "status is not expected");
119 ASSERT_EQ(pos, 0, "position", "expected position");
120 })
121}
#define APPS_DO(pos1, pos2)
Definition: AppsTest.c:5
@ APPS_OK
Definition: Apps.h:17
@ APPS_FAULT
Definition: Apps.h:18
void initApps(Apps *apps, int hz, int channel1, int channel2)
Initializes the APPs with the given frequency and channel.
Definition: Apps.c:30
Definition: Apps.h:21
AppsStatus status
Definition: Apps.h:23
#define ASSERT_OK(BOOL, LABEL)
Definition: test.h:29
#define TEST(NAME, BODY)
Definition: test.h:19
#define ASSERT_EQ(GOT, WANT, GOT_LABEL, WANT_LABEL)
Definition: test.h:32
#define ASSERT(BOOL, OK, ERR)
Definition: test.h:27
Here is the call graph for this function:

◆ bms_main()

void bms_main ( )

Definition at line 32 of file BMSTest.c.

32 {
33 TEST(bms_init, {
34 Bms bms;
35 initBms(&bms, BmsHz, "Tests/Systems/External/Orion_CANBUS.dbc");
36 ASSERT(bms.chargeStatus == IDLE, "bms is idle", "bms is not idle");
37 ASSERT_EQ(bms.packVoltage, 0, "pack voltage", "expected pack voltage");
38 ASSERT_EQ(bms.packCurrent, 0, "pack current", "expected pack current");
39 })
40
41 Bms expectedBms;
42 initBms(&expectedBms, BmsHz, "Tests/Systems/External/Orion_CANBUS.dbc");
43 expectedBms.packVoltage = 600.0f;
44 expectedBms.packVoltage = 400.0f;
45 expectedBms.stateOfCharge = 80.0f;
46
47 TEST(bms_update, {
48 Bms bms;
49 initBms(&bms, BmsHz, "Tests/Systems/External/Orion_CANBUS.dbc");
50 updateBmsTest(&bms, "Tests/Systems/External/BmsFakeCanData.txt");
51 // FIXME Should this be equal or !equal? Original had it as equal is a failure
52 ASSERT(!equal(&bms, &expectedBms), "bms doesn't equal expected bms", "bms equals expected bms");
53 })
54}
#define BmsHz
Definition: BMSTest.c:30
bool equal(Bms *bms1, Bms *bms2)
Definition: BMSTest.c:14
void updateBmsTest(void *bms, const char *canDataFn)
Updates the BMS data.
Definition: BMS.c:96
@ IDLE
Definition: BMS.h:12
void initBms(Bms *bms, int hz, const char *dbcFn)
Initializes the BMS with the given frequency.
Definition: BMS.c:7
Definition: BMS.h:15
float packVoltage
Definition: BMS.h:19
BmsChargeStatus chargeStatus
Definition: BMS.h:29
float packCurrent
Definition: BMS.h:20
Here is the call graph for this function:

◆ lut_main()

void lut_main ( )

Definition at line 115 of file LUT.c.

115 {
116 table pressure_mb_to_altitude_m;
117 assert(table_init(&pressure_mb_to_altitude_m, 9));
118
119 test_uninitialized_table(&pressure_mb_to_altitude_m);
120
121 // Initializes the table with equally-spaced points using the transfer
122 // function
123 for (unsigned int reference_pressure_mb = 300; reference_pressure_mb <= 1100;
124 reference_pressure_mb += 100) {
126 &pressure_mb_to_altitude_m, reference_pressure_mb,
127 altitude_m_at_pressure_mb(reference_pressure_mb)));
128 }
129
130 test_initialized_table(&pressure_mb_to_altitude_m);
131
132 test_sampling_endpoints(&pressure_mb_to_altitude_m);
133
134 test_sampling_reference_point(&pressure_mb_to_altitude_m);
135
136 test_sampling_unknown_point(&pressure_mb_to_altitude_m);
137}
bool table_init(table *table, uint16_t count)
Initializes the table.
Definition: LUT.c:31
bool table_add_reference_point(table *table, float in, float out)
Adds a reference point to the table.
Definition: LUT.c:79
void test_sampling_reference_point(table *table)
Definition: LUT.c:87
void test_uninitialized_table(table *table)
Definition: LUT.c:20
void test_sampling_endpoints(table *table)
Definition: LUT.c:63
void test_initialized_table(table *table)
Definition: LUT.c:41
float altitude_m_at_pressure_mb(float pressure_mb)
Definition: LUT.c:11
void test_sampling_unknown_point(table *table)
Definition: LUT.c:101
Definition: LUT.h:40
Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file main.c.

49 {
50 bool all = false;
51
52 int opt;
53 while ((opt = getopt(argc, argv, "a")) != -1) {
54 switch (opt) {
55 case 'a':
56 all = true;
57 break;
58 default:
59 fprintf(stderr, "Usage: %s [-a] [tests]\n", argv[0]);
60 exit(EXIT_FAILURE);
61 }
62 }
63
64 if (all) {
66 }
67
68 if (optind >= argc) {
69 fprintf(stderr, "Expected name of test\n");
70 exit(EXIT_FAILURE);
71 }
72
73 for (int n = optind; n < argc; ++n) {
74 run_test(argv[n]);
75 }
76
77 return EXIT_SUCCESS;
78}
void run_test(const char *name)
Definition: main.c:39
void run_all_tests()
Definition: main.c:32
Here is the call graph for this function:

◆ run_all_tests()

void run_all_tests ( )

Definition at line 32 of file main.c.

32 {
33 for (int n = 0; n < NUM_TESTS; ++n) {
34 name_to_main[n].main();
35 }
36 exit(EXIT_SUCCESS);
37}
#define NUM_TESTS
Definition: main.c:30
static map name_to_main[]
Definition: main.c:24
void(* main)()
Definition: main.c:19
Here is the caller graph for this function:

◆ run_test()

void run_test ( const char *  name)

Definition at line 39 of file main.c.

39 {
40 for (int n = 0; n < NUM_TESTS; ++n) {
41 map entry = name_to_main[n];
42 if (strncmp(entry.name, name, strlen(entry.name)) == 0) {
43 entry.main();
44 }
45 }
46 exit(EXIT_SUCCESS);
47}
Definition: main.c:17
const char * name
Definition: main.c:18
Here is the caller graph for this function:

◆ torque_control_main()

void torque_control_main ( )

Definition at line 14 of file TorqueControlActuatorTest.c.

14 {
15 TEST(torque_init, {
17 initTorqueControl(&tc, 0, 100);
18 ASSERT(tc.status == TORQUE_OK, "status is expected", "status is not expected");
19 })
20
21 TEST(update_normal, {
22 TORQUE_DO(75, 75)
23 ASSERT(tc.status == TORQUE_OK, "status is expected", "status is not expected");
24 })
25
26 TEST(update_below_desired, {
27 TORQUE_DO(93.5, 95)
28 ASSERT(tc.status == TORQUE_OK, "status is expected", "status is not expected");
29 })
30
31 TEST(update_above_desired, {
32 TORQUE_DO(98.5, 95)
33 ASSERT(tc.status == TORQUE_OK, "status is expected", "status is not expected");
34 })
35
36 TEST(update_over_limit, {
37 TORQUE_DO(101, 95)
38 ASSERT(tc.status == TORQUE_OVER_LIMIT, "status is expected", "status is not expected");
39 })
40
41 TEST(update_negative_torque, {
42 TORQUE_DO(-10, 95)
43 ASSERT(tc.status == TORQUE_UNDER_LIMIT, "status is expected", "status is not expected");
44 })
45
46 TEST(update_sensor_error, {
47 TORQUE_DO(10, 80)
48 ASSERT(tc.status == TORQUE_SENSOR_ERROR, "status is expected", "status is not expected");
49 })
50}
#define TORQUE_DO(torque, desired)
@ TORQUE_OK
Definition: TorqueControl.h:10
@ TORQUE_UNDER_LIMIT
Definition: TorqueControl.h:12
@ TORQUE_SENSOR_ERROR
Definition: TorqueControl.h:13
@ TORQUE_OVER_LIMIT
Definition: TorqueControl.h:11
void initTorqueControl(TorqueControl *tc, int hz, float maxTorque)
Initializes the Torque Control Actuator with initial settings.
Definition: TorqueControl.c:4
TorqueStatus status
Definition: TorqueControl.h:21
Here is the call graph for this function:

◆ wheel_speed_main()

void wheel_speed_main ( )

Definition at line 17 of file WheelSpeedTest.c.

17 {
18 TEST(low_speed_1, {
19 ASSERT_IN_ERROR(testTransferFunction(0.127f, 48, 100, 0.5f), 7.44f, "speed",
20 "expected speed");
21 })
22
23 TEST(low_speed_2, {
24 ASSERT_IN_ERROR(testTransferFunction(0.15f, 60, 100, 1.0f), 3.51f, "speed",
25 "expected speed");
26 })
27
28 TEST(low_speed_3, {
29 ASSERT_IN_ERROR(testTransferFunction(0.1f, 40, 25, 0.25f), 3.51f, "speed",
30 "expected speed");
31 })
32
33 TEST(medium_speed_1, {
34 ASSERT_IN_ERROR(testTransferFunction(0.127f, 48, 300, 0.5f), 22.31f,
35 "speed", "expected speed");
36 })
37
38 TEST(medium_speed_2, {
39 ASSERT_IN_ERROR(testTransferFunction(0.15f, 60, 300, 1.0f), 10.54f, "speed",
40 "expected speed");
41 })
42
43 TEST(medium_speed_3, {
44 ASSERT_IN_ERROR(testTransferFunction(0.1f, 40, 150, 0.25f), 21.08f, "speed",
45 "expected speed");
46 })
47
48 TEST(high_speed_1, {
49 ASSERT_IN_ERROR(testTransferFunction(0.127f, 48, 1000, 0.5f), 74.37f,
50 "speed", "expected speed");
51 })
52
53 TEST(high_speed_2, {
54 ASSERT_IN_ERROR(testTransferFunction(0.15f, 60, 1000, 1.0f), 35.14f,
55 "speed", "expected speed");
56 })
57
58 TEST(high_speed_3, {
59 ASSERT_IN_ERROR(testTransferFunction(0.1f, 40, 500, 0.25f), 70.28f, "speed",
60 "expected speed");
61 })
62}
float testTransferFunction(float radius, int numTeeth, int pulseCount, float timeInterval)
Definition: WheelSpeedTest.c:4
#define ASSERT_IN_ERROR(GOT, WANT, GOT_LABEL, WANT_LABEL)
Definition: test.h:35
Here is the call graph for this function:

Variable Documentation

◆ name_to_main

map name_to_main[]
static
Initial value:
= {{"apps", apps_main},
{"bms", bms_main},
{"lut", lut_main},
{"torque_control", torque_control_main},
{"wheel_speed", wheel_speed_main}}
void bms_main()
Definition: BMSTest.c:32
void apps_main()
Definition: AppsTest.c:13
void wheel_speed_main()
void torque_control_main()
void lut_main()
Definition: LUT.c:115

Definition at line 24 of file main.c.