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-08-02
- Revision:
- 1:107a7d8f4c54
- Parent:
- 0:00fcc71314cf
- Child:
- 2:74c543a0a671
File content as of revision 1:107a7d8f4c54:
#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,p12,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);
}
}