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
Diff: main.cpp
- Revision:
- 0:00fcc71314cf
- Child:
- 1:107a7d8f4c54
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jul 31 13:42:06 2015 +0000 @@ -0,0 +1,53 @@ +#define pi 3.141592 +#include "mbed.h" +#include "rtos.h" +#include "QEI.h" +#include "Motor.h" +#include "HMC6352.h" +BusOut air(p15,p16); +Serial conn(p29,p28); +BusOut mypaul(p17,p18); +Motor od(p21,p19,p20); +Motor ot(p22,p10,p11); +QEI sensort(p5,p6,NC,720); +HMC6352 sensord(p9,p10); +char read; +void serial_thread(void const *argument) +{ + while(1) { + if(conn.readable()) { + read = conn.getc(); + } + } +} +int main() +{ + sensord.setOpMode(HMC6352_CONTINUOUS,1,20); + Thread thread(serial_thread); + double direct,tilt,cdirect,adirect,atilt,tdirect,ttilt; + adirect = sensord.sample()/10.0; + sensort.reset(); + while(1) { + air = read%4; + mypaul = (read>>2)%4; + if((read>>4)%2) { + tdirect++; + } + if((read>>5)%2) { + tdirect--; + } + if((read>>6)%2) { + ttilt++; + } + if((read>>7)%2) { + ttilt--; + } + cdirect = sensord.sample()/10.0; + direct = cdirect+540-adirect; + direct = int(direct+0.5)%360; + direct -= 180; + tilt = sensort.getPulses()/360.0*2/25.0*pi; + od.speed(tdirect-direct); + ot.speed(ttilt-tilt); + } +}