Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
LUT.h
Go to the documentation of this file.
1#ifndef RENNSSELAERMOTORSPORT_LUT_H
2#define RENNSSELAERMOTORSPORT_LUT_H
3#include <stdbool.h>
4#include <stdint.h>
5
6/* Defines a mapping from one input to one output. */
7typedef struct {
8 /* Input value. */
9 float input;
10 /* Output value. */
11 float output;
12} point;
13
23int point_compare(const void *a, const void *b);
24
34bool point_is_between(const point *min, const point *max, float in);
35
36#define TABLE_CAPACITY 64
37
38/* Defines a interpolated table of multiple reference points, forming a
39 * continuous mapping from inputs to outputs. */
40typedef struct {
41 /* Number of reference points. */
42 uint16_t count_;
43 /* Number of added reference points. */
44 uint16_t added_;
45 /* True if the table is initialized; cache for table_is_initialized. */
47 /* Reference points. */
49} table;
50
58bool table_init(table *table, uint16_t count);
59
68bool table_add_reference_point(table *table, float in, float out);
69
78
87
96
104bool table_can_sample(table *table, float in);
105
114bool table_sample(table *table, float in, float *out);
115#endif // RENNSSELAERMOTORSPORT_LUT_H
int point_compare(const void *a, const void *b)
Compares two points by input.
Definition: LUT.c:6
bool table_is_initialized(table *table)
Checks if the table has been fully initialized, with all reference points added.
Definition: LUT.c:53
#define TABLE_CAPACITY
Definition: LUT.h:36
bool table_sample(table *table, float in, float *out)
Samples a output value from the table for an input value.
Definition: LUT.c:137
bool table_init(table *table, uint16_t count)
Initializes the table.
Definition: LUT.c:31
const point * table_min_point(table *table)
Retrieves the point in the table with the least input value.
Definition: LUT.c:95
bool table_can_sample(table *table, float in)
Checks if the input input is valid for the table.
Definition: LUT.c:107
bool point_is_between(const point *min, const point *max, float in)
Determines if the input value is between the input of two points.
Definition: LUT.c:16
const point * table_max_point(table *table)
Retrieves the point in the table with the greatest input value.
Definition: LUT.c:101
bool table_add_reference_point(table *table, float in, float out)
Adds a reference point to the table.
Definition: LUT.c:79
Definition: LUT.h:7
float input
Definition: LUT.h:9
float output
Definition: LUT.h:11
Definition: LUT.h:40
uint16_t count_
Definition: LUT.h:42
bool initialized_
Definition: LUT.h:46
uint16_t added_
Definition: LUT.h:44