Skip to content

Commit

Permalink
Добавлено чтение данных с GPS (#180)
Browse files Browse the repository at this point in the history
В лог отправляем координаты курс и скорость

Co-authored-by: Gavriliyuk Vasiliy <[email protected]>
  • Loading branch information
PugachA and NoMonsters authored May 1, 2021
1 parent 0839309 commit 2fa0ac5
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 23 deletions.
1 change: 1 addition & 0 deletions Plane/Core/Inc/stm32f4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void DebugMon_Handler(void);
void TIM2_IRQHandler(void);
void TIM4_IRQHandler(void);
void USART2_IRQHandler(void);
void USART3_IRQHandler(void);
void TIM8_TRG_COM_TIM14_IRQHandler(void);
void TIM5_IRQHandler(void);
void TIM6_DAC_IRQHandler(void);
Expand Down
67 changes: 64 additions & 3 deletions Plane/Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "PIReg/PIReg.h"
#include "Beta/P3002.h"
#include "PWMCapturer/PWMCapturer.h"
#include "Gps/Gps.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -74,6 +75,7 @@ TIM_HandleTypeDef htim5;
TIM_HandleTypeDef htim6;

UART_HandleTypeDef huart2;
UART_HandleTypeDef huart3;

/* USER CODE BEGIN PV */
enum Channels
Expand All @@ -99,6 +101,11 @@ enum Sensors
TETA,
GAMMA,
PSI,
LATITUDE,
LONGITUDE,
GPS_SPEED,
COURSE,
GPS_VALID,
SENSOR_ARRAY_SIZE, //этот элемент всегда должен быть последним в енуме
};
enum Modes
Expand Down Expand Up @@ -249,6 +256,15 @@ void IcHandlerTim4(TIM_HandleTypeDef *htim)
} break;
}
}

//GPS-----------------------------------------------------------
Gps gps = Gps(&huart3, GPIOE, GPIO_PIN_7);

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart == &huart3)
gps.UartCallback();
}
//-----------------------------------------------------------

Servo thr_servo(&htim3, 1),
Expand Down Expand Up @@ -290,6 +306,7 @@ static void MX_I2C3_Init(void);
static void MX_TIM6_Init(void);
static void MX_TIM4_Init(void);
static void MX_I2C2_Init(void);
static void MX_USART3_UART_Init(void);
void StartDefaultTask(void *argument);
void sensorsUpdateTask(void *argument);
void modeUpdateTask(void *argument);
Expand Down Expand Up @@ -583,6 +600,7 @@ int main(void)
MX_TIM6_Init();
MX_TIM4_Init();
MX_I2C2_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */

//-------------------Radio PWM IC INIT--------------------------
Expand Down Expand Up @@ -1266,6 +1284,39 @@ static void MX_USART2_UART_Init(void)

}

/**
* @brief USART3 Initialization Function
* @param None
* @retval None
*/
static void MX_USART3_UART_Init(void)
{

/* USER CODE BEGIN USART3_Init 0 */

/* USER CODE END USART3_Init 0 */

/* USER CODE BEGIN USART3_Init 1 */

/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 38400;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */

/* USER CODE END USART3_Init 2 */

}

/**
* @brief GPIO Initialization Function
* @param None
Expand Down Expand Up @@ -1348,6 +1399,8 @@ void sensorsUpdateTask(void *argument)
bno055_vector_t euler;
bno055_vector_t accel;

gps.Start();

//MS4525DO ms4525do(&hi2c2, 0.01);
/* Infinite loop */
for(;;)
Expand All @@ -1365,6 +1418,13 @@ void sensorsUpdateTask(void *argument)
data_input[NZ] = accel.z;
//data_input[AIR] = ms4525do.getAirSpeed();
//data_input[BETA] = p3002.getAngle();

data_input[LATITUDE] = (double) minmea_tocoord(&gps.gpsData.latitude);
data_input[LONGITUDE] = (double) minmea_tocoord(&gps.gpsData.longitude);
data_input[GPS_SPEED] = (double) minmea_tofloat(&gps.gpsData.speed) * 0.51; //перевод в м/с из узлов
data_input[COURSE] = (double) minmea_tofloat(&gps.gpsData.course);
data_input[GPS_VALID] = (double) gps.gpsData.valid;

osDelay(10);//ещё 5 мС внутри либы airspeed
}
/* USER CODE END sensorsUpdateTask */
Expand Down Expand Up @@ -1426,15 +1486,16 @@ void loggerUpdateTask(void *argument)
{
memset(str, '\0', sizeof(str));
#ifndef DEBUG_MODE
sprintf(str, "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d",\
HAL_GetTick(), (int)(10*logger_data[OMEGA_X_ZAD]), (int)(data_input[GYROX]*10),\
sprintf(str, "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d",\
(int)HAL_GetTick(), (int)(10*logger_data[OMEGA_X_ZAD]), (int)(data_input[GYROX]*10),\
(int)(10*logger_data[OMEGA_Y_ZAD]), (int)(data_input[GYROY]*10), (int)(10*logger_data[OMEGA_Z_ZAD]),\
(int)(data_input[GYROZ]*10), (int)(data_input[BARO]*100), (int)(100*logger_data[VY_ZAD]),\
(int)(100*data_input[BAROVY]), (int)(100*data_input[AIR]), (int)(k_pr_omega_x*10),\
(int)(100*k_int_omega_x), (int)(10*k_pr_omega_y), (int)(100*k_int_omega_y),\
(int)(10*k_pr_omega_z), (int)(100*k_int_omega_z), (int)(10*k_pr_Vy),\
(int)(data_input[TETA]*10), (int)(data_input[GAMMA]*10), (int)(data_input[PSI]*10),\
(int)(data_input[NZ]*1000), switch_rc.getPulseWidth());
(int)(data_input[NZ]*1000), (int)(data_input[LONGITUDE]*1000000), (int)(data_input[LATITUDE]*1000000),\
(int)(data_input[GPS_SPEED]*100), (int)(data_input[COURSE]*10), (int)(data_input[GPS_VALID]), (int)switch_rc.getPulseWidth());
#else
#if DEBUG_MODE == BARO_DEBUG
sprintf(str, "%d %d %d\n", (int)(data_input[BARO]*100), (int)(logger_data[ALT_FILTERED]*100), (int)(100*data_input[BAROVY]));
Expand Down
47 changes: 47 additions & 0 deletions Plane/Core/Src/stm32f4xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,33 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)

/* USER CODE END USART2_MspInit 1 */
}
else if(huart->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspInit 0 */

/* USER CODE END USART3_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART3_CLK_ENABLE();

__HAL_RCC_GPIOD_CLK_ENABLE();
/**USART3 GPIO Configuration
PD8 ------> USART3_TX
PD9 ------> USART3_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

/* USART3 interrupt Init */
HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
/* USER CODE BEGIN USART3_MspInit 1 */

/* USER CODE END USART3_MspInit 1 */
}

}

Expand Down Expand Up @@ -711,6 +738,26 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)

/* USER CODE END USART2_MspDeInit 1 */
}
else if(huart->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspDeInit 0 */

/* USER CODE END USART3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART3_CLK_DISABLE();

/**USART3 GPIO Configuration
PD8 ------> USART3_TX
PD9 ------> USART3_RX
*/
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9);

/* USART3 interrupt DeInit */
HAL_NVIC_DisableIRQ(USART3_IRQn);
/* USER CODE BEGIN USART3_MspDeInit 1 */

/* USER CODE END USART3_MspDeInit 1 */
}

}

Expand Down
15 changes: 15 additions & 0 deletions Plane/Core/Src/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern TIM_HandleTypeDef htim4;
extern TIM_HandleTypeDef htim5;
extern TIM_HandleTypeDef htim6;
extern UART_HandleTypeDef huart2;
extern UART_HandleTypeDef huart3;
extern TIM_HandleTypeDef htim14;

/* USER CODE BEGIN EV */
Expand Down Expand Up @@ -205,6 +206,20 @@ void USART2_IRQHandler(void)
/* USER CODE END USART2_IRQn 1 */
}

/**
* @brief This function handles USART3 global interrupt.
*/
void USART3_IRQHandler(void)
{
/* USER CODE BEGIN USART3_IRQn 0 */

/* USER CODE END USART3_IRQn 0 */
HAL_UART_IRQHandler(&huart3);
/* USER CODE BEGIN USART3_IRQn 1 */

/* USER CODE END USART3_IRQn 1 */
}

/**
* @brief This function handles TIM8 trigger and commutation interrupts and TIM14 global interrupt.
*/
Expand Down
51 changes: 31 additions & 20 deletions Plane/Plane.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Mcu.IP11=TIM4
Mcu.IP12=TIM5
Mcu.IP13=TIM6
Mcu.IP14=USART2
Mcu.IP15=USART3
Mcu.IP2=FREERTOS
Mcu.IP3=I2C1
Mcu.IP4=I2C2
Expand All @@ -45,7 +46,7 @@ Mcu.IP6=NVIC
Mcu.IP7=RCC
Mcu.IP8=SYS
Mcu.IP9=TIM2
Mcu.IPNb=15
Mcu.IPNb=16
Mcu.Name=STM32F407V(E-G)Tx
Mcu.Package=LQFP100
Mcu.Pin0=PH0-OSC_IN
Expand All @@ -56,32 +57,34 @@ Mcu.Pin12=PB1
Mcu.Pin13=PE7
Mcu.Pin14=PB10
Mcu.Pin15=PB11
Mcu.Pin16=PD12
Mcu.Pin17=PD13
Mcu.Pin18=PC9
Mcu.Pin19=PA8
Mcu.Pin16=PD8
Mcu.Pin17=PD9
Mcu.Pin18=PD12
Mcu.Pin19=PD13
Mcu.Pin2=PA0-WKUP
Mcu.Pin20=PD5
Mcu.Pin21=PD6
Mcu.Pin22=PB3
Mcu.Pin23=PB6
Mcu.Pin24=PB7
Mcu.Pin25=PB9
Mcu.Pin26=VP_FREERTOS_VS_CMSIS_V2
Mcu.Pin27=VP_SYS_VS_tim14
Mcu.Pin28=VP_TIM2_VS_ClockSourceINT
Mcu.Pin29=VP_TIM3_VS_ClockSourceINT
Mcu.Pin20=PC9
Mcu.Pin21=PA8
Mcu.Pin22=PD5
Mcu.Pin23=PD6
Mcu.Pin24=PB3
Mcu.Pin25=PB6
Mcu.Pin26=PB7
Mcu.Pin27=PB9
Mcu.Pin28=VP_FREERTOS_VS_CMSIS_V2
Mcu.Pin29=VP_SYS_VS_tim14
Mcu.Pin3=PA1
Mcu.Pin30=VP_TIM4_VS_ClockSourceINT
Mcu.Pin31=VP_TIM5_VS_ClockSourceINT
Mcu.Pin32=VP_TIM6_VS_ClockSourceINT
Mcu.Pin30=VP_TIM2_VS_ClockSourceINT
Mcu.Pin31=VP_TIM3_VS_ClockSourceINT
Mcu.Pin32=VP_TIM4_VS_ClockSourceINT
Mcu.Pin33=VP_TIM5_VS_ClockSourceINT
Mcu.Pin34=VP_TIM6_VS_ClockSourceINT
Mcu.Pin4=PA2
Mcu.Pin5=PA3
Mcu.Pin6=PA4
Mcu.Pin7=PA5
Mcu.Pin8=PA6
Mcu.Pin9=PA7
Mcu.PinsNb=33
Mcu.PinsNb=35
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F407VGTx
Expand All @@ -108,6 +111,7 @@ NVIC.TIM8_TRG_COM_TIM14_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
NVIC.TimeBase=TIM8_TRG_COM_TIM14_IRQn
NVIC.TimeBaseIP=TIM14
NVIC.USART2_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.USART3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA0-WKUP.Signal=S_TIM5_CH1
PA1.Signal=S_TIM5_CH2
Expand Down Expand Up @@ -151,6 +155,10 @@ PD5.Mode=Asynchronous
PD5.Signal=USART2_TX
PD6.Mode=Asynchronous
PD6.Signal=USART2_RX
PD8.Mode=Asynchronous
PD8.Signal=USART3_TX
PD9.Mode=Asynchronous
PD9.Signal=USART3_RX
PE7.Locked=true
PE7.Signal=GPIO_Output
PH0-OSC_IN.Mode=HSE-External-Oscillator
Expand Down Expand Up @@ -185,7 +193,7 @@ ProjectManager.StackSize=0x80000
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_TIM2_Init-TIM2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM3_Init-TIM3-false-HAL-true,6-MX_TIM5_Init-TIM5-false-HAL-true,7-MX_ADC1_Init-ADC1-false-HAL-true,8-MX_I2C1_Init-I2C1-false-HAL-true,9-MX_ADC2_Init-ADC2-false-HAL-true,10-MX_I2C3_Init-I2C3-false-HAL-true,11-MX_TIM6_Init-TIM6-false-HAL-true,12-MX_TIM4_Init-TIM4-false-HAL-true,13-MX_I2C2_Init-I2C2-false-HAL-true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_TIM2_Init-TIM2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM3_Init-TIM3-false-HAL-true,6-MX_TIM5_Init-TIM5-false-HAL-true,7-MX_ADC1_Init-ADC1-false-HAL-true,8-MX_I2C1_Init-I2C1-false-HAL-true,9-MX_ADC2_Init-ADC2-false-HAL-true,10-MX_I2C3_Init-I2C3-false-HAL-true,11-MX_TIM6_Init-TIM6-false-HAL-true,12-MX_TIM4_Init-TIM4-false-HAL-true,13-MX_I2C2_Init-I2C2-false-HAL-true,14-MX_USART3_UART_Init-USART3-false-HAL-true
RCC.48MHZClocksFreq_Value=84000000
RCC.AHBFreq_Value=168000000
RCC.APB1CLKDivider=RCC_HCLK_DIV4
Expand Down Expand Up @@ -276,6 +284,9 @@ TIM6.Prescaler=83
TIM6.TIM_MasterOutputTrigger=TIM_TRGO_UPDATE
USART2.IPParameters=VirtualMode
USART2.VirtualMode=VM_ASYNC
USART3.BaudRate=38400
USART3.IPParameters=VirtualMode,BaudRate
USART3.VirtualMode=VM_ASYNC
VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2
VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2
VP_SYS_VS_tim14.Mode=TIM14
Expand Down

0 comments on commit 2fa0ac5

Please sign in to comment.