匿名四軸上位機使用手冊_第1頁
匿名四軸上位機使用手冊_第2頁
匿名四軸上位機使用手冊_第3頁
匿名四軸上位機使用手冊_第4頁
匿名四軸上位機使用手冊_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

匿名四軸上位機使??冊匿名四軸上位機使??冊?錄1、串?功能軟件界?串?功能和串?助?等軟件功能類似,設置也差不多。1.設置接收格式、端?、波特率即可。2.打開基本收碼功能。3.打開串?。4.測試:2、?級收碼?級收碼設置選項卡:1.1-10對應0XA1-0XAA,我們只需要按定義幀設置即可,我這?使?0XA2,選擇2,并打開開關(guān)。2.因為我需要查看的有三個數(shù)據(jù),pitch,roll,yaw,并為float類型,所以如此設置。3.最后打開?級收碼功能,如果你需要實時查看上傳的數(shù)據(jù)可以打開收碼顯?。4.打開串?。5.測試:3、波形顯?波形顯?功能需要在?級收碼的功能上做修改。波形顯?設置選項卡如下:1.1-20序號對應的是波形序號,也就是說最多能指定顯?20個波形,我們這?有pitch,roll,yaw三個波形,所以設置1,2,3。2.設置第?個波形1,它來源于數(shù)據(jù)幀2的第?位。3.設置第?個波形2,它來源于數(shù)據(jù)幀2的第?位。4.設置第?個波形3,它來源于數(shù)據(jù)幀2的第三位。5.打開數(shù)據(jù)校驗,數(shù)據(jù)顯?。6.打開波形顯?。7.在波形顯?頁?勾上前三個即可:8.打開串?。9.測試:4、飛控狀態(tài)使?到此功能再補充。5、上傳數(shù)據(jù)的單?機程序以下為上傳三個?度的代碼,串?初始化等略過:voidusart1_send_char(u8c){while((USART1->SR&0X40)==0);//等待上?次發(fā)送完畢USART1->DR=c;}//fun:功能字.0XA0~0XAF//data:數(shù)據(jù)緩存區(qū),最多28字節(jié)!!//len:data區(qū)有效數(shù)據(jù)個數(shù)voidusart1_niming_report(u8fun,u8*data,u8len){u8send_buf[32];u8i;if(len>28)return;//最多28字節(jié)數(shù)據(jù)send_buf[len+3]=0;//校驗數(shù)置零send_buf[0]=0X88;//幀頭send_buf[1]=fun;//功能字send_buf[2]=len;//數(shù)據(jù)長度for(i=0;i<len;i++)send_buf[3+i]=data[i];//復制數(shù)據(jù)for(i=0;i<len+3;i++)send_buf[len+3]+=send_buf[i];//計算校驗和for(i=0;i<len+4;i++)usart1_send_char(send_buf[i]);//發(fā)送數(shù)據(jù)到串?1}voidmpu6050_send_data(floatpitch,floatroll,floatyaw){u8tbuf[16];unsignedchar*p;p=(unsignedchar*)&pitch;tbuf[0]=(unsignedchar)(*(p+3));tbuf[1]=(unsignedchar)(*(p+2));tbuf[2]=(unsignedchar)(*(p+1));tbuf[3]=(unsignedchar)(*(p+0));p=(unsignedchar*)&roll;tbuf[4]=(unsignedchar)(*(p+3));tbuf[5]=(unsignedchar)(*(p+2));tbuf[6]=(unsignedchar)(*(p+1));tbuf[7]=(unsignedchar)(*(p+0));p=(unsignedchar*)&yaw;tbuf[8]=(unsignedchar)(*(p+3));tbuf[9]=(unsignedchar)(*(p+2));tbuf[10]=(unsignedchar)(*(p+1));tbuf[11]=(unsignedchar)(*(p+0));usart1_niming_report(0XA2,tbuf,12);//?定義幀,0XA2}注意:最后?個函數(shù)把float拆成四個字節(jié)發(fā)送(由于串?只能?個字節(jié)?個字節(jié)的發(fā)送),?指針獲得float型變量的?地址,然后強制轉(zhuǎn)換為unsignedchar型,地址逐漸加?把float的四個字節(jié)分別發(fā)出即可。6、更多參考另外在個?的??機中使?如下:/**********************************************************************************?件名:main.c*描述:??機*實驗平臺:STM32開發(fā)板*庫版本:ST3.5.0*作者:零**********************************************************************************/#include"stm32f10x.h"#include"pwm_output.h"#include"key.h"#include"delay.h"#include"QDTFT_demo.h"#include"led.h"#include"Lcd_Driver.h"#include"mpu6050.h"#include"inv_mpu.h"#include"inv_mpu_dmp_motion_driver.h"#include"usart.h"#include"delay.h"#include"misc.h"#include"GUI.h"#include"pid_1.h"#include"math.h"#include"control.h"#include"string.h"#include"usmart.h"#include"stm32f10x_usart.h"/************************************************///串?1發(fā)送1個字符//c:要發(fā)送的字符voidusart1_send_char(u8c){while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);//循環(huán)發(fā)送,直到發(fā)送完畢USART_SendData(USART1,c);}/*//傳送數(shù)據(jù)給匿名四軸上位機軟件(V2.6版本)//fun:功能字.0XA0~0XAF//data:數(shù)據(jù)緩存區(qū),最多28字節(jié)!!//len:data區(qū)有效數(shù)據(jù)個數(shù)voidusart1_niming_report(u8fun,u8*data,u8len){u8send_buf[32];u8i;if(len>28)return;//最多28字節(jié)數(shù)據(jù)send_buf[len+3]=0;//校驗數(shù)置零send_buf[0]=0X88;//幀頭send_buf[1]=fun;//功能字send_buf[2]=len;//數(shù)據(jù)長度for(i=0;i<len;i++)send_buf[3+i]=data[i];//復制數(shù)據(jù)for(i=0;i<len+3;i++)send_buf[len+3]+=send_buf[i];//計算校驗和for(i=0;i<len+4;i++)usart1_send_char(send_buf[i]);//發(fā)送數(shù)據(jù)到串?1}//if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);//??定義幀發(fā)送加速度和陀螺儀原始數(shù)據(jù)//if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10));//發(fā)送加速度傳感器數(shù)據(jù)和陀螺儀數(shù)據(jù)//aacx,aacy,aacz:x,y,z三個向上?的加速度值向上?的陀螺儀值//gyrox,gyroy,gyroz:x,y,z三個voidmpu6050_send_data(shortaacx,shortaacy,shortaacz,shortgyrox,shortgyroy,shortgyroz){u8tbuf[12];tbuf[0]=(aacx>>8)&0XFF;tbuf[1]=aacx&0XFF;tbuf[2]=(aacy>>8)&0XFF;tbuf[3]=aacy&0XFF;tbuf[4]=(aacz>>8)&0XFF;tbuf[5]=aacz&0XFF;tbuf[6]=(gyrox>>8)&0XFF;tbuf[7]=gyrox&0XFF;tbuf[8]=(gyroy>>8)&0XFF;tbuf[9]=gyroy&0XFF;tbuf[10]=(gyroz>>8)&0XFF;tbuf[11]=gyroz&0XFF;usart1_niming_report(0XA1,tbuf,12);//?定義幀,0XA1}//通過串?1上報結(jié)算后的姿態(tài)數(shù)據(jù)給電腦//aacx,aacy,aacz:x,y,z三個向上?的加速度值向上?的陀螺儀值//gyrox,gyroy,gyroz:x,y,z三個//roll:橫滾?.單位0.01度。-18000->18000對應-180.00->180.00度//pitch:俯仰?.單位0.01度。-9000-9000對應-90.00->90.00度//yaw:航向?.單位為0.1度0->3600對應0->360.0度voidusart1_report_imu(shortaacx,shortaacy,shortaacz,shortgyrox,shortgyroy,shortgyroz,shortroll,shortpitch,shortyaw){u8tbuf[28];u8i;for(i=0;i<28;i++)tbuf[i]=0;//清0tbuf[0]=(aacx>>8)&0XFF;

tbuf[1]=aacx&0XFF;tbuf[2]=(aacy>>8)&0XFF;tbuf[3]=aacy&0XFF;tbuf[4]=(aacz>>8)&0XFF;tbuf[5]=aacz&0XFF;tbuf[6]=(gyrox>>8)&0XFF;tbuf[7]=gyrox&0XFF;tbuf[8]=(gyroy>>8)&0XFF;tbuf[9]=gyroy&0XFF;tbuf[10]=(gyroz>>8)&0XFF;tbuf[11]=gyroz&0XFF;tbuf[18]=(roll>>8)&0XFF;tbuf[19]=roll&0XFF;tbuf[20]=(pitch>>8)&0XFF;tbuf[21]=pitch&0XFF;tbuf[22]=(yaw>>8)&0XFF;tbuf[23]=yaw&0XFF;usart1_niming_report(0XAF,tbuf,28);//飛控顯?幀,0XAF}************************************************///fun:功能字.0XA0~0XAF//data:數(shù)據(jù)緩存區(qū),最多28字節(jié)!!//len:data區(qū)有效數(shù)據(jù)個數(shù)voidusart1_niming_report(u8fun,u8*data,u8len){u8send_buf[32];u8i;if(len>28)return;//最多28字節(jié)數(shù)據(jù)send_buf[len+3]=0;//校驗數(shù)置零send_buf[0]=0X88;//幀頭send_buf[1]=fun;//功能字send_buf[2]=len;//數(shù)據(jù)長度for(i=0;i<len;i++)send_buf[3+i]=data[i];//復制數(shù)據(jù)for(i=0;i<len+3;i++)send_buf[len+3]+=send_buf[i];//計算校驗和for(i=0;i<len+4;i++)usart1_send_char(send_buf[i]);//發(fā)送數(shù)據(jù)到串?1}voidmpu6050_send_data(floatpitch,floatroll,floatyaw){u8tbuf[16];unsignedchar*p;p=(unsignedchar*)&pitch;tbuf[0]=(unsignedchar)(*(p+3));tbuf[1]=(unsignedchar)(*(p+2));tbuf[2]=(unsignedchar)(*(p+1));tbuf[3]=(unsignedchar)(*(p+0));p=(unsignedchar*)&roll;tbuf[4]=(unsignedchar)(*(p+3));tbuf[5]=(unsignedchar)(*(p+2));tbuf[6]=(unsignedchar)(*(p+1));tbuf[7]=(unsignedchar)(*(p+0));p=(unsignedchar*)&yaw;tbuf[8]=(unsignedchar)(*(p+3));tbuf[9]=(unsignedchar)(*(p+2));tbuf[10]=(unsignedchar)(*(p+1));tbuf[11]=(unsignedchar)(*(p+0));usart1_niming_report(0XA2,tbuf,12);//?定義幀,0XA2}u16pwm1=2000,pwm2=2000,pwm3=2000,pwm4=2000;/************************************************//**函數(shù)名:main*描述:主函數(shù)*輸?:?*輸出:?*/intmain(void){u8report=1;//默認開啟上報u8res;u8test[20];u8temp_value[20];//存儲陀螺儀的臨時值u8temp_value2[20];//存儲pwm輸出的臨時值u8t=0;u8key;//按鍵值u8key_status=0;//按鍵狀態(tài)u8keystatus=0;//按鍵s4的狀態(tài)值floattemp;floatpitch,roll,yaw;//歐拉?shortaacx,aacy,aacz;//加速度傳感器原始數(shù)據(jù)shortgyrox,gyroy,gyroz;//陀螺儀原始數(shù)據(jù)intMotor1=0;//電機1輸出intMotor2=0;//電機2輸出intMotor3=0;//電機3輸出intMotor4=0;//電機4輸出floatPitch;floatRoll;floatYaw;PIDx_init();PIDy_init();PIDz_init();pitch_init();roll_init();yaw_init();NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應優(yōu)先級delay_init();

KEY_Init();uart_init(500000);//初始化串?usmart_dev.init(72);//初始化USMARTpwm_init();/*TIM3PWM波輸出初始化,并使能TIM3PWM輸出*/Lcd_Init();LCD_LED_SET;//通過IO控制背光亮Lcd_Clear(GRAY0);delay_ms(1000);MPU_Init();//初始化MPU6050Gui_DrawFont_GBK16(25,30,YELLOW,GRAY0,"Startcheck");while(mpu_dmp_init())Gui_DrawFont_GBK16(16,50,YELLOW,GRAY0,"MPU6050Error");Gui_DrawFont_GBK16(25,50,YELLOW,GRAY0,"MPU6050OK");Lcd_Clear(GRAY0);Gui_DrawFont_GBK16(25,30,YELLOW,GRAY0,"S3->shuju");Gui_DrawFont_GBK16(25,50,BLUE,GRAY0,"S4->PWM");while(1){if(keystatus!=1&&key!=2)key=KEY_Scan(0);//得到鍵值if(key){switch(key){caseKEY0_PRES://{Lcd_Clear(GRAY0);Gui_DrawFont_GBK16(25,30,YELLOW,GRAY0,"M1:");Gui_DrawFont_GBK16(25,50,BLUE,GRAY0,"M2:");Gui_DrawFont_GBK16(25,70,RED,GRAY0,"M3:");Gui_DrawFont_GBK16(25,90,BLUE,GRAY0,"M4:");while(1){key=KEY_Scan(1);if(key)switch(key){caseKEY1_PRES:key_status=1;break;}if(key_status==1)break;//有沒有更新值,有更新新的值就會繼續(xù)往下執(zhí)?if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0){/*MPU_Get_Accelerometer(&aacx,&aacy,&aacz);//得到加速度傳感器數(shù)據(jù)MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);//得到陀螺儀數(shù)據(jù)*/Pitch=PIDx_out_realize(pitch);Roll=PIDy_out_realize(roll);Yaw=PIDz_out_realize(yaw);//Pitch+=PIDx_inner_realize(pitch);//Roll+=PIDy_inner_realize(roll);//Yaw+=PIDz_inner_realize(yaw);//Motor1=(int)(2200-Pitch+Roll-Yaw);//Motor2=(int)(2200+Pitch+Roll+Yaw);//Motor3=(int)(2200+Pitch-Roll-Yaw);//Motor4=(int)(2200-Pitch-Roll+Yaw);Motor1=(int)(2500+Pitch-Roll);Motor2=(int)(2500+Pitch+Roll);Motor3=(int)(2500-Pitch+Roll);Motor4=(int)(2500-Pitch-Roll);//TIM_SetCompare1(TIM3,Motor4);////TIM_SetCompare2(TIM3,Motor1);////TIM_SetCompare3(TIM3,Motor2);////TIM_SetCompare4(TIM3,Motor3);//if(t%1==0){sprintf(temp_value2,"%4d",Motor4);Gui_DrawFont_GBK16(50,30,BLUE,GRAY0,temp_value2);sprintf(temp_value2,"%4d",Motor1);Gui_DrawFont_GBK16(50,50,BLUE,GRAY0,temp_value2);sprintf(temp_value2,"%4d",Motor2);Gui_DrawFont_GBK16(50,70,BLUE,GRAY0,temp_value2);sprintf(temp_value2,"%4d",Motor3);Gui_DrawFont_GBK16(50,90,BLUE,GRAY0,temp_value2);if(report)mpu6050_send_data(pitch,roll,yaw);//??定義幀發(fā)送加速度和陀螺儀原始數(shù)據(jù)//if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10));}}t++;}key_status=0;}caseKEY1_PRES://{keystatus=0;Lcd_Clear(GRAY0);Gui_DrawFont_GBK16(25,50,BLUE,GRAY0,"Pitch:.C");Gui_DrawFont_GBK16(25,70,RED,GRAY0,"Roll:.C");Gui_DrawFont_GBK16(25,90,BLUE,GRAY0,"Yaw:.C");while(1){key=KEY_Scan(0);if(key)switch(key){caseKEY0_PRES:key_status=1;break;}if(key_status==1)break;if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)

{//MPU_Get_Accelerometer(&aacx,&aacy,&aacz);//得到加速度傳感器數(shù)據(jù)//MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);//得到陀螺儀數(shù)據(jù)Pitch=PIDx_out_realize(pitch);Roll=PIDy_out_realize(roll);Yaw=PIDz_out_realize(yaw);//Pitch+=PIDx_inner_realize(pitch);//Roll+=PIDy_inner_realize(roll);//Yaw+=PIDz_inner_realize(yaw);//Motor1=(int)(2200-Pitch+Roll-Yaw);//Motor2=(int)(2200+Pitch+Roll+Yaw);//Motor3=(int)(2200+Pitch-Roll-Yaw);//Motor4=(int)(2200-Pitch-Roll+Yaw);Motor1=(int)(2500+Pitch-Roll);Motor2=(int)(2500+Pitch+Roll);Motor3=(int)(2500-Pitch+Roll);Motor4=(int)(2500-Pitch-Roll);//TIM_SetCompare1(TIM3,Motor4);////TIM_SetCompare2(TIM3,Motor1);////TIM_SetCompare3(TIM3,Motor2);////TIM_SetCompare4(TIM3,Motor3);//temp=pitch;if(temp<0)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論