PS3 version

Dependencies:   Motor_NIT_Nagaoka_College PID QEI SoftServo SoftPWM mbed DebounceIn

Fork of NHK2015 by mbedを用いた制御学生の制御

main.cpp

Committer:
WAT34
Date:
2015-07-31
Revision:
0:00fcc71314cf
Child:
1:107a7d8f4c54

File content as of revision 0:00fcc71314cf:

#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);
    }
}