添加ADC采集电压和RGB灯

This commit is contained in:
2024-03-08 15:19:23 +08:00
parent 7749d1d7b7
commit fa1cc826f1
14 changed files with 1189 additions and 915 deletions

View File

@ -5,7 +5,7 @@
#define _constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
float Voltage_PowerSupply = 12;
const float Voltage_PowerSupply = 12;
float Pole_Pairs = 14;
float Voltage_Limit = 6.9;
float Velocity_Limit = 100;
@ -17,15 +17,15 @@ FOCTypeDef FOCStruct_Y={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void PID_Iint(void)
{
FOCStruct_X.ZT_KP = 4;
FOCStruct_X.ZT_KP = 3.5;
FOCStruct_X.ZT_KI = 0;
FOCStruct_X.ZT_KD = 0.5;
FOCStruct_X.V_KP = 0.1;
FOCStruct_X.V_KI = 2;
FOCStruct_X.V_KI = 1;
FOCStruct_X.V_KD = 0;
//2024/1/2 Y<><59>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FOCStruct_Y.ZT_KP = 2;
///////////
FOCStruct_Y.ZT_KP = 3;
FOCStruct_Y.ZT_KI = 0;
FOCStruct_Y.ZT_KD = 0.5;

View File

@ -9,35 +9,40 @@ void mymain()
HAL_UART_Receive_IT(&huart1, (uint8_t *)g_rx_buffer, RXBUFFERSIZE); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
HAL_Delay(2000);
led_init();
adc_init();
tle5012b_init();
Init_ICM42688();
imu_rest();
// Init_ICM42688();
// imu_rest();
moto_Init();
PID_Iint();
setvbuf(stdout, NULL, _IONBF, 0); //<2F><><EFBFBD><EFBFBD>printfû<66><C3BB>\n<><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
float x = 0,y=0;
unsigned int i =0;
HAL_TIM_Base_Start(&htim5); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// while(i<3300*3)
// while(i<2000*1)
// {
// Angel_closed_loop(motorx,&FOCStruct_X,-0.2);
// Angel_closed_loop(motory,&FOCStruct_Y,2.3);
//// MpuGetData();
//// GetAngle(&ICM42688,&Angle);
// Angel_closed_loop(motorx,&FOCStruct_X,3.0);
// Angel_closed_loop(motory,&FOCStruct_Y,2.2);
// i++;
// }
// i=0;
LED_ON;
// LED_ON;
while(1)
{
MpuGetData();
GetAngle(&ICM42688,&Angle);
x = Angle.pitch;
y = Angle.roll ;
Zitai_closed_loop(motorx,&FOCStruct_X,x);
Zitai_closed_loop(motory,&FOCStruct_Y,-y);
commander_run();
// MpuGetData();
// GetAngle(&ICM42688,&Angle);
// x = Angle.pitch;
// y = Angle.roll;
// Zitai_closed_loop(motorx,&FOCStruct_X,x);
// Zitai_closed_loop(motory,&FOCStruct_Y,-y);
// commander_run();
// x = getAngle(motorx);
// y = getAngle(motory);
// x= get_VCC();
// printf("%fY%f\n",x,y);
// HAL_Delay(2);
// speed_closed_loop(motorx,&FOCStruct_X,_2PI*5);
// speed_closed_loop(motory,&FOCStruct_Y,_2PI*2);
// printf("b%d\n",b);

View File

@ -16,6 +16,7 @@
#include "main.h"
#include "tim.h"
#include "adc.h"
#include "usart.h"
#include "gpio.h"
#include "tle5012b.h"
@ -30,6 +31,7 @@
#include "LED.h"
#include "Usart1.h"
#include "LED_RGB.h"
#include "vcc_adc.h"
void mymain();
#endif //FOC_N_MYMAIN_H

43
APP/vcc_adc.c Normal file
View File

@ -0,0 +1,43 @@
//
// Created by hu123456 on 2024/3/8.
//
#include "vcc_adc.h"
void adc_init(void)
{
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
}
uint32_t adc_get_result(void)
{
ADC_ChannelConfTypeDef adc_ch_conf = {0};
adc_ch_conf.Channel = ADC_CHANNEL_8;
adc_ch_conf.Rank = ADC_REGULAR_RANK_1;
adc_ch_conf.SamplingTime = ADC_SAMPLETIME_810CYCLES_5;
adc_ch_conf.SingleDiff = ADC_SINGLE_ENDED;
adc_ch_conf.OffsetNumber = ADC_OFFSET_NONE;
adc_ch_conf.Offset = 0;
HAL_ADC_ConfigChannel(&hadc1, &adc_ch_conf);
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 10);
return HAL_ADC_GetValue(&hadc1);
}
float get_VCC(void)
{
uint32_t temp_val = 0;
float vcc;
for (uint8_t t = 0; t < 10; t++)
{
temp_val += adc_get_result();
HAL_Delay(5);
}
vcc = temp_val/10.f/65535.f * 3.3 * 11.f;
return vcc;
}

14
APP/vcc_adc.h Normal file
View File

@ -0,0 +1,14 @@
//
// Created by hu123456 on 2024/3/8.
//
#ifndef FOC_N_VCC_ADC_H
#define FOC_N_VCC_ADC_H
#include "mymain.h"
void adc_init(void);
uint32_t adc_get_result(void);
float get_VCC(void);
#endif //FOC_N_VCC_ADC_H