stm32F103pid调试助手
时间: 2023-07-30 18:12:33 浏览: 154
stm32F103程序
在STM32F103的PID调试助手中,你可以使用以下代码来实现功能:
首先,你需要在程序初始化部分定义一个初始化函数,对PID参数进行初始化配置。例如,你可以使用以下代码:
```c
void PID_Init(PID_InitDefStruct* p) {
p->Velcity_Kp = 5;
p->Velcity_Ki = 0.5;
p->Velcity_Kd = 0;
p->Ur = 7100;
p->PID_is_Enable = 1;
p->Un = 0;
p->En_1 = 0;
p->En_2 = 0;
p->PWM = 0;
}
```
接下来,你需要修改串口1的中断函数,并添加一个Usart_SendArray函数,用于PID调试。例如,你可以使用以下代码:
```c
void USART1_IRQHandler(void) {
uint8_t ucTemp;
if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE) != RESET) {
ucTemp = USART_ReceiveData(DEBUG_USARTx);
protocol_data_recv(&ucTemp, 1);
}
USART_ClearITPendingBit(DEBUG_USARTx,USART_IT_RXNE);
}
void Usart_SendArray(USART_TypeDef* USARTx, uint8_t *array,uint8_t num) {
uint8_t i;
for( i=0; i<num; i++ ) {
Usart_SendByte(USARTx, array\[i\]);
}
while( USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET );
}
```
最后,你可以根据需要在代码中添加PID调试的相关逻辑。例如,你可以根据输入的GPIO信号来调整左右电机的速度和PWM输出。例如,你可以使用以下代码:
```c
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14)==0) {
left_set_point=left_targetspeed*SPEED_AMPLIF;
right_set_point=right_targetspeed*SPEED_AMPLIF;
TIM_SetCompare1(TIM2,0);
TIM_SetCompare2(TIM2,left_compara);
TIM_SetCompare3(TIM2,0);
TIM_SetCompare4(TIM2,right_compara);
} else if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)==0) {
left_set_point=left_targetspeed/2*SPEED_AMPLIF;
right_set_point=right_targetspeed*SPEED_AMPLIF;
left_compara=0;
TIM_SetCompare1(TIM2,0);
TIM_SetCompare2(TIM2,0);
TIM_SetCompare3(TIM2,0);
TIM_SetCompare4(TIM2,right_compara);
} else if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15)==0) {
right_set_point=right_targetspeed/2*SPEED_AMPLIF;
left_set_point=left_targetspeed*SPEED_AMPLIF;
right_compara=0;
TIM_SetCompare1(TIM2,0);
TIM_SetCompare2(TIM2,left_compara);
TIM_SetCompare3(TIM2,0);
TIM_SetCompare4(TIM2,0);
}
```
这样,你就可以使用STM32F103的PID调试助手来进行调试了。
#### 引用[.reference_title]
- *1* *2* [stm32f103基于pid的蓝牙循迹小车](https://blog.csdn.net/qq_51643989/article/details/130282315)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [【STM32】STM32F103C8T6实现直流电机速度PID控制](https://blog.csdn.net/qq_52785580/article/details/123002248)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文