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
autoMode.h
- Committer:
- unicore32
- Date:
- 2015-10-08
- Revision:
- 68:2b2b88ecdcce
- Parent:
- 66:14df82661dfa
- Child:
- 69:bf094811b4a9
File content as of revision 68:2b2b88ecdcce:
#ifndef AUTOMODE_H #define AUTOMODE_H /***PID Controller***/ //PID velocity_controller(36.0,5274.0 ,0.0,RATE); //PID direction_controller(36.0,3.0,0.0,RATE); PID velocity_controller(9.0,5274.0 ,0.0,RATE); PID direction_controller(36.0,3.0,0.0,RATE); #ifdef IM920 /***IM920 correspondence***/ void autoIM920() { if(b==7){ /*mode change*/ if(edge7){ edge7=0; autoflag=0; Indicator4=0; IndicatorAuto=1; } } else if(b==6){ /*start*/ flagf=1; targ_velocity=speed; sendData(7,defoR); stateR = defoR; stateL = defoL; step = 0; CMode = 0; } else if(b==8){ /*middle start*/ flagf=1; targ_velocity=speed; sendData(7,57); stateR = 17; stateL = 17; step = 4; CMode = 6; } else if(b==5){ /*reset*/ sendData(7,255); } else if(b==9){ /*stop*/ Motor_swing=0; sita=PI/4.0,x=0.0,y=0.0; targ_velocity=0.0; targ_sita=PI/4.0; velocity_controller.reset(); direction_controller.reset(); } else if(b==1){ /*L down*/ if(edge1){ edge1=0; if(stateL!=1) stateL--; sendData(4,stateL); } } else if(b==2){ /*L up*/ if(edge2){ edge2=0; if(stateL!=28) stateL++; sendData(4,stateL); } } else if(b==3){ /*R down*/ if(edge3){ edge3=0; if(stateR!=1) stateR--; sendData(5,stateR); } } else if(b==4){ /*R up*/ if(edge4){ edge4=0; if(stateR!=28) stateR++; sendData(5,stateR); } } if(b!=7) edge7=1; if(b!=1) edge1=1; if(b!=2) edge2=1; if(b!=3) edge3=1; if(b!=4) edge4=1; } #else void autoPS3(){ if(circle){ /*mode change*/ if(edge_circle){ edge_circle=0; autoflag=0; Indicator4=0; IndicatorAuto=1; } } else if(up){ /*start*/ flagf=1; targ_velocity=speed; sendData(7,defoR); stateR = defoR; stateL = defoL; step = 0; CStep = 1; } else if(right){ /*middle start*/ flagf = 1; targ_velocity=speed; sendData(7,57); stateR = 17; stateL = 17; step = 4; CStep = 6; } else if(square){ /*reset*/ sendData(7,255); } else if(triangle){ /*set defo*/ sendData(7,defoR); } else if(cross){ /*stop*/ Motor_swing=0; // sita=PI/4.0,x=0.0,y=0.0; targ_velocity=0.0; targ_sita=PI/4.0; velocity_controller.reset(); direction_controller.reset(); } else if(l1){ /*L up*/ if(edge_l1){ edge_l1=0; if(stateL!=1) stateL--; sendData(4,stateL); } } else if(l2){ /*L down*/ if(edge_l2){ edge_l2=0; if(stateL!=28) stateL++; sendData(4,stateL); } } else if(r1){ /*R up*/ if(edge_r1){ edge_r1=0; if(stateR!=1) stateR--; sendData(5,stateR); } } else if(r2){ /*R down*/ if(edge_r2){ edge_r2=0; if(stateR!=28) stateR++; sendData(5,stateR); } } } #endif /***The function is PID controller initialize.***/ inline void initializeControllers() { // velocity_controller.setInputLimits(-200000.0, 200000.0); //x1 velocity_controller.setInputLimits(-20000.0, 20000.0); //x1 direction_controller.setInputLimits(-10.0, 10.0); //x2 //Pwm output from MOVE_OUTPUT_LIMIT_BOTTOM to MOVE_OUTPUT_LIMIT_TOP velocity_controller.setOutputLimits(-1.0, 1.0); direction_controller.setOutputLimits(-1.0, 1.0); //set bias. 初期値 velocity_controller.setBias(0.0); direction_controller.setBias(0.0); //set mode. velocity_controller.setMode(AUTO_MODE); direction_controller.setMode(AUTO_MODE); } /***The function is following move speed.***/ inline void velocity_following() { velocity_controller.setSetPoint((float)targ_velocity); velocity_controller.setProcessValue((float)velocity); x1 = (double)velocity_controller.compute(); } inline void sita_following() { direction_controller.setSetPoint((float)targ_sita); direction_controller.setProcessValue((float)sita); //direction_controller.setSetPoint(0.0); /*目標値とのずれをなくす*/ //direction_controller.setProcessValue(-y); x2 = (double)direction_controller.compute(); } inline void move_following() { velocity_following(); sita_following(); if(flagf==0){ Vr = ( x1 + x2 ) / 2.0; Vl = ( x1 - x2 ) / 2.0; } else if(flagf==1){ if(x2>0){ Vr = x1; Vl = x1 - x2; } else{ Vr = x1 + x2; Vl = x1; } } if( abs(Vr) < 0.2 ) Vr = 0.0; if( abs(Vl) < 0.2 ) Vl = 0.0; Move_r( ( float ) Vr ); Move_l( ( float ) Vl ); } #endif /*autoMode.h*/