Repository navigation
Expand file tree
/
Copy pathconfig.cpp
More file actions
124 lines (100 loc) · 4.09 KB
/
Copy pathconfig.cpp
File metadata and controls
124 lines (100 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "tailwind_controller.h"
// =============================================================================
// TELEMETRY CONFIGURATION
// =============================================================================
// WiFi Web Interface - set to true to enable
bool enable_wifi_telemetry = true;
// VESC Bridge Mode - set to true to enable direct VESC access via ESP32
bool vesc_bridge_mode = false; // Set to true to enable VESC Bridge Mode
// NOTE: When vesc_bridge_mode is enabled, the ESP32 acts as a transparent
// bridge between your computer and the VESC controller. This allows you to
// use VESC Tool directly through the ESP32's USB connection.
// WARNING: When bridge mode is active, the normal tailwind controller is disabled!
// =============================================================================
// GLOBAL VARIABLE DEFINITIONS AND CONFIGURATION
// =============================================================================
// Speed interpolation points [km/h]
float SPEED_POINTS_KMH[NUM_SPEED_POINTS] = {0, 5, 10, 15, 20, 30, 40};
// Profile order matches AssistMode and the web API mode IDs.
AssistProfile AVAILABLE_PROFILES[] = {
{"Standard",
"Proportional assistance with a configurable speed curve",
false,
{6, 4, 3, 3.5, 4.5, 6.5, 8.5}},
{"Turbo",
"Full available assist after pedal detection",
true,
{}}, // Turbo uses the power ceiling.
{"Aus",
"Motor assistance off",
false,
{}},
};
// Calculate number of active profiles at compile time
const int NUM_ACTIVE_PROFILES = sizeof(AVAILABLE_PROFILES) / sizeof(AVAILABLE_PROFILES[0]);
// PAS sensor state variables
int pos = 0;
int reverse_steps = 0;
int a = 0, b = 0;
int pedal_direction = 0; // 1=forward, -1=backward, 0=standstill
unsigned long last_pulse_time = 0;
unsigned long pulse_intervals[4] = {0, 0, 0, 0};
int pulse_index = 0;
// Interrupt-based PAS sensor variables
volatile bool pas_interrupt_flag = false;
volatile unsigned long last_interrupt_time = 0;
volatile int quadrature_pulses_per_rev = 32; // 8 original pulses × 4 quadrature transitions
volatile unsigned long last_revolution_time = 0;
// Sensor measurements
float current_cadence_rpm = 0.0;
float current_cadence_rps = 0.0;
int raw_torque_value = 0;
float crank_torque_nm = 0.0;
float filtered_torque = 0.0;
// Torque sensor calibration
int torque_standstill_calibrated = TORQUE_STANDSTILL_DEFAULT; // Start with default value
// Speed and assist
float current_speed_kmh = 0.0;
float current_motor_rpm = 0.0;
float dynamic_assist_factor = 1.0;
bool vesc_data_valid = false;
// Power calculation
float human_power_watts = 0.0;
float assist_power_watts = 0.0;
float target_current_amps = 0.0;
float actual_current_amps = 0.0;
// System status
int current_mode = MODE_STANDARD;
bool motor_enabled = false;
bool lightOn = false;
unsigned long last_pedal_activity = 0;
// Battery monitoring
float battery_voltage = 0.0;
float battery_percentage = 100.0;
bool battery_low = false;
bool battery_critical = false;
bool battery_led_state = false;
unsigned long last_battery_led_toggle = 0;
// Debug/Compatibility
int loopCounter = 0;
int vescCounter = 0;
int vescDelayBetween = 9999;
int vescDelayBetweenList = 9999;
// =============================================================================
// DEBUG MODE VARIABLES
// =============================================================================
bool debug_mode = false; // Keep startup torque calibration enabled
bool debug_simulate_pas = false; // Simulate PAS sensor when in debug mode
bool debug_simulate_torque = false; // Simulate torque sensor when in debug mode
// Debug simulation mode selection
debug_mode_type_t debug_simulation_mode = DEBUG_MODE_SYSTEMATIC_TEST; // Change this to switch modes
// Debug simulation variables
float debug_cadence_rpm = 0.0;
float debug_torque_nm = 0.0;
unsigned long debug_last_update = 0;
int debug_cycle_state = 0; // 0=ramp up, 1=hold high, 2=ramp down, 3=hold low
// Systematic test variables
int debug_test_cadence_index = 0;
int debug_test_torque_index = 0;
unsigned long debug_test_start_time = 0;
bool debug_test_completed = false;