2017ロボコンはやとブーメランプログラム

Dependencies:   PID QEI ikarashiMDC recieveController omni

main.cpp

Committer:
WAT34
Date:
2017-10-06
Revision:
16:5f205692b14d
Parent:
14:5cc44bec9cfc
Child:
17:311aed3cad15

File content as of revision 16:5f205692b14d:

#include "mbed.h"
#include "hayatoBoomerang.h"
#include "recieveController.h"
#include "omni.h"
#include "gakugaku.h"


Serial rs485(PC_10,PC_11,38400);
Serial serial(USBTX,USBRX);
PwmOut led(LED1);
DigitalIn button(BUTTON1);
boomerang boom(&rs485);
gakugaku fishingPole(&rs485);
recieveController con(PC_12,PD_2,198);

void init()
{
  button.mode(PullUp);

 serial.baud(115200);
  //boom.calibrateArm();
  boom.setTargetMotorSpeed(0);
}

int main() {
  init();
  int angle = 10,turnRate = 127;
  double angling;
  bool prevAnglechange = false,prevSwing=false;
  char data[20],*data2,*data3;
  // commThread.start(&comm);
  // ticker.attach(&updater,0.01);
  while(true)
  {
    if((con.buttons[0] >>7)%2 )
      boom.fire();

    if((con.buttons[0] >>8)%2)
      boom.setTargetMotorSpeed(13000);
    else
      boom.setTargetMotorSpeed(0);


    if((con.buttons[0]>>3)%2) //square
      angle = 80;
    if((con.buttons[0]>>4)%2) //cross
      angle = 45;
    if((con.buttons[0]>>5)%2) //circle
      angle = 25;
    if((con.buttons[0]>>6)%2) //triangle
      angle = 10;
    if((con.buttons[0]>>13)%2 )
    {
      if(!prevSwing)
        fishingPole.toggleSwing();
      prevSwing = true;
    }else{
      prevSwing = false;
    }
    if(con.buttons[3] < 117 )
    {
      if(!prevAnglechange)
        angle += 5;
      prevAnglechange =true;
    }else
    if(con.buttons[3] > 137)
    {
      if(!prevAnglechange)
        angle -= 5;
      prevAnglechange =true;
    }else{
      prevAnglechange =false;
    }
    if(angle < 5){
      angle = 5;
    }
    if(angle > 80 ){
      angle = 80;
    }

    if((con.buttons[0] >> 9)%2)
      turnRate = 127+127*.2; //turn at .2 power
    else if((con.buttons[0] >> 10)%2)
      turnRate = 127-127*.2;
    else
      turnRate = 127;

    if((con.buttons[0]>>14)%2)
      angling = 0.4;
    else if((con.buttons[0]>>12)%2)
      angling = -0.4;
    else
      angling = 0;
    fishingPole.setAnglingSpeed(angling);

    if((con.buttons[0]>>15)%2)
      fishingPole.Deploy();


    fishingPole.update();


    boom.setTargetArmAngle(angle);
    led = boom.beltSpeed;
    boom.move(con.buttons[1],con.buttons[2],turnRate);
    boom.update();

    serial.printf("controller:%d",con.buttons[0]);
    wait_ms(20);
     con.update();

  }

}