足回り動かすためのライブラリ
使用例
#include "scrp_slave.hpp" #include "core.hpp" #include "mbed.h" ScrpSlave sendpwm(PC_12,PD_2 ,PH_1 ,SERIAL_TX,SERIAL_RX,0x0807f800); Robot AKASHIKOSEN(50.8,25.4,322.5,259.75); Core RBT(&AKASHIKOSEN,OMNI4,0.02); int main(){ /*--------------SETUP--------------*/ AKASHIKOSEN.setCWID(0,1,2,3); AKASHIKOSEN.setSWID(4,5,6,7); RBT.addENC(PC_4,PA_13,512,4,0); RBT.addENC(PA_14,PA_15,512,4,1); RBT.addENC(PC_2,PC_3,512,4,2); RBT.addENC(PC_10,PC_11,512,4,3); RBT.addENC(PA_7,PA_6,512,4,4); RBT.addENC(PA_9,PA_8,512,4,5); RBT.addENC(PC_1,PC_0,512,4,6); RBT.addENC(PC_5,PA_12,512,4,7); RBT.START(); /*--------------LOOP--------------*/ Position pos; while(true){ pos = RBT.getStatus(); printf("x:%lf,y:%lf,theta:%lf\n",pos.x,pos.y,pos.theta); RBT.LOOP(); } }
pid.hpp@5:8dec5e011b3c, 2021-10-18 (annotated)
- Committer:
- hamohamo
- Date:
- Mon Oct 18 08:15:39 2021 +0000
- Revision:
- 5:8dec5e011b3c
- Parent:
- 2:d88ff6dda390
- Child:
- 6:87fd489a9801
hkh;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hamohamo | 0:0a9ce35078a3 | 1 | #ifndef take_PID |
hamohamo | 0:0a9ce35078a3 | 2 | #define take_PID |
hamohamo | 0:0a9ce35078a3 | 3 | |
hamohamo | 0:0a9ce35078a3 | 4 | #ifndef M_PI |
hamohamo | 0:0a9ce35078a3 | 5 | #define M_PI 3.14159265358979 |
hamohamo | 0:0a9ce35078a3 | 6 | #endif |
hamohamo | 1:59244694c2bb | 7 | /*INFO |
hamohamo | 1:59244694c2bb | 8 | *coreを使わない場合idはなんでもいいです |
hamohamo | 1:59244694c2bb | 9 | *UpdateのValueには現在値、ターゲットには目標値、dtには微分する時間を入れてください |
hamohamo | 5:8dec5e011b3c | 10 | *getmvで操作量を含んだ結果を取得できます |
hamohamo | 1:59244694c2bb | 11 | * |
hamohamo | 1:59244694c2bb | 12 | */ |
hamohamo | 0:0a9ce35078a3 | 13 | class PID{ |
hamohamo | 0:0a9ce35078a3 | 14 | public: |
hamohamo | 0:0a9ce35078a3 | 15 | PID(double kp,double ki,double kd,int id); |
hamohamo | 0:0a9ce35078a3 | 16 | ~PID(); |
hamohamo | 2:d88ff6dda390 | 17 | void setLimit(double max,double min); |
hamohamo | 0:0a9ce35078a3 | 18 | void Update(double Value,double Target,double dt); |
hamohamo | 5:8dec5e011b3c | 19 | double getmv(); |
hamohamo | 5:8dec5e011b3c | 20 | double mv; |
hamohamo | 0:0a9ce35078a3 | 21 | double value; |
hamohamo | 0:0a9ce35078a3 | 22 | double target; |
hamohamo | 5:8dec5e011b3c | 23 | double e[3]; |
hamohamo | 2:d88ff6dda390 | 24 | double Max; |
hamohamo | 0:0a9ce35078a3 | 25 | private: |
hamohamo | 2:d88ff6dda390 | 26 | double Min; |
hamohamo | 0:0a9ce35078a3 | 27 | double Kp; |
hamohamo | 0:0a9ce35078a3 | 28 | double Ki; |
hamohamo | 0:0a9ce35078a3 | 29 | double Kd; |
hamohamo | 0:0a9ce35078a3 | 30 | double P; |
hamohamo | 0:0a9ce35078a3 | 31 | double I; |
hamohamo | 0:0a9ce35078a3 | 32 | double D; |
hamohamo | 0:0a9ce35078a3 | 33 | double integral; |
hamohamo | 0:0a9ce35078a3 | 34 | int ID; |
hamohamo | 0:0a9ce35078a3 | 35 | }; |
hamohamo | 0:0a9ce35078a3 | 36 | |
hamohamo | 0:0a9ce35078a3 | 37 | #endif |