Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
TorqueControl.h File Reference
#include "../ControllerSystem.h"
#include "../../Utils/Constants.h"
#include "Apps.h"
Include dependency graph for TorqueControl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TorqueControl
 

Enumerations

enum  TorqueStatus {
  TORQUE_OK , TORQUE_RTD , TORQUE_LOW , TORQUE_OVER_LIMIT ,
  TORQUE_UNDER_LIMIT , TORQUE_SENSOR_ERROR , TORQUE_BRAKE_FIGHT
}
 

Functions

void initTorqueControl (TorqueControl *tc, Apps *apps, int hz, float maxTorque)
 Initializes the Torque Control Actuator with initial settings. More...
 
int startTorqueControl (TorqueControl *tc)
 Starts the Torque Control Actuator. More...
 
int setDesiredTorque (ControllerSystem *controller)
 Sets the desired torque for the Torque Control Actuator. More...
 

Enumeration Type Documentation

◆ TorqueStatus

Enumerator
TORQUE_OK 
TORQUE_RTD 
TORQUE_LOW 
TORQUE_OVER_LIMIT 
TORQUE_UNDER_LIMIT 
TORQUE_SENSOR_ERROR 
TORQUE_BRAKE_FIGHT 

Definition at line 8 of file TorqueControl.h.

8 {
TorqueStatus
Definition: TorqueControl.h:8
@ TORQUE_OK
Definition: TorqueControl.h:9
@ TORQUE_LOW
Definition: TorqueControl.h:11
@ TORQUE_UNDER_LIMIT
Definition: TorqueControl.h:13
@ TORQUE_SENSOR_ERROR
Definition: TorqueControl.h:14
@ TORQUE_OVER_LIMIT
Definition: TorqueControl.h:12
@ TORQUE_BRAKE_FIGHT
Definition: TorqueControl.h:15
@ TORQUE_RTD
Definition: TorqueControl.h:10

Function Documentation

◆ initTorqueControl()

void initTorqueControl ( TorqueControl tc,
Apps apps,
int  hz,
float  maxTorque 
)

Initializes the Torque Control Actuator with initial settings.

Parameters
tcA pointer to the TorqueControl structure.
hzRate at which the sensor is called (in hz).
maxTorqueThe maximum torque limit set for the system (in Nm).

Definition at line 6 of file TorqueControl.c.

6 {
7 initControllerSystem(&tc->base, "Torque Control", hz, c_TORQUE, setDesiredTorque, tc);
8 tc->desiredTorque = 0;
9 tc->maxAllowedTorque = maxTorque;
10 tc->apps = apps;
11}
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_TORQUE
int setDesiredTorque(ControllerSystem *controller)
Sets the desired torque for the Torque Control Actuator.
Definition: TorqueControl.c:27
ControllerSystem base
Definition: TorqueControl.h:19
float maxAllowedTorque
Definition: TorqueControl.h:22
float desiredTorque
Definition: TorqueControl.h:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDesiredTorque()

int setDesiredTorque ( ControllerSystem controller)

Sets the desired torque for the Torque Control Actuator.

Parameters
controllerA pointer to the ControllerSystem structure.
Returns
_SUCCESS if the desired torque was set, _FAILURE otherwise.

Definition at line 27 of file TorqueControl.c.

27 {
28 TorqueControl* tc = (TorqueControl*)controller->child;
29 float pedalposition = getAppsPosition(tc->apps);
30 float torque = pedalposition * tc->maxAllowedTorque;
31
32 if (torque > tc->maxAllowedTorque) {
33 printf("Desired torque exceeds the maximum allowed torque, stepping down to max\n");
34 torque = tc->maxAllowedTorque;
35 }
36
37 // Perform any desired mapping, i.e. fit to sigmoid function.
38 double normalized = torque / tc->maxAllowedTorque; // Normalize to range [0, 1]
39 double s_curve = 1.0 / (1.0 + exp(-10 * (normalized - 0.5)));
40 tc->desiredTorque = s_curve * tc->maxAllowedTorque;
41 tc->base.state = c_computed;
42
43 #ifdef DEBUGn
44 printf("Desired Torque: %f\r\n", tc->desiredTorque);
45 #endif
46
47 return _SUCCESS;
48}
float getAppsPosition(Apps *apps)
Averages app sensors to get pedal position.
Definition: Apps.c:42
#define _SUCCESS
Definition: Common.h:5
@ c_computed
ControllerState state
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startTorqueControl()

int startTorqueControl ( TorqueControl tc)

Starts the Torque Control Actuator.

Parameters
tcA pointer to the TorqueControl structure.
Returns
_SUCCESS if the actuator was started, _FAILURE otherwise.

Definition at line 13 of file TorqueControl.c.

13 {
14 if (tc->base.safety == NULL) {
15 printf("Safety system not set for Torque Control\n");
16 return _FAILURE;
17 }
18 else if (tc->base.safety(&tc->base) == _FAILURE) {
19 printf("Torque Control Actuator is not in a safe state\n");
20 return _FAILURE;
21 }
22 ENABLE(tc->base.system);
23 tc->base.state = c_idle;
24 return _SUCCESS;
25}
#define _FAILURE
Definition: Common.h:6
@ c_idle
#define ENABLE(item_)
Definition: Updateable.h:10
int(* safety)(struct ControllerSystem *controller)
Here is the caller graph for this function: