欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
基于stm32的萬向車源程序
[打印本頁]
作者:
zly990828
時間:
2019-8-2 10:35
標題:
基于stm32的萬向車源程序
#include "stm32f10x.h" // 相當于51單片機中的 #include <reg51.h>
#include "bsp_moto.h"
#include "./key/bsp_key.h"
#include "bsp_SysTick.h"
#include "exti.h"
#include "filter.h"
#include "MPU6050.h"
#include "IOI2C.h"
#include "bsp_usart.h"
#include "delay.h"
#include "bsp_servo.h"
#include "bsp_dma.h"
long int Target_A,Target_B,Target_C; //電機目標值
long int Motor_A,Motor_B,Motor_C; //電機PWM變量
int Vx,Vy,Vz; //車子三輪的速度
float GYROA=0.004;
float Pitch,Roll,Yaw,Move_X,Move_Y,Move_Z; //三軸角度和XYZ軸目標速度 3200
int time; //小車轉度數計時變量
int control_flag=0; //小車的行駛4個狀態的控制量
int mode_flag=1; // 小車模式的控制量,1為自動,0為手動
char position ='0'; //小車當前的狀態。
//小車忙不忙,如果小車在運動,上位機第四部分禁止發數據,只有小車空閑時,上位機第四部分才能給我發數據,
// 用字符‘1’代表忙,字符‘0’代表空閑.
char commend[11]={'\0'}; //接受手動命令的數組
/*手動控制關閉,前進,后退,順時針轉90度,逆時針轉90度,順時針轉,逆時針轉*/
int off=0,forward=0,backward=0,clockwise_90=0,anticlockwise_90=0,clockwise=0,anticlockwise=0;
char send_data[63]={'\0'}; //發送數據的數組
double frequency_B,count_B,sum_B=0;
//char wifi_flag=0;
void Start_to_A(void);
void A_to_Start(void);
void Start_A_B(void);
void Start_A_B_C(void);
int main(void)
{
led_GPIO_Config(); //自動模式時,燈會亮;手動模式時,燈熄滅
led(0);
Key_GPIO_Config();
while(!Key_Scan());
wifi_Config(); //wifi初始化,配置中斷優先級為0
// USART1_Config();
Servo_Init();//舵機初始化
Servo_heng(); //不管舵機現在是什么狀態,一律變為水平狀態
moto_init(); //電機初始化,剛初始化電機完,電機不能轉動,失能電機
IIC_Init(); //=====IIC初始化,為MPU6050傳輸數據做準備
MPU6050_initialize(); //=====MPU6050初始化
DMP_Init(); //=====初始化DMP
delay_ms(1000); //=====延時等待DMP初始化穩定
/************一上電為了后面數據的準確性,需要給出Z軸角速度的準確值,大概需要7-8秒*******/
Read_DMP();
delay_ms(5);
Read_DMP();
delay_ms(5);
while(gyro[2]!=0)
{
Read_DMP();
delay_ms(5);
}
/**************************************************************************************/
GENERAL_TIM7_Init(); //以100ms的速度給上位機發送小車的運動參數,配置中斷優先級為10
GENERAL_TIM4_Init(); //以5ms一次中斷控制小車運動 ,初始化時不開啟,配置中斷優先級為15
// 使能計數器TIM_Cmd(GENERAL_TIM4, ENABLE);
GENERAL_TIM6_Init();//,配置中斷優先級為5
led(1);
//printf("init ok!!!\n");
//wifi_flag=1;
wifi_NVIC_Configuration(); // wifi4中斷優先級配置
USART_ITConfig(DEBUG_USART4, USART_IT_RXNE, ENABLE); // wifi串口接收中斷使能
while(1)
{
switch(control_flag)
{
case 1 : Start_to_A(); break;
case 2 : A_to_Start(); break;
case 3 : Start_A_B(); break;
case 4 : Start_A_B_C(); break;
case 5 : turn_angle(1);control_flag=0; break;//順時針90度
case 6 : turn_angle(0);control_flag=0; break;
default: ; break;
}
}
}
void Start_to_A(void)
{
delay_ms(1);
position='1'; //小車忙
Servo_shu(); //頂貨物 ,有延時
motoEN(1);//使能電機
car_speed(0,600,0); //小車速度
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
Servo_heng(); //放貨物
car_speed(0,-600,0); //小車速度
control_flag=1;
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
motoEN(0);
control_flag=0;
position='0';//小車不忙
}
void A_to_Start(void)
{
motoEN(1);//使能電機
delay_ms(1);
position='1'; //小車忙
car_speed(0,600,0); //小車速度
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
Servo_shu();
car_speed(0,-600,0); //小車速度
control_flag=2;
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
Servo_heng();
motoEN(0);
control_flag=0;
position='0';//小車不忙
}
void Start_A_B(void)
{
motoEN(1);//使能電機
delay_ms(1);
position='1'; //小車忙
car_speed(0,600,0); //小車速度
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
Servo_shu();
turn_angle(1);//順時針90度
delay_ms(500);
control_flag=3;
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
Servo_heng();
car_speed(0,-600,0); //小車速度
control_flag=3;
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
turn_angle(0);//逆時針90度
delay_ms(500);
control_flag=3;
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
motoEN(0);
control_flag=0;
position='0';//小車不忙
}
void Start_A_B_C(void)
{
motoEN(1);//使能電機
delay_ms(1);
position='1'; //小車忙
car_speed(0,600,0); //小車速度
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
turn_angle(1);//順時針90度
delay_ms(500);
control_flag=4;
TIM_Cmd(GENERAL_TIM4, ENABLE); //使能計數器,讓小車開始運動
while(control_flag); // 等待小車跑完
delay_ms(500);
Servo_shu();
turn_angle(1);//順時針90度
delay_ms(500);
control_flag=4;
TIM_Cmd(GENERAL_TIM4, ENABLE);
while(control_flag); // 等待小車跑完
delay_ms(500);
turn_angle(1);//順時針90度
delay_ms(500);
control_flag=4;
TIM_Cmd(GENERAL_TIM4, ENABLE);
while(control_flag); // 等待小車跑完
delay_ms(500);
turn_angle(1);//順時針90度
Servo_heng();
motoEN(0);
control_flag=0;
position='0';//小車不忙
}
復制代碼
全部程序51hei下載地址:
萬向車.7z
(252.23 KB, 下載次數: 5)
2019-8-2 17:01 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時間:
2019-8-2 17:01
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1