目录
使用正点原子核心板,24V电机(带编码器),超声波加舵机避障
前言
1
全向轮小车
一、全向轮小车姿态解算以及说明
详细代码在下面,只看姿态解算的到此结束。
原理图+PCB板
二、cubemx配置
整体引脚图:
cubemx配置:
RCC时钟源
系统时钟源
窗口看门狗
RTC:
定时器3(编码器模式)
定时器2(编码器模式)
定时器4(编码器模式)
定时器5(PWM输出模式)频率10Khz
定时器8(PWM输出模式)频率10Khz
定时器9,10(输入捕获)超声波功能
定时器11,13,14(PWM输出)舵机功能
FSMC LCD屏幕
串口1~6
freertos配置
三、代码
freertos代码:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : freertos.c
* Description : Code for freertos applications
******************************************************************************
* @attention
*
* Copyright (c) 2016 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "rtc.h"
#include "stdio.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
uint8_t ID;
uint8_t key;
Uart_Tpye_t Uart2;
Uart_Tpye_t Uart3;
extern DMA_HandleTypeDef hdma_usart3_rx;
extern uint16_t ADC_Value[1];
extern struct Supersonic supersonic1;
extern struct Supersonic supersonic2;
extern struct Supersonic supersonic3;
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
/* Definitions for LED_Task */
osThreadId_t LED_TaskHandle;
const osThreadAttr_t LED_Task_attributes = {
.name = "LED_Task",
.stack_size = 256 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Serial_esp32 */
osThreadId_t Serial_esp32Handle;
const osThreadAttr_t Serial_esp32_attributes = {
.name = "Serial_esp32",
.stack_size = 512 * 4,
.priority = (osPriority_t) osPriorityNormal1,
};
/* Definitions for LCD */
osThreadId_t LCDHandle;
const osThreadAttr_t LCD_attributes = {
.name = "LCD",
.stack_size = 512 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Control_A4950 */
osThreadId_t Control_A4950Handle;
const osThreadAttr_t Control_A4950_attributes = {
.name = "Control_A4950",
.stack_size = 1024 * 4,
.priority = (osPriority_t) osPriorityNormal1,
};
/* Definitions for SG90_Ware */
osThreadId_t SG90_WareHandle;
const osThreadAttr_t SG90_Ware_attributes = {
.name = "SG90_Ware",
.stack_size = 512 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for send_Serial */
osThreadId_t send_SerialHandle;
const osThreadAttr_t send_Serial_attributes = {
.name = "send_Serial",
.stack_size = 256 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for myQueue01 */
osMessageQueueId_t myQueue01Handle;
const osMessageQueueAttr_t myQueue01_attributes = {
.name = "myQueue01"
};
/* Definitions for myQueue02 */
osMessageQueueId_t myQueue02Handle;
const osMessageQueueAttr_t myQueue02_attributes = {
.name = "myQueue02"
};
/* Definitions for myQueue03 */
osMessageQueueId_t myQueue03Handle;
const osMessageQueueAttr_t myQueue03_attributes = {
.name = "myQueue03"
};
/* Definitions for myQueue04 */
osMessageQueueId_t myQueue04Handle;
const osMessageQueueAttr_t myQueue04_attributes = {
.name = "myQueue04"
};
/* Definitions for myQueue05 */
osMessageQueueId_t myQueue05Handle;
const osMessageQueueAttr_t myQueue05_attributes = {
.name = "myQueue05"
};
/* Definitions for myQueue06 */
osMessageQueueId_t myQueue06Handle;
const osMessageQueueAttr_t myQueue06_attributes = {
.name = "myQueue06"
};
/* Definitions for speed */
osMessageQueueId_t speedHandle;
const osMessageQueueAttr_t speed_attributes = {
.name = "speed"
};
/* Definitions for Angle */
osMessageQueueId_t AngleHandle;
const osMessageQueueAttr_t Angle_attributes = {
.name = "Angle"
};
/* Definitions for rotate */
osMessageQueueId_t rotateHandle;
const osMessageQueueAttr_t rotate_attributes = {
.name = "rotate"
};
/* Definitions for Switch */
osMessageQueueId_t SwitchHandle;
const osMessageQueueAttr_t Switch_attributes = {
.name = "Switch"
};
/* Definitions for myMutex01 */
osMutexId_t myMutex01Handle;
const osMutexAttr_t myMutex01_attributes = {
.name = "myMutex01"
};
/* Definitions for myMutex02 */
osMutexId_t myMutex02Handle;
const osMutexAttr_t myMutex02_attributes = {
.name = "myMutex02"
};
/* Definitions for myMutex03 */
osMutexId_t myMutex03Handle;
const osMutexAttr_t myMutex03_attributes = {
.name = "myMutex03"
};
/* Definitions for myBinarySem01 */
osSemaphoreId_t myBinarySem01Handle;
const osSemaphoreAttr_t myBinarySem01_attributes = {
.name = "myBinarySem01"
};
/* Definitions for myEvent01 */
osEventFlagsId_t myEvent01Handle;
const osEventFlagsAttr_t myEvent01_attributes = {
.name = "myEvent01"
};
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* USER CODE END FunctionPrototypes */
void APP_LED_Task(void *argument);
void APP_Serial_esp32(void *argument);
void APP_LCD(void *argument);
void APP_Control_A4950(void *argument);
void APP_SG90_Ware(void *argument);
void APP_send_Serial(void *argument);
extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/**
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Create the mutex(es) */
/* creation of myMutex01 */
myMutex01Handle = osMutexNew(&myMutex01_attributes);
/* creation of myMutex02 */
myMutex02Handle = osMutexNew(&myMutex02_attributes);
/* creation of myMutex03 */
myMutex03Handle = osMutexNew(&myMutex03_attributes);
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* Create the semaphores(s) */
/* creation of myBinarySem01 */
myBinarySem01Handle = osSemaphoreNew(1, 0, &myBinarySem01_attributes);
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* Create the queue(s) */
/* creation of myQueue01 */
myQueue01Handle = osMessageQueueNew (1, sizeof(uint16_t), &myQueue01_attributes);
/* creation of myQueue02 */
myQueue02Handle = osMessageQueueNew (1, sizeof(uint16_t), &myQueue02_attributes);
/* creation of myQueue03 */
myQueue03Handle = osMessageQueueNew (1, sizeof(uint16_t), &myQueue03_attributes);
/* creation of myQueue04 */
myQueue04Handle = osMessageQueueNew (1, sizeof(uint16_t), &myQueue04_attributes);
/* creation of myQueue05 */
myQueue05Handle = osMessageQueueNew (1, sizeof(uint16_t), &myQueue05_attributes);
/* creation of myQueue06 */
myQueue06Handle = osMessageQueueNew (1, sizeof(uint16_t), &myQueue06_attributes);
/* creation of speed */
speedHandle = osMessageQueueNew (1, sizeof(float), &speed_attributes);
/* creation of Angle */
AngleHandle = osMessageQueueNew (1, sizeof(float), &Angle_attributes);
/* creation of rotate */
rotateHandle = osMessageQueueNew (1, sizeof(int), &rotate_attributes);
/* creation of Switch */
SwitchHandle = osMessageQueueNew (1, sizeof(uint8_t), &Switch_attributes);
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* creation of LED_Task */
LED_TaskHandle = osThreadNew(APP_LED_Task, NULL, &LED_Task_attributes);
/* creation of Serial_esp32 */
Serial_esp32Handle = osThreadNew(APP_Serial_esp32, NULL, &Serial_esp32_attributes);
/* creation of LCD */
LCDHandle = osTh