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.
Fork of 2015robot_main by
main_ps3.cpp
- Committer:
- DeguNaoto
- Date:
- 2015-09-29
- Revision:
- 56:ac01d6b46291
- Parent:
- 55:db1797ac6cb1
- Child:
- 57:3fbd487e055e
File content as of revision 56:ac01d6b46291:
/**
* This program is written in main micro computer "mbed" for 2015 NHK Robot Contest (Bteam).
*/
//速度コントローラと向きコントローラはそのまま
#define BLUE
//#define RED
#if defined(BLUE) && defined(RED)
#error Caution, You should define either BLUE or RED
#endif
#include "machine_ps3.h"
Serial pc(USBTX, USBRX);
//LocalFileSystem local("local");
int main()
{
initializeIM920();
initializeMotors();
initializeControllers();
initializeSwing();
#ifdef BLUE
sita=PI/4.0,targ_sita=PI/4.0;
IndicatorBLUE = 1;
#else
sita=-PI/4.0,targ_sita=-PI/4.0;
IndicatorRED = 1;
#endif
Indicator4=1;
Enable=1;
// FILE *fp_r = fopen("/local/velocity.dat", "w");
sendData(4,31);
wait(0.1);
sendData(5,31);
wait(0.1);
// double time=0.0;
while(1) {
if(autoflag){
autoIM920(); /*IM920 button*/
#ifdef BLUE
//Blue
if((step==0)&&((8650.0>x)&&(x>1400.0))) targ_sita=0.0,step=1;
if((step==1)&&(x>8650.0)) targ_velocity=-speed,step=2;
if((step==2)&&(x<2000.0)) targ_sita=PI/4,step=3;
if((step==3)&&(x<10.0)) targ_velocity=0.0,step=4;
if((x>3344.0)&&(CStep==1)) CStep=2,sendData(1,1);
if((x>6234.0)&&(CStep==2)) CStep=3,sendData(1,2);
if((x>7885.0)&&(CStep==3)) CStep=4,sendData(1,3);
// if((x<6700.0)&&(CStep==4)) CStep=5,sendData(1,5);
if((x<6750.0)&&(CStep==4)) CStep=5,sendData(1,5);
if((x<6300.0)&&(CStep==5)) CStep=6,sendData(1,4);
#else
//Red
if((step==0)&&((8650.0>x)&&(x>1400.0))) targ_sita=0.0,step=1;
if((step==1)&&(x>8650.0)) targ_velocity=-speed,step=2;
if((step==2)&&(x<2000.0)) targ_sita=-PI/4,step=3;
if((step==3)&&(x<10.0)) targ_velocity=0.0,step=4;
if((x>3344.0)&&(CStep==1)) CStep=2,sendData(1,1);
if((x>6234.0)&&(CStep==2)) CStep=3,sendData(1,3);
if((x>7885.0)&&(CStep==3)) CStep=4,sendData(1,2);
if((x<6700.0)&&(CStep==4)) CStep=5,sendData(1,4);
if((x<6300.0)&&(CStep==5)) CStep=6,sendData(1,5);
#endif
move_following();
}
else if(!autoflag) {
manualMoveIM920(); /*analogStick*/
manualIM920(); /*IM920 button*/
//Swing
swingFollowing();
/*if(square){
IndicatorAuto=0;
fclose(fp_r);
}
fprintf(fp_r, "time:%1.3f, %f[rad/s], pwm:%f\r\n",time,swingRadVelocity,cont);
time+=0.01;*/
}
/***update state***/
readIM920();
mesure_state();
mesureSwing();
wait(RATE);
// pc.printf("sita:%f, x:%f, y:%f ,x1:%f, x2:%f ,velocity:%f\r\n",sita,x,y,x1,x2,velocity);
// pc.printf("A2 = %d, X = %d, Y = %d, B = %d, dead = %d\r\n", a2, X, Y, b, deadflag);
pc.printf("%f %f\r\n",cont,swingRadVelocity);
}
}

