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 , APPS_LOW }
 

Functions

void initApps (Apps *apps, int hz, int channel1, int channel2)
 Initializes the APPs with the given frequency and channel. More...
 
int updateApps (ControllerSystem *controller)
 Updates the APPS based on both sensor outputs. More...
 
float getAppsPosition (Apps *apps)
 Averages app sensors to get pedal position. 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 
APPS_LOW 

Definition at line 16 of file Apps.h.

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

Function Documentation

◆ getAppsPosition()

float getAppsPosition ( Apps apps)

Averages app sensors to get pedal position.

Parameters
appsPointer to the APPS controller.

Definition at line 42 of file Apps.c.

42 {
43 if (apps->base.state != c_validated) {
44
45 printf("Apps Controller value has not been validated\r\n");
46 return 0.0f;
47 }
48 checkAppsLimit(apps);
49 if (apps->status != APPS_OK) return 0.0f;
50 float pos1 = getAppPosition(apps->app[0]);
51 float pos2 = getAppPosition(apps->app[1]);
52 return fabs(pos1 + pos2) / 2;
53}
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: AppsMonitor.c:37
@ c_validated
App * app[2]
Definition: Apps.h:25
AppsStatus status
Definition: Apps.h:24
ControllerSystem base
Definition: Apps.h:23
ControllerState state
Here is the call graph for this function:
Here is the caller 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 7 of file Apps.c.

7 {
8 initControllerSystem(&apps->base, "Apps", hz, c_APPS, updateApps, apps);
9 // Allocate memory for the app instances
10 static App app1, app2;
11 apps->app[0] = &app1;
12 apps->app[1] = &app2;
13
14 // Check if memory allocation was successful
15 if (apps->app[0] == NULL || apps->app[1] == NULL) {
16 return;
17 }
18
19 // Controller setup
20 apps->status = APPS_OK;
21 initApp(apps->app[0], hz, channel1);
22 initApp(apps->app[1], hz, channel2);
23 ENABLE(apps->base.system);
24}
void initApp(App *app, int hz, int channel)
Initializes the APP with the given frequency and channel.
Definition: App.c:5
int updateApps(ControllerSystem *controller)
Updates the APPS based on both sensor outputs.
Definition: Apps.c:26
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type, int(*updateController)(ControllerSystem *controller), void *child)
Initializes the Controller System with initial settings.
@ c_APPS
#define ENABLE(item_)
Definition: Updateable.h:10
Definition: App.h:6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateApps()

int updateApps ( ControllerSystem controller)

Updates the APPS based on both sensor outputs.

Parameters
controllerA pointer to the APPs ControllerSystem.

Definition at line 26 of file Apps.c.

26 {
27 Apps* appsPtr = (Apps*)controller->child;
28 updateApp(appsPtr->app[0]);
29 updateApp(appsPtr->app[1]);
30
31 // Set to computed
32 appsPtr->base.state = c_computed;
33
34
35 #ifdef DEBUGn
36 printf("Apps updated. #1: %f, #2: %f\r\n", getAppPosition(appsPtr->app[0]), getAppPosition(appsPtr->app[1]));
37 #endif
38
39 return _SUCCESS;
40}
void updateApp(App *app)
Updates the APP data.
Definition: App.c:15
#define _SUCCESS
Definition: Common.h:5
@ c_computed
Definition: Apps.h:22
Here is the call graph for this function:
Here is the caller graph for this function: