足回り動かすためのライブラリ
使用例
#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(); } }
core.hpp@0:0a9ce35078a3, 2021-09-21 (annotated)
- Committer:
- hamohamo
- Date:
- Tue Sep 21 06:16:58 2021 +0000
- Revision:
- 0:0a9ce35078a3
- Child:
- 1:59244694c2bb
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hamohamo | 0:0a9ce35078a3 | 1 | #ifndef take_core |
hamohamo | 0:0a9ce35078a3 | 2 | #define take_core |
hamohamo | 0:0a9ce35078a3 | 3 | |
hamohamo | 0:0a9ce35078a3 | 4 | #include <vector> |
hamohamo | 0:0a9ce35078a3 | 5 | #include "mbed.h" |
hamohamo | 0:0a9ce35078a3 | 6 | #include "motor.hpp" |
hamohamo | 0:0a9ce35078a3 | 7 | #include "encoder.hpp" |
hamohamo | 0:0a9ce35078a3 | 8 | #include "pid.hpp" |
hamohamo | 0:0a9ce35078a3 | 9 | #include "robot.hpp" |
hamohamo | 0:0a9ce35078a3 | 10 | #include "position.hpp" |
hamohamo | 0:0a9ce35078a3 | 11 | |
hamohamo | 0:0a9ce35078a3 | 12 | #define OMNI4 1 |
hamohamo | 0:0a9ce35078a3 | 13 | #define OMNI3 2 |
hamohamo | 0:0a9ce35078a3 | 14 | #define MECANUM 3 |
hamohamo | 0:0a9ce35078a3 | 15 | |
hamohamo | 0:0a9ce35078a3 | 16 | class Core{ |
hamohamo | 0:0a9ce35078a3 | 17 | public: |
hamohamo | 0:0a9ce35078a3 | 18 | Core(Robot* robot,int mode,double dt); |
hamohamo | 0:0a9ce35078a3 | 19 | void addMOT(PinName plus,PinName minus,int period,int id); |
hamohamo | 0:0a9ce35078a3 | 20 | void addENC(PinName plus,PinName minus,int resolution,int mode,int id); |
hamohamo | 0:0a9ce35078a3 | 21 | void addPID(double Kp,double Ki,double Kd,int id); |
hamohamo | 0:0a9ce35078a3 | 22 | void setLIM(double MOT_max,double MOT_min,double PID_max,double PID_min); |
hamohamo | 0:0a9ce35078a3 | 23 | void START(); |
hamohamo | 0:0a9ce35078a3 | 24 | bool LOOP(); |
hamohamo | 0:0a9ce35078a3 | 25 | void WAIT(double wt); |
hamohamo | 0:0a9ce35078a3 | 26 | void setVelocity(double Vx,double Vy,double Vw); |
hamohamo | 0:0a9ce35078a3 | 27 | Position getStatus(); |
hamohamo | 0:0a9ce35078a3 | 28 | Timer timer; |
hamohamo | 0:0a9ce35078a3 | 29 | Robot* rbt; |
hamohamo | 0:0a9ce35078a3 | 30 | std::vector<Motor*> Mots; |
hamohamo | 0:0a9ce35078a3 | 31 | std::vector<Encoder*> Encs; |
hamohamo | 0:0a9ce35078a3 | 32 | std::vector<PID*> PIDs; |
hamohamo | 0:0a9ce35078a3 | 33 | private: |
hamohamo | 0:0a9ce35078a3 | 34 | int mode; |
hamohamo | 0:0a9ce35078a3 | 35 | double dt; |
hamohamo | 0:0a9ce35078a3 | 36 | unsigned long long t; |
hamohamo | 0:0a9ce35078a3 | 37 | Position pos,vel; |
hamohamo | 0:0a9ce35078a3 | 38 | }; |
hamohamo | 0:0a9ce35078a3 | 39 | |
hamohamo | 0:0a9ce35078a3 | 40 | #endif |