RP2040-Decoder
Loading...
Searching...
No Matches
core1.h
Go to the documentation of this file.
1
8#pragma once
9#include "shared.h"
10
11typedef struct pid_params{
12 // Controller variables - won't change after init
13 float k_i; // Integral gain
14 float k_d; // Derivative gain
15 float t; // Sampling time
16 float tau; // Low-pass-filter time constant
17 float k_ff; // Feed-Forward gain
18 float ci_0; // (k_i*t)/2
19 float cd_0; // (k_d*2)/(2*tau+t)
20 float cd_1; // (2*tau-t)/(2*tau+t)
21 float int_lim_max; // max limit for integrator
22 float int_lim_min; // min limit for integrator
23 float max_output; // max possible pwm output value
24 float k_p_x_1_shift;
25 float k_p_x_1;
26 float k_p_x_2;
27 float k_p_y_0;
28 float k_p_y_1;
29 float k_p_y_2;
30 float k_p_m_1;
31 float k_p_m_2;
32 // Controller variables - might change on runtime
33 float k_p; // Proportional gain
34 float e_prev; // Previous Error
35 float i_prev; // Previous Integral Value
36 float d_prev; // Previous Derivative Value
37 float measurement_prev; // Previous Measurement
38 float x_1_fwd; // Base Speed; forward direction
39 float x_2_fwd; // High Speed; forward direction
40 float y_1_fwd; // Base PWM; forward direction
41 float y_2_fwd; // High PWM; forward direction
42 float x_1_rev; // Base Speed; reverse direction
43 float x_2_rev; // High Speed; reverse direction
44 float y_1_rev; // Base PWM; reverse direction
45 float y_2_rev; // High PWM; reverse direction
46 float m_fwd; // Slope forward direction
47 float m_rev; // Slope reverse direction
48 uint16_t speed_table[127]; // Array with setpoint values corresponding to every speed step
49 uint32_t speed_step_target; // End target speed step
50 uint32_t setpoint; // Current setpoint
51 uint32_t setpoint_prev; // Previous setpoint
52 // Measurement Variables
53 float measurement; // Newest Measurement value
54 float adc_offset; // ADC offset value
55 uint8_t msr_delay_in_us; // Delay before VEMF Measurement
56 uint8_t msr_total_iterations; // Amount of samples
57 uint8_t l_side_arr_cutoff; // Discarded samples (left side)
58 uint8_t r_side_arr_cutoff; // Discarded samples (right side)
60
61uint8_t get_speed_step_table_index_of_speed_step(uint8_t speed_step);
62bool speed_helper(struct repeating_timer *t);
63void adjust_pwm_level(uint16_t level);
64void update_m(pid_params *pid);
65void update_y(pid_params *pid,float i);
66float get_ff_val(const pid_params *pid);
67float get_kp(const pid_params *pid);
68bool pid_control(struct repeating_timer *t);
69void init_pid( pid_params * pid);
Definition core1.h:11