HRI board firmware v2.1 Microcontroller firmware of the board used during the HRI labs.

main.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2017 EPFL-LSRO (Laboratoire de Systemes Robotiques).
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
76 #ifndef __MAIN_H
77 #define __MAIN_H
78
79 #include <math.h>
80 #include <stdbool.h>
81 #include "arm_math.h"
82
83 #include "stm32f4xx_adc.h"
84 #include "stm32f4xx_dac.h"
85 #include "stm32f4xx_dma.h"
86 #include "stm32f4xx_exti.h"
87 #include "stm32f4xx_gpio.h"
88 #include "stm32f4xx_i2c.h"
89 #include "stm32f4xx_iwdg.h"
90 #include "stm32f4xx_pwr.h"
91 #include "stm32f4xx_rcc.h"
92 #include "stm32f4xx_rtc.h"
93 #include "stm32f4xx_spi.h"
94 #include "stm32f4xx_syscfg.h"
95 #include "stm32f4xx_tim.h"
96 #include "stm32f4xx_usart.h"
97 #include "stm32f4xx_wwdg.h"
98
99 // Clocks configuration.
100 #define STM_SYSCLOCK_FREQ 168000000 // [Hz].
101 #define APB1_PRESCALER 4
102 #define APB2_PRESCALER 2
103 #define TIM_MULTIPLIER 2
104
105 // Interupt priority.
106 #define CURRENT_LOOP_IRQ_PRIORITY 1 // High freq loop, should interrupt all the others.
107 #define CONTROL_LOOP_IRQ_PRIORITY 2
108 #define CODER_INDEX_IRQ_PRIORITY 2 // Useless, remove?
109 #define UART_RX_IRQ_PRIORIY 3
110 #define DATA_LOOP_IRQ_PRIORITY 4 // Streaming packets.
111 #define USER_BUTTON_IRQ_PRIORITY 4
112
113 // Electrical parameters.
114 #define STM_SUPPLY_VOLTAGE 3.3f // Power supply voltage of the microcontroller [V].
115 #define ADC_REF_VOLTAGE 2.5f // Voltage reference of the ADC (VREF) [V].
116 #define H_BRIDGE_SUPPLY_VOLTAGE 24.0f // [V].
117 #define CURRENT_SHUNT_RESISTANCE 0.025f // [ohm].
118 #define CURRENT_SHUNT_AMPLIFIER_GAIN 30.0f // Gain of 60 (AD817) / 2 (voltage divider) [].
119 #define MOTOR_RESISTANCE (10.6f + 5.0f) // 10.6 ohm according to the datasheet, actually more, depends on the motor [ohm].
120
121 // Mechanical parameters.
122 #define REDUCTION_RATIO 15.0f
123 #define MOTOR_TORQUE_CONST 0.0538f // [N.m/A].
124 #define MOTOR_SPEED_CONST 177.0f // [RPM/V].
125 #define MOTOR_NOMINAL_TORQUE 0.0323f // [N.m].
126
127 #endif