![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
四轴
Dependencies: BufferedSerial SoftPWM mbed send
Fork of send_copy by
main.cpp
- Committer:
- accelerator225
- Date:
- 2017-11-08
- Revision:
- 4:876bfa91934c
- Parent:
- 3:61afd8d17063
- Child:
- 5:683542d82dd7
File content as of revision 4:876bfa91934c:
#include "mbed.h" #include "nRF24L01P.h" #include "SoftPWM.h" #define JY901transfersize 11 #define TRANSFER_SIZE 11 #include"JY901.h" #define pwm_period 1 int flagg = 0; char targetdata[3]; char receivedata[4]; float change[4]; int receivedatacnt = 0; SoftPWM PWM1(PA_2),PWM2(PA_3),PWM3(PA_6),PWM4(PA_7),PWM5(PB_0),PWM6(PB_1); int rollx=0,rolly=0,rollz=0,drx,dry,drz,ax,ay,az; float kp,ki,kd; void pwm_init() { PWM1.period_ms(pwm_period); PWM2.period_ms(pwm_period); PWM3.period_ms(pwm_period); PWM4.period_ms(pwm_period); PWM5.period_ms(pwm_period); PWM6.period_ms(pwm_period); PWM1=0.0;PWM2=0.0;PWM3=0.0;PWM4=0.0;PWM5=0.0;PWM6=0.0; } JY901 _JY901(PA_9,PA_10); //nRF24L01P my_nrf24l01p(PB_15, PB_14, PB_13, PC_1, PC_2, PC_0); char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; int JY901cnt = 0; int txDataCnt = 0; int rxDataCnt = 0; void transferdata(){ _JY901.receiveData(); float acc[3]; _JY901.getAttitude(acc[0], acc[1], acc[2]); PWM1=0.2;//0.13+0.13*(float)rollx/32767.0; PWM2=0.4;//0.13-0.13*(float)rolly/32767.0; PWM3=0.1-0.1*acc[0]/180; } int PIDcontrol(char *targetdata,char *data,float *change){ return 1; } void update_roll() { // char *s; /*char data[JY901transfersize]; char flag =0,flag2 = 0; int q=1; while(q < 1000){ q++; switch(flag){ case 0: flag2=JY901.getc(); if(flag2==0x55) flag++; break; case 1: flag2=JY901.getc(); if(flag2 == 0x53){ flag++; data[0] = 0x55; data[1] = flag2; } else flag--; break; case 2: for(int i = 2;i != JY901transfersize;i++) data[i] = JY901.getc(); q = 1001; break; } }*/ // rollx+=drx; // rolly+=dry; //rollz+=drz; // sprintf(s,"%f",rollx*180/32767); // my_nrf24l01p.write( NRF24L01P_PIPE_P0,s,11); } int main() { // my_nrf24l01p.powerUp(); // my_nrf24l01p.setTransferSize( 11); // my_nrf24l01p.setReceiveMode(); // my_nrf24l01p.enable(); Ticker time; time.attach(&transferdata,0.1); while(1){ // pc.printf("succes"); } }