Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions
WheelSpeedTest.c File Reference
#include "../Inc/Sensors/DigitalSensors/WheelSpeed.h"
#include "test.h"
Include dependency graph for WheelSpeedTest.c:

Go to the source code of this file.

Functions

float testTransferFunction (float radius, int numTeeth, int pulseCount, float timeInterval)
 
void wheel_speed_main ()
 

Function Documentation

◆ testTransferFunction()

float testTransferFunction ( float  radius,
int  numTeeth,
int  pulseCount,
float  timeInterval 
)

Definition at line 4 of file WheelSpeedTest.c.

5 {
6 WheelSpeed wheelSpeed;
7 int wheelSpeedHz = 200;
8 initWheelSpeed(&wheelSpeed, wheelSpeedHz, 0, radius, numTeeth, 0);
9
10 addPulse(&wheelSpeed, pulseCount);
11 // Inverting time because get function relies on current time
12 setTimeInterval(&wheelSpeed, -timeInterval);
13
14 return calculateSpeed(&wheelSpeed);
15}
void addPulse(WheelSpeed *wf, int num)
Add pulses to sensor;.
Definition: WheelSpeed.c:66
void setTimeInterval(WheelSpeed *ws, float interval)
Set time interval.
Definition: WheelSpeed.c:62
float calculateSpeed(WheelSpeed *ws)
Translates data to speed in mph.
Definition: WheelSpeed.c:24
void initWheelSpeed(WheelSpeed *ws, int hz, int port, float radius, int numTeeth, WHEEL_LOCATION location)
Initialization function for a wheel speed sensor.
Definition: WheelSpeed.c:12
Here is the call graph for this function:
Here is the caller 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 TEST(NAME, BODY)
Definition: test.h:19
#define ASSERT_IN_ERROR(GOT, WANT, GOT_LABEL, WANT_LABEL)
Definition: test.h:35
Here is the call graph for this function: