You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.0 KiB

3 years ago
/*
* @Author: your name
* @Date: 2022-04-17 21:03:48
3 years ago
* @LastEditTime: 2022-04-18 23:11:30
3 years ago
* @LastEditors: Please set LastEditors
* @Description: koroFileHeader查看配置 : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \undefinede:\\\MotorPid\stm32\USER\main.c
*/
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "wifi.h"
#include "adc.h"
#include "timer.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oled.h"
#include "motor.h"
#include "encoder.h"
#include "key.h"
struct UserInfo userInfo;
// 函数声明
void Sys_Init(void);
void processingTasks(void);
void OLED_Display(void);
/**
* @description: main函数
* @param {*}
* @return {*}
*/
int main(void)
{
Sys_Init();
delay_ms(1000);
while(1)
{
processingTasks();
OLED_Display();
delay_ms(100);
}
}
/**
* @description: pid
* @param {int} targetSpeed
* @param {int} currentSpeed
* @return {*}
*/
int velocity_PID(int targetSpeed, int currentSpeed){
static float velocity_Kp = 0.04, velocity_Kd = 0;
int Bias, velocity = 0;
Bias = currentSpeed - targetSpeed;
velocity = velocity_Kp * Bias + Bias * velocity_Kd;
return velocity;
}
/**
* @description:
* @param {*}
* @return {*}
*/
void processingTasks(void)
{
int key = 0;
// 方向
if(userInfo.diversion) AIN1 = 1, AIN1 = 0;
else AIN1 = 0, AIN1 = 1;
}
/**
* @description:
* @param {*}
* @return {*}
*/
void Sys_Init(void)
{
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
PWM_Init(7199,0);
TIM3_Int_Init(5000, 71); // 定时器3
Encoder_Init_TIM2();
KEY_Init();
OLED_Init();
OLED_Clear();
userInfo.pwm_val = 6000;
}
/**
* @description: Oled显示
* @param {*}
* @return {*}
*/
void OLED_Display(void)
{
char str[30];
sprintf(str, "speed:%d,pwd_val:%d", abs(userInfo.currentSpeed), userInfo.pwm_val);
OLED_ShowString(0,0, str, 16);
}