Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Apps.c
Go to the documentation of this file.
1#include "../../../Inc/Systems/Controller/Apps.h"
2#include "../../../Inc/Systems/Monitor/AppsMonitor.h"
3#include "../../../Inc/Utils/Common.h"
4#include "../../../Inc/Utils/MessageFormat.h"
5
6#include <math.h>
7
8void initApps(Apps* apps, int hz, int channel1, int channel2) {
9 initControllerSystem(&apps->base, "Apps", hz, c_APPS, updateApps, apps);
10 // Allocate memory for the app instances
11 static App app1, app2;
12 apps->app[0] = &app1;
13 apps->app[1] = &app2;
14
15 // Check if memory allocation was successful
16 if (apps->app[0] == NULL || apps->app[1] == NULL) {
17 return;
18 }
19
20 // Controller setup
21 apps->status = APPS_OK;
22 initApp(apps->app[0], hz, channel1, "App 1");
23 initApp(apps->app[1], hz, channel2, "App 2");
24 ENABLE(apps->base.system);
25}
26
27int updateApps(ControllerSystem* controller) {
28 Apps* appsPtr = (Apps*)controller->child;
29 updateApp(appsPtr->app[0]);
30 updateApp(appsPtr->app[1]);
31
32 // Set to computed
33 appsPtr->base.state = c_computed;
34
35 return _SUCCESS;
36}
37
38float getAppsPosition(Apps* apps) {
39 if (apps->base.state != c_validated) {
40 return 0.0f;
41 }
42 checkAppsLimit(apps);
43 if (apps->status != APPS_OK) return 0.0f;
44 float pos1 = getAppPosition(apps->app[0]);
45 float pos2 = getAppPosition(apps->app[1]);
46 return fabs(pos1 + pos2) / 2;
47}
float getAppPosition(App *app)
Gets the current position of the APP.
Definition: App.c:17
void updateApp(App *app)
Updates the APP data.
Definition: App.c:21
void initApp(App *app, int hz, int channel, char *name)
Initializes the APP with the given frequency and channel.
Definition: App.c:6
void checkAppsLimit(Apps *apps)
Checks App limits for faults.
Definition: AppsMonitor.c:35
void initApps(Apps *apps, int hz, int channel1, int channel2)
Initializes the APPs with the given frequency and channel.
Definition: Apps.c:8
int updateApps(ControllerSystem *controller)
Updates the APPS based on both sensor outputs.
Definition: Apps.c:27
float getAppsPosition(Apps *apps)
Averages app sensors to get pedal position.
Definition: Apps.c:38
@ APPS_OK
Definition: Apps.h:17
#define _SUCCESS
Definition: Common.h:5
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
@ c_computed
@ c_validated
#define ENABLE(item_)
Definition: Updateable.h:10
Definition: App.h:7
Definition: Apps.h:22
App * app[2]
Definition: Apps.h:25
AppsStatus status
Definition: Apps.h:24
ControllerSystem base
Definition: Apps.h:23
ControllerState state