Red Bird Racing VCU v2
 
Loading...
Searching...
No Matches
Curves.hpp
Go to the documentation of this file.
1/**
2 * @file Curves.hpp
3 * @author Planeson, Red Bird Racing
4 * @brief Definition of throttle and brake mapping tables
5 * @version 1.5
6 * @date 2026-02-09
7 * @see Interp.hpp, Pedal
8 */
9
10#ifndef CURVES_HPP
11#define CURVES_HPP
12#include "Interp.hpp"
13#include <stdint.h>
14
15// === APPS Limits ===
16
17constexpr uint16_t APPS_5V_MIN = 50; /**< value below which apps_5v is considered shorted to ground */
18constexpr uint16_t APPS_5V_MAX = 950; /**< value above which apps_5v is considered shorted to rail */
19
20constexpr uint16_t APPS_3V3_MIN = 50; /**< value below which apps_3v3 is considered shorted to ground */
21constexpr uint16_t APPS_3V3_MAX = 950; /**< value above which apps_3v3 is considered shorted to rail */
22
23/**
24 * @brief Ratio between 5V APPS and 3.3V APPS, use integer math to avoid float operations.
25 * Expanded to apps_scaled = apps_3v3 * APPS_RATIO
26 * @note max 64 for multiply to prevent overflow
27 */
28#define APPS_RATIO 53 / 34
29
30/**
31 * @brief Throttle mapping table
32 */
34 {0, 0},
35 {15000, 2000},
36 {30000, 10000},
37 {45000, 25000},
38 {60000, 32500}}; // make sure this point doesn't exceed +-32767
39
40// === Brake Limits ===
41
42constexpr uint16_t brake_min = 50; /**< value below which brake is considered shorted to ground */
43constexpr uint16_t brake_max = 950; /**< value above which brake is considered shorted to rail */
44
45/**
46 * @brief Brake mapping table, negative values for regen
47 */
49 {120, 0},
50 {150, -15000},
51 {180, -26000},
52 {210, -31000},
53 {240, -32500}}; // make sure this point doesn't exceed +-32767
54
55/**
56 * @brief APPS_3V3 mapping table, maps 3V3 readings to 5V readings
57 */
59 {189, 325},
60 {327, 506},
61 {530, 775}};
62
63/**
64 * @brief APPS_5V to percent mapping table, maps 5V readings to percent throttle (0-60000)
65 */
67 {370, 0},
68 {740, 60000}};
69
70// === calculated tables
71/**
72 * @brief APPS percent mapping table, maps APPS percentage to 5V readings
73 * @see THROTTLE_TABLE, APPS_5V_TABLE_INVERTED_MAP
74 */
78
79/**
80 * @brief LinearInterp for APPS_5V_TABLE_INVERTED, used to get APPS reading from a desired percentage
81 * @see THROTTLE_TABLE, APPS_5V_TABLE_INVERTED
82 */
84
85/**
86 * @brief Throttle mapping table (calculated), maps APPS_5V readings to torque values
87 * @see CURVE_TABLE, APPS_5V_PERCENT_TABLE
88 */
94 {APPS_5V_TABLE_INVERTED_MAP.interp(CURVE_TABLE[4].in), CURVE_TABLE[4].out}};
95
96#endif // CURVES_HPP
constexpr uint16_t APPS_3V3_MIN
Definition: Curves.hpp:20
constexpr TablePoint< uint16_t, int16_t > CURVE_TABLE[5]
Throttle mapping table.
Definition: Curves.hpp:33
constexpr LinearInterp< uint16_t, uint16_t, uint32_t, 2 > APPS_5V_TABLE_INVERTED_MAP
LinearInterp for APPS_5V_TABLE_INVERTED, used to get APPS reading from a desired percentage.
Definition: Curves.hpp:83
constexpr uint16_t brake_min
Definition: Curves.hpp:42
constexpr TablePoint< uint16_t, int16_t > THROTTLE_TABLE[5]
Throttle mapping table (calculated), maps APPS_5V readings to torque values.
Definition: Curves.hpp:89
constexpr TablePoint< uint16_t, int16_t > BRAKE_TABLE[5]
Brake mapping table, negative values for regen.
Definition: Curves.hpp:48
constexpr TablePoint< uint16_t, uint16_t > APPS_5V_PERCENT_TABLE[2]
APPS_5V to percent mapping table, maps 5V readings to percent throttle (0-60000)
Definition: Curves.hpp:66
constexpr uint16_t APPS_3V3_MAX
Definition: Curves.hpp:21
constexpr uint16_t brake_max
Definition: Curves.hpp:43
constexpr uint16_t APPS_5V_MIN
Definition: Curves.hpp:17
constexpr TablePoint< uint16_t, uint16_t > APPS_5V_TABLE_INVERTED[2]
APPS percent mapping table, maps APPS percentage to 5V readings.
Definition: Curves.hpp:75
constexpr TablePoint< uint16_t, uint16_t > APPS_3V3_SCALE_TABLE[3]
APPS_3V3 mapping table, maps 3V3 readings to 5V readings.
Definition: Curves.hpp:58
constexpr uint16_t APPS_5V_MAX
Definition: Curves.hpp:18
Declaration and definition of the LinearInterp class template for linear interpolation.
Class template for performing linear interpolation using a lookup table.
Definition: Interp.hpp:35
Structure representing a point in the interpolation table.
Definition: Interp.hpp:21