diff --git a/Firmware/src/controller.h b/Firmware/src/controller.h index 45b3085..9bba7e6 100644 --- a/Firmware/src/controller.h +++ b/Firmware/src/controller.h @@ -1,64 +1,64 @@ #ifndef __CONTROLLER_H #define __CONTROLLER_H #include "main.h" // Type of regulation. // Comment out to get the "wall" non-symetric behavior. #define REGULATION_TYPE_SYMMETRIC // Loops periode values #define TE_LOOP_MIN_VALUE 50 // Minimum period for any loop [us]. #define TE_LOOP_MAX_VALUE 65534 // Maximum period for any loop [us]. #define TE_CURRENT_LOOP_DEFAULT_VAL 50 // Current control loop period [us] (max 2^16-1) (default value at reset). #define TE_CONTROL_LOOP_DEFAULT_VAL 350 // Main control loop period [us] (max 2^16-1) (default value at reset). #define TE_DATA_LOOP_DEFAULT_VAL 1000 // Data loop period [us] (max 2^16-1) (default value at reset). // Current loop parameters #define KP_CURRENT_DEFAULT_VAL 200.0f #define KI_CURRENT_DEFAULT_VAL 500000.0f #define KD_CURRENT_DEFAULT_VAL 0.0f #define FF_CURRENT_DEFAULT_VAL MOTOR_RESISTANCE -#define CURRENT_INTEGRATOR_SAT_DEFAULT_VAL 24.0f +#define CURRENT_INTEGRATOR_SAT_DEFAULT_VAL 10.0f #define CURRENT_LOOP_PWM_MAX_DUTY_CYCLE 0.98f // Max PWM value (normalized) duty cycle (less than 1 to ensure bootstrap capacitor charging) // Main control loop parameters #define KP_POSITION_DEFAULT_VAL 0.01f #define KI_POSITION_DEFAULT_VAL 0.0f #define KD_POSITION_DEFAULT_VAL 0.0f #define POSITION_INTEGRATOR_SAT_DEFAULT_VAL 0.01f // Increment encoder filter default coef. #define ENCODER_FILT_TAU_DEFAULT_VAL 0.999f // Filter types #define FILTER_TYPE_NONE 0 #define FILTER_TYPE_FIRST_ORDER 1 #define FILTER_TYPE_RUNNING_MEAN 2 /** @defgroup Controller Main / Controllers * @brief Control the paddle * * This module is the high-level controller of the board. It runs two "loops" * (in fact, functions called periodically by the interrupt of a timer), one to * regulate the motor current (ctrl_RegulateCurrent(), high frequency) and * another to control the rest (ctrl_RegulatePosition(), lower frequency). * The content of ctrl_RegulatePosition() is typically what the user of the * board will modify, depending on the selected sensors and control algorithms. * * Call ctrl_Init() to setup this module. Its interrupt functions will be called * automatically periodically. * * @addtogroup Controller * @{ */ void ctrl_Init(void); void ctrl_StartCurrentLoop(void); /** * @} */ #endif diff --git a/Firmware/src/main.h b/Firmware/src/main.h index eba926f..fe40299 100644 --- a/Firmware/src/main.h +++ b/Firmware/src/main.h @@ -1,96 +1,96 @@ /** \mainpage HRI board firmware documentation * \section intro_sec Introduction * This is the documentation of the HRI board firmware. You will find a * description of the provided library and drivers. As all the hardware and * software is very new, please do not hesitate to suggest improvements to the * course assistants (Romain Baud, Philipp Hörler and Laurent Jenni). * * \section code_struct_sec Code structure * The code is divided into 3 parts: * - main: this is where the controllers and the communication protocol are * implemented. The call of all the initialization functions is also made here. * - library: all the algorithms, data structures that could be used at many * places, are put into the library. * - drivers: there is one driver per peripheral. All the hardware-specific * code is wrapped into these files, so that the user does not have to worry * about the microcontroller operation (and spend a lot of time to read the * documentation). * * One module (controller, communication, library or driver) is always splitted * in two files, .h and .c, like in C++. * @image html soft_architecture.png * * \section lib_how_to How to use the provided library * For most of the driver/library modules, call x_Init() only once, when the * program starts (typically in the main()). Then, you can call * x_Step()/x_Set()/x_Get() everytime as needed, typically in the control * functions called periodically (ctrl_RegulatePosition()...). * * See the "Modules" section of this documentation to see how they work. * * \section stm32_resources_usage STM32's resources usage * \subsection stm32_resources_usage_timers Timers * - TIM1: PWM of the 4 user LEDs. * - TIM2: - * - TIM3: - * - TIM4: - * - TIM5: encoder quadrature decoder. * - TIM6: position loop. * - TIM7: variables streaming loop. * - TIM8: H-bridge PWM. * - TIM9: - * - TIM10: current loop. * - TIM11: - * - TIM12: - * - TIM13: - * - TIM14: - * \subsection stm32_resources_usage_adcs ADCs * - ADC1: general purpose ADC. * - ADC2: - * - ADC3: motor current sensor ADC. * \subsection stm32_resources_usage_dac DAC * - DAC: DAC extension. * \subsection stm32_resources_usage_buses Communication buses * - USART1: UART extension. * - USART2: USB communication UART. * - I2C1: I2C extension. * - SPI3: SPI extension. */ #ifndef __MAIN_H #define __MAIN_H #include "stm32f4_discovery.h" #include #include #include "arm_math.h" // Clocks configuration. #define STM_SYSCLOCK_FREQ 168000000 // [Hz]. #define APB1_PRESCALER 4 #define APB2_PRESCALER 2 #define TIM_MULTIPLIER 2 // Interupt priority. #define CURRENT_LOOP_IRQ_PRIORITY 1 // High freq loop, should interrupt all the others. #define CONTROL_LOOP_IRQ_PRIORITY 2 #define CODER_INDEX_IRQ_PRIORITY 2 // Useless, remove? #define UART_RX_IRQ_PRIORIY 3 #define DATA_LOOP_IRQ_PRIORITY 4 // Streaming packets. #define USER_BUTTON_IRQ_PRIORITY 4 // Electrical parameters. #define STM_SUPPLY_VOLTAGE 3.3f // Power supply voltage of the microcontroller [V]. #define ADC_REF_VOLTAGE 2.5f // Voltage reference of the ADC (VREF) [V]. #define H_BRIDGE_SUPPLY_VOLTAGE 24.0f // [V]. #define CURRENT_SHUNT_RESISTANCE 0.025f // [ohm]. -#define CURRENT_SHUNT_AMPLIFIER_GAIN 50.0f // []. +#define CURRENT_SHUNT_AMPLIFIER_GAIN 30.0f // Gain of 60 (AD817) / 2 (voltage divider) []. #define MOTOR_RESISTANCE 10.6f + 5.0f // 10.6 ohm according to the datasheet, actually more, depends on the motor [ohm]. // Mechanical parameters. #define REDUCTION_RATIO 16.5f #define MOTOR_TORQUE_CONST 0.0538f // [N.m/A]. #define MOTOR_SPEED_CONST 177.0f // [RPM/V]. #define MOTOR_NOMINAL_TORQUE 0.0323f // [N.m]. #endif