Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | * @file dynoview.h | |||
3 | * | |||
4 | * @date Jan 05, 2025 | |||
5 | * @author Alexey Ershov, (c) 2012-2025 | |||
6 | */ | |||
7 | ||||
8 | #pragma once | |||
9 | ||||
10 | void updateDynoView(); | |||
11 | int getDynoviewHP(); | |||
12 | int getDynoviewTorque(); | |||
13 | ||||
14 | struct DynoPoint { | |||
15 | int rpm; | |||
16 | float time; | |||
17 | float tps; | |||
18 | ||||
19 | float engineRps; | |||
20 | float axleRps; | |||
21 | float vMs; | |||
22 | float mph; | |||
23 | float distanceM; | |||
24 | float aMs2; | |||
25 | float forceN; | |||
26 | float forceDragN; | |||
27 | float forceTotalN; | |||
28 | float torqueWheelNm; | |||
29 | float torqueNm; | |||
30 | float torqueLbFt; | |||
31 | float hp; | |||
32 | }; | |||
33 | ||||
34 | class DynoView { | |||
35 | public: | |||
36 | ||||
37 | void init(); | |||
38 | void update(); | |||
39 | bool onRpm(int rpm, float time, float tps); | |||
40 | ||||
41 | float currentTorque; | |||
42 | float currentHP; | |||
43 | ||||
44 | private: | |||
45 | ||||
46 | void reset(); | |||
47 | ||||
48 | 442 | static inline void move(uint8_t size, float* data) { | ||
49 |
2/2✓ Branch 0 taken 3138 times.
✓ Branch 1 taken 442 times.
|
2/2✓ Decision 'true' taken 3138 times.
✓ Decision 'false' taken 442 times.
|
3580 | for(int i = size - 1; i > 0; --i) |
50 | { | |||
51 | 3138 | memcpy(&data[i], &data[i - 1], sizeof(float)); | ||
52 | } | |||
53 | 442 | } | ||
54 | ||||
55 | 442 | static inline float accumulate_window(uint8_t size, const float* data) | ||
56 | { | |||
57 | 442 | float sum = 0.0; | ||
58 | ||||
59 |
2/2✓ Branch 0 taken 3232 times.
✓ Branch 1 taken 442 times.
|
2/2✓ Decision 'true' taken 3232 times.
✓ Decision 'false' taken 442 times.
|
3674 | for(int i = 0; i < size; ++i) { |
60 | 3232 | sum += data[size - i - 1]; | ||
61 | } | |||
62 | ||||
63 | 442 | return sum / (float)size; | ||
64 | } | |||
65 | ||||
66 | float airDensityKgM3 = 1.225; // 15C | |||
67 | uint16_t wheelOverallDiameterMm = 0; | |||
68 | ||||
69 | // SAE corrections | |||
70 | float saeBaroCorrectionFactor; | |||
71 | float saeBaroMmhg; | |||
72 | float saeTempCorrectionFactor; | |||
73 | float saeVaporPressure; | |||
74 | float saeCorrectionFactor; | |||
75 | ||||
76 | DynoPoint dynoViewPoint; | |||
77 | DynoPoint dynoViewPointPrev; | |||
78 | ||||
79 | int count = 0; | |||
80 | int count_rpm = 0; | |||
81 | int prev_rpm = 0; | |||
82 | ||||
83 | static constexpr int dyno_view_window_size = 7; | |||
84 | static constexpr int dyno_view_window_size_rpm = 10; | |||
85 | static constexpr int dyno_view_tps_min_for_run = 30; | |||
86 | static constexpr int dyno_view_rpm_diff_smooth = 30; | |||
87 | static constexpr float dyno_view_log_time_smooth_sec = 0.05f; | |||
88 | static constexpr int dyno_view_tps_diff_to_reset_run = 10; | |||
89 | static constexpr int dyno_view_rpm_fall_to_reset_run = 60; | |||
90 | ||||
91 | float tail_hp[dyno_view_window_size]; | |||
92 | float tail_torque[dyno_view_window_size]; | |||
93 | float tail_rpm[dyno_view_window_size_rpm]; | |||
94 | ||||
95 | bool isInitialized = false; | |||
96 | }; | |||
97 |