Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
Apps.h File Reference

: Contains the logic for the two app sensors. More...

#include "../ControllerSystem.h"
#include "../../Sensors/AnalogSensors/App.h"
Include dependency graph for Apps.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Apps
 

Macros

#define APPS_DIFFERENCE   0.1
 

Enumerations

enum  AppsStatus { APPS_OK , APPS_FAULT }
 

Functions

void initApps (Apps *apps, int hz, int channel1, int channel2)
 Initializes the APPs with the given frequency and channel. More...
 
void updateApps (void *apps)
 Updates the APPS based on both sensor outputs. More...
 
float getAppsPosition (Apps *apps)
 Averages app sensors to get pedal position. More...
 
int appsSafetyCheck (void *apps)
 Checks the safety of Apps. More...
 

Detailed Description

: Contains the logic for the two app sensors.

Definition in file Apps.h.

Macro Definition Documentation

◆ APPS_DIFFERENCE

#define APPS_DIFFERENCE   0.1

Definition at line 14 of file Apps.h.

Enumeration Type Documentation

◆ AppsStatus

enum AppsStatus
Enumerator
APPS_OK 
APPS_FAULT 

Definition at line 16 of file Apps.h.

16 {
17 APPS_OK,
AppsStatus
Definition: Apps.h:16
@ APPS_OK
Definition: Apps.h:17
@ APPS_FAULT
Definition: Apps.h:18

Function Documentation

◆ appsSafetyCheck()

int appsSafetyCheck ( void *  apps)

Checks the safety of Apps.

Parameters
appsA pointer to the APPs controller.

Definition at line 74 of file Apps.c.

74 {
75 Apps* appsPtr = (Apps*)apps;
76 if(appsPtr->base.num_monitors == 0) {
77 printf("No monitors set for Apps\n");
78 return FAILURE;
79 }
80 else if (appsPtr->status != APPS_OK) {
81 printf("Apps is not in a safe state\n");
82 return FAILURE;
83 }
84 return SUCCESS;
85}
#define FAILURE
Definition: Common.h:6
#define SUCCESS
Definition: Common.h:5
Definition: Apps.h:21
AppsStatus status
Definition: Apps.h:23
ControllerSystem base
Definition: Apps.h:22
Here is the caller graph for this function:

◆ getAppsPosition()

float getAppsPosition ( Apps apps)

Averages app sensors to get pedal position.

Parameters
appsPointer to the APPS controller.

Definition at line 66 of file Apps.c.

66 {
67 checkAppsLimit(apps);
68 if (apps->status != APPS_OK) return 0.0f;
69 float pos1 = getAppPosition(apps->app[0]);
70 float pos2 = getAppPosition(apps->app[1]);
71 return fabs(pos1 + pos2) / 2;
72}
float getAppPosition(App *app)
Gets the current position of the APP.
Definition: App.c:11
void checkAppsLimit(Apps *apps)
Checks App limits for faults.
Definition: Apps.c:14
App * app[2]
Definition: Apps.h:24
Here is the call graph for this function:

◆ initApps()

void initApps ( Apps apps,
int  hz,
int  channel1,
int  channel2 
)

Initializes the APPs with the given frequency and channel.

Parameters
appsPointer to the Apps structure to initialize.
hzThe frequency in Hertz at which the APP operates.
channel1The analog channel the first APP is connected to.
channel2The analog channel the second APP is connected to.

Definition at line 30 of file Apps.c.

30 {
31 // Allocate memory for the app instances
32 apps->app[0] = (App*)malloc(sizeof(App));
33 apps->app[1] = (App*)malloc(sizeof(App));
34
35 // Check if memory allocation was successful
36 if (apps->app[0] == NULL || apps->app[1] == NULL) {
37 return;
38 }
39
40 // System setup
41 MonitorSystem monitor;
42 initMonitorSystem(&monitor, "APPs Monitor", 200, m_APPS, VEHICLE_SHUTDOWN);
43 initControllerSystem(&apps->base, "APPS", hz, c_APPS);
44 defaultAddMonitor(&apps->base, &monitor);
45
46 // Controller setup
49 apps->status = APPS_OK;
50 initApp(apps->app[0], hz, channel1);
51 initApp(apps->app[1], hz, channel2);
52}
void initApp(App *app, int hz, int channel)
Initializes the APP with the given frequency and channel.
Definition: App.c:5
int appsSafetyCheck(void *apps)
Checks the safety of Apps.
Definition: Apps.c:74
void updateApps(void *apps)
Updates the APPS based on both sensor outputs.
Definition: Apps.c:54
int defaultAddMonitor(void *self, MonitorSystem *monitor)
Adds a monitor to the controller.
@ c_APPS
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type)
Initializes the Controller System with initial settings.
void initMonitorSystem(MonitorSystem *monitor, const char *name, int hz, MonitorType type, FaultType fault)
Initializes the Monitor System with initial settings.
Definition: MonitorSystem.c:3
@ m_APPS
Definition: MonitorSystem.h:12
@ VEHICLE_SHUTDOWN
Definition: MonitorSystem.h:21
Definition: App.h:6
int(* safety)(void *self)
Updateable updateable
Definition: System.h:18
void(* update)(void *self)
Definition: Updateable.h:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateApps()

void updateApps ( void *  apps)

Updates the APPS based on both sensor outputs.

Parameters
appsA pointer to the APPs structure.

Definition at line 54 of file Apps.c.

54 {
55 Apps* appsPtr = (Apps*) apps;
56 updateApp(&appsPtr->app[0]);
57 updateApp(&appsPtr->app[1]);
58 if (appsPtr->base.safety(apps) == FAILURE) {
59 printf("APPs is not in a safe state\n");
60 return;
61 }
62 checkAppsLimit(appsPtr);
63 if (appsPtr->status != APPS_OK) return;
64}
void updateApp(void *app)
Updates the APP data.
Definition: App.c:15
Here is the call graph for this function:
Here is the caller graph for this function: