CodeUC HRI2  v2.0
Microcontroller firmware of the board used during the HRI labs.
controller.h
Go to the documentation of this file.
1 #ifndef __CONTROLLER_H
2 #define __CONTROLLER_H
3 
4 #include "main.h"
5 
6 // Type of regulation.
7 // Comment out to get the "wall" non-symetric behavior.
8 #define REGULATION_TYPE_SYMMETRIC
9 
10 // Loops periode values
11 #define TE_LOOP_MIN_VALUE 50 // Minimum period for any loop [us].
12 #define TE_LOOP_MAX_VALUE 65534 // Maximum period for any loop [us].
13 
14 #define TE_CURRENT_LOOP_DEFAULT_VAL 50 // Current control loop period [us] (max 2^16-1) (default value at reset).
15 #define TE_CONTROL_LOOP_DEFAULT_VAL 350 // Main control loop period [us] (max 2^16-1) (default value at reset).
16 #define TE_DATA_LOOP_DEFAULT_VAL 1000 // Data loop period [us] (max 2^16-1) (default value at reset).
17 
18 // Current loop parameters
19 #define KP_CURRENT_DEFAULT_VAL 200.0f
20 #define KI_CURRENT_DEFAULT_VAL 500000.0f
21 #define KD_CURRENT_DEFAULT_VAL 0.0f
22 #define FF_CURRENT_DEFAULT_VAL MOTOR_RESISTANCE
23 #define CURRENT_INTEGRATOR_SAT_DEFAULT_VAL 10.0f
24 #define CURRENT_LOOP_PWM_MAX_DUTY_CYCLE 0.98f // Max PWM value (normalized) duty cycle (less than 1 to ensure bootstrap capacitor charging)
25 
26 // Main control loop parameters
27 #define KP_POSITION_DEFAULT_VAL 0.01f
28 #define KI_POSITION_DEFAULT_VAL 0.0f
29 #define KD_POSITION_DEFAULT_VAL 0.0f
30 #define POSITION_INTEGRATOR_SAT_DEFAULT_VAL 0.01f
31 
32 // Increment encoder filter default coef.
33 #define ENCODER_FILT_TAU_DEFAULT_VAL 0.999f
34 
35 // Filter types
36 #define FILTER_TYPE_NONE 0
37 #define FILTER_TYPE_FIRST_ORDER 1
38 #define FILTER_TYPE_RUNNING_MEAN 2
39 
57 void ctrl_Init(void);
58 void ctrl_StartCurrentLoop(void);
59 
64 #endif
void ctrl_StartCurrentLoop(void)
Start the current regulation.
Definition: controller.c:63
void ctrl_Init(void)
Initialize the position and current controllers.
Definition: controller.c:31