- Reduced amount of global variables. Many variables are now initialized in main() and core1_entry() respectively and then passed as pointer.
- Updates in speed steps are passed via multicore fifo. - Pointer to direction variable is also passed from core1 to core0 via multicore fifo - PID parameter struct definition moved to core1.h - Implemented variable Proportional gain function - Implemented function to determine base pwm level - Minor changes regarding variable names - Added more comments to roughly describe functionality of functions
This commit is contained in:
1 parent
15f67f6c8c
commit
f09c4ff136
6 files changed
+407
-194
No files matched your search
@@ -7,11 +7,60 @@
|
||||
#pragma once
|
||||
#include "shared.h"
|
||||
#include <math.h>
|
||||
uint16_t calc_end_target();
|
||||
bool speed_helper();
|
||||
void adjust_pwm_level(uint16_t level);
|
||||
typedef struct pid_params{
|
||||
// Controller variables - won't change after init
|
||||
float k_i; // Integral gain
|
||||
float k_d; // Derivative gain
|
||||
float t; // Sampling time
|
||||
float tau; // Low-pass-filter time constant
|
||||
float k_ff; // Feed-Forward gain
|
||||
float ci_0; // (k_i*t)/2
|
||||
float cd_0; // (k_d*2)/(2*tau+t)
|
||||
float cd_1; // (2*tau-t)/(2*tau+t)
|
||||
float int_lim_max; // max limit for integrator
|
||||
float int_lim_min; // min limit for integrator
|
||||
float max_output; // max possible pwm output value
|
||||
// Controller variables - might change on runtime
|
||||
float k_p; // Proportional gain
|
||||
float e_prev; // Previous Error
|
||||
float integral_prev; // Previous Integral Value
|
||||
float derivative_prev; // Previous Derivative Value
|
||||
float measurement_prev; // Previous Measurement
|
||||
float x_1_fwd; // Base Speed; forward direction
|
||||
float x_2_fwd; // High Speed; forward direction
|
||||
float y_1_fwd; // Base PWM; forward direction
|
||||
float y_2_fwd; // High PWM; forward direction
|
||||
float x_1_rev; // Base Speed; reverse direction
|
||||
float x_2_rev; // High Speed; reverse direction
|
||||
float y_1_rev; // Base PWM; reverse direction
|
||||
float y_2_rev; // High PWM; reverse direction
|
||||
float m_fwd; // Slope forward direction
|
||||
float m_rev; // Slope reverse direction
|
||||
uint16_t speed_table[127]; // Array with setpoint values corresponding to every speed step
|
||||
uint32_t speed_step_target; // End target speed step
|
||||
uint16_t end_target_index; // Index for speed table array corresponding to end target speed step
|
||||
uint32_t setpoint; // Current setpoint
|
||||
uint32_t setpoint_prev; // Previous setpoint
|
||||
bool direction; // Current Direction
|
||||
bool direction_prev; // Previous Direction
|
||||
// Measurement Variables
|
||||
float measurement; // Newest Measurement value
|
||||
float adc_offset; // ADC offset value
|
||||
uint8_t msr_delay_in_us; // Delay before VEMF Measurement
|
||||
uint8_t msr_total_iterations; // Amount of samples
|
||||
uint8_t l_side_arr_cutoff; // Discarded samples (left side)
|
||||
uint8_t r_side_arr_cutoff; // Discarded samples (right side)
|
||||
}pid_params;
|
||||
|
||||
void update_speed_dir(pid_params *pid, uint32_t speed_step_target);
|
||||
bool speed_helper(struct repeating_timer *t);
|
||||
float measure(pid_params *pid,bool direction);
|
||||
void adjust_pwm_level(uint16_t level, pid_params *pid);
|
||||
void update_m(pid_params *pid);
|
||||
void update_y(pid_params *pid,float i);
|
||||
float get_ff_val(pid_params *pid);
|
||||
float get_kp(pid_params *pid);
|
||||
bool pid_control(struct repeating_timer *t);
|
||||
void init_speed_table();
|
||||
void init_pid();
|
||||
void init_msr();
|
||||
uint16_t measure_base_pwm(pid_params *pid,bool direction);
|
||||
void init_pid(pid_params *pid);
|
||||
void init_motor_pwm(uint8_t gpio);
|
||||
Reference in new issue
Block a user