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:
- DeguNaoto
- Date:
- 2015-09-19
- Revision:
- 30:2923c6879e5f
- Parent:
- 29:03bb1ddbe456
- Child:
- 31:74e77ef0831c
File content as of revision 30:2923c6879e5f:
#ifndef AUTOMODE_H #define AUTOMODE_H /***PID Controller***/ PID velocity_controller(18.0,5274.0 ,0.0,RATE); PID direction_controller(18.0,5274.0,0.0,RATE); /***Ps3 correspondence***/ void autoPs3(){ if(up) targ_velocity=speed; else if(down) targ_velocity=-speed; else if(right) targ_velocity=0.0,targ_sita=0.0; else if(left) targ_velocity=0.0,targ_sita=PI/2.0; else if(r1) targ_sita=0.0; else if(l1) targ_sita=PI/2.0; else if(circle){ if(edge_circle) edge_circle=0,autoflag=0,Indicator4=0; } else if(cross){ 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(triangle){ if(edge_triangle){ edge_triangle=0; if(cylinderStep==3) cylinderStep=0; cylinderStep++; sendData(1, cylinderStep); } } } /***The function is PID controller initialize.***/ inline void initializeControllers() { velocity_controller.setInputLimits(-200000.0, 200000.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(); Vr = ( x1 + x2 ) / 2.0; Vl = ( x1 - x2 ) / 2.0; if( abs(Vr) < 0.05 ) Vr = 0.0; if( abs(Vl) < 0.05 ) Vl = 0.0; Move_r( ( float ) Vr ); Move_l( ( float ) Vl ); } #endif /*autoMode.h*/