Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
TorqueMonitor.h File Reference
#include "MonitorSystem.h"
Include dependency graph for TorqueMonitor.h:

Go to the source code of this file.

Classes

struct  TorqueControl
 

Macros

#define TORQUE_ERROR_MARGIN   0.05
 

Enumerations

enum  TorqueStatus {
  TORQUE_OK , TORQUE_OVER_LIMIT , TORQUE_UNDER_LIMIT , TORQUE_SENSOR_ERROR ,
  TORQUE_OK , TORQUE_OVER_LIMIT , TORQUE_UNDER_LIMIT , TORQUE_SENSOR_ERROR
}
 

Functions

void initTorqueControl (TorqueControl *tc, int hz, float maxTorque)
 Initializes the Torque Control Actuator with initial settings. More...
 
void setDesiredTorque (TorqueControl *tc, float torque)
 Sets the desired torque for the Torque Control Actuator. More...
 
void setTorque (TorqueControl *tc, float torque)
 
void updateTorqueControl (void *tc)
 Updates the Torque Control Actuator based on sensor inputs and calculations. More...
 
TorqueStatus checkTorqueLimits (TorqueControl *tc)
 Checks if the actual torque is within the defined limits and desired range. More...
 
void sendTorqueCommand (const TorqueControl *tc)
 

Macro Definition Documentation

◆ TORQUE_ERROR_MARGIN

#define TORQUE_ERROR_MARGIN   0.05

Definition at line 6 of file TorqueMonitor.h.

Enumeration Type Documentation

◆ TorqueStatus

Enumerator
TORQUE_OK 
TORQUE_OVER_LIMIT 
TORQUE_UNDER_LIMIT 
TORQUE_SENSOR_ERROR 
TORQUE_OK 
TORQUE_OVER_LIMIT 
TORQUE_UNDER_LIMIT 
TORQUE_SENSOR_ERROR 

Definition at line 9 of file TorqueMonitor.h.

9 {
TorqueStatus
Definition: TorqueMonitor.h:9
@ TORQUE_OK
Definition: TorqueMonitor.h:10
@ TORQUE_UNDER_LIMIT
Definition: TorqueMonitor.h:12
@ TORQUE_SENSOR_ERROR
Definition: TorqueMonitor.h:13
@ TORQUE_OVER_LIMIT
Definition: TorqueMonitor.h:11

Function Documentation

◆ checkTorqueLimits()

TorqueStatus checkTorqueLimits ( TorqueControl tc)

Checks if the actual torque is within the defined limits and desired range.

TODO: move into torque police

Note
FIXME: When should each torque condition be in place?
Parameters
tcA pointer to the TorqueControl structure.
Returns
The actual status of the torque.

Definition at line 58 of file TorqueControl.c.

58 {
59 if (tc->actualTorque > tc->maxAllowedTorque) {
60 return TORQUE_OVER_LIMIT;
61 }
62 else if (tc->actualTorque < 0) {
63 return TORQUE_UNDER_LIMIT;
64 }
65
66 float lowerBound = tc->desiredTorque * (1 - TORQUE_ERROR_MARGIN);
67 float upperBound = tc->desiredTorque * (1 + TORQUE_ERROR_MARGIN);
68
69 if (tc->actualTorque < lowerBound || tc->actualTorque > upperBound) {
71 }
72
73 return TORQUE_OK;
74}
@ TORQUE_OK
Definition: TorqueControl.h:10
@ TORQUE_UNDER_LIMIT
Definition: TorqueControl.h:12
@ TORQUE_SENSOR_ERROR
Definition: TorqueControl.h:13
@ TORQUE_OVER_LIMIT
Definition: TorqueControl.h:11
#define TORQUE_ERROR_MARGIN
Definition: TorqueControl.h:6
float maxAllowedTorque
Definition: TorqueControl.h:20
float actualTorque
Definition: TorqueControl.h:18
float desiredTorque
Definition: TorqueControl.h:19
Here is the caller graph for this function:

◆ initTorqueControl()

void initTorqueControl ( TorqueControl tc,
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 4 of file TorqueControl.c.

4 {
5 initControllerSystem(&tc->base, "Torque Control", hz, c_TORQUE);
7 tc->actualTorque = 0;
8 tc->desiredTorque = 0;
9 tc->maxAllowedTorque = maxTorque;
10 tc->status = TORQUE_OK;
12}
@ c_TORQUE
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type)
Initializes the Controller System with initial settings.
void updateTorqueControl(void *tc)
Updates the Torque Control Actuator based on sensor inputs and calculations.
Definition: TorqueControl.c:43
int torqueSafetyCheck(void *tc)
Checks the safety of the torque with multiple monitors.
Definition: TorqueControl.c:76
int(* safety)(void *self)
Updateable updateable
Definition: System.h:18
ControllerSystem base
Definition: TorqueControl.h:17
TorqueStatus status
Definition: TorqueControl.h:21
void(* update)(void *self)
Definition: Updateable.h:26

◆ sendTorqueCommand()

void sendTorqueCommand ( const TorqueControl tc)

◆ setDesiredTorque()

void setDesiredTorque ( TorqueControl tc,
float  torque 
)

Sets the desired torque for the Torque Control Actuator.

Note
FIXME: Update to this to a map in the future.
Parameters
tcA pointer to the TorqueControl structure.
torqueThe desired torque to be set (in Nm).

Definition at line 27 of file TorqueControl.c.

27 {
28 if (tc->base.safety(tc) == FAILURE) {
29 printf("Torque Control Actuator is not in a safe state\n");
30 return;
31 }
32 if (torque > tc->maxAllowedTorque) {
33 printf("Desired torque exceeds the maximum allowed torque\n");
34 return;
35 }
36 tc->desiredTorque = torque;
37}
#define FAILURE
Definition: Common.h:6

◆ setTorque()

void setTorque ( TorqueControl tc,
float  torque 
)

◆ updateTorqueControl()

void updateTorqueControl ( void *  tc)

Updates the Torque Control Actuator based on sensor inputs and calculations.

Parameters
tcA pointer to the TorqueControl structure.

Definition at line 43 of file TorqueControl.c.

43 {
44 TorqueControl* tcPtr = (TorqueControl*)tc;
45 if (tcPtr->base.safety(tc) == FAILURE) {
46 printf("Torque Control Actuator is not in a safe state\n");
47 return;
48 }
49 tcPtr->status = checkTorqueLimits(tc);
50 if (tcPtr->status != TORQUE_OK) {
51 printf("Torque Control Actuator is not in OK\n");
52 return;
53 }
54 // TODO: Implement some way to send the torque where it needs to go
55 // sendTorqueCommand(tc);
56}
TorqueStatus checkTorqueLimits(TorqueControl *tc)
Checks if the actual torque is within the defined limits and desired range.
Definition: TorqueControl.c:58
Here is the caller graph for this function: