Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Motor_NIT_Nagaoka_College PID Servo QEI SoftPWM mbed HBridge
main.cpp
- Committer:
- WAT34
- Date:
- 2015-09-15
- Revision:
- 9:98ef1eee7ace
- Parent:
- 8:9d8999740604
File content as of revision 9:98ef1eee7ace:
#define pi 3.141593 #include "mbed.h" #include "Motor.h" #include "PID.h" #include "QEI.h" #include "Servo.h" #define RATE 0.05 BusOut air(PC_10,PC_11); DigitalOut out(PC_12); Serial conn(PA_15,PB_7); Serial pc(USBTX,USBRX); Serial nara(PA_2,PA_3); PID Tp(50,40000,0,0.001); BusOut led(LED1,LED2,LED3,LED4); Motor ot(PB_13,PB_3,PA_10); Motor pak(PB_14,PB_4,PA_11); Motor sup1(PB_15,PB_10,PB_4); Motor sup2(PA_11,PA_6,PA_7); QEI sensort(PC_3,PC_0,NC,624); Servo L(PC_9); Servo R(PC_8); BusIn limits(PB_8,PB_9); Timeout ai; Timeout yanagi; char read ,yayaya = 0; int Rs = 0,Ls = 0; int i = 0; void zero(){ air = 0; i = 0; out = 1; } void rev(){ air = 2; ai.attach(&zero,1.0); out = 0; } void pakri(){ yayaya = 2; } int main() { ot.setfrequency(60000); double tilt = 0,lo = 0,ro = 0; int8_t ttilt = 0,tmpread = 0,tmpttilt = 0; char tro = 0,tlo = 0; Tp.setInputLimits(-45,45); Tp.setOutputLimits(-0.9,0.9); Tp.setMode(1); Tp.setBias(0.0); while(1) { if(conn.getc() == 255) { tmpread = conn.getc(); tmpttilt = conn.getc(); tro = conn.getc(); tlo = conn.getc(); if(tmpread^tmpttilt^tro^tlo == conn.getc()){ ttilt = tmpttilt; read = tmpread; ro = (tro-127)/127.0*0.9; lo = (tlo-127)/127.0*0.9; } } if(read%2){ //yanagi shoot. yanagi.attach(&pakri,3.0); yayaya = 1; } if((read>>2)%2 && i == 0){ air = 1; ai.attach(&rev,1.0); i = 1; } /* yanagi controll */ if (yayaya == 1 && limits != 2) { pak.speed(1); }else if (yayaya == 2 && limits !=1) { pak.speed(-1); }else { pak.speed(0); } /* 射角調整 */ Tp.setSetPoint(ttilt); tilt = double(sensort.getPulses()); tilt = tilt*61/5128.0; Tp.setProcessValue(tilt); if (abs(lo) < 0.1){ lo = 0; } if (abs(ro) < 0.1){ ro = 0; } L.write((lo+1.0)/2.0); R.write((ro+1.0)/2.0); ot.speed(Tp.compute()); //pc.printf("%f %d\n\r",Tp.compute(),read); //pc.printf("%d-%d\r\n",tlo,tro); wait_ms(1); } }