足回り動かすためのライブラリ
使用例
#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@6:87fd489a9801, 2021-10-21 (annotated)
- Committer:
- hamohamo
- Date:
- Thu Oct 21 16:16:01 2021 +0000
- Revision:
- 6:87fd489a9801
- Parent:
- 2:d88ff6dda390
- Child:
- 10:f434b6848059
lkn
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 | 2:d88ff6dda390 | 4 | #include "scrp_slave.hpp" |
hamohamo | 2:d88ff6dda390 | 5 | |
hamohamo | 0:0a9ce35078a3 | 6 | #include <vector> |
hamohamo | 0:0a9ce35078a3 | 7 | #include "mbed.h" |
hamohamo | 0:0a9ce35078a3 | 8 | #include "motor.hpp" |
hamohamo | 0:0a9ce35078a3 | 9 | #include "encoder.hpp" |
hamohamo | 0:0a9ce35078a3 | 10 | #include "pid.hpp" |
hamohamo | 0:0a9ce35078a3 | 11 | #include "robot.hpp" |
hamohamo | 0:0a9ce35078a3 | 12 | #include "position.hpp" |
hamohamo | 0:0a9ce35078a3 | 13 | |
hamohamo | 0:0a9ce35078a3 | 14 | #define OMNI4 1 |
hamohamo | 0:0a9ce35078a3 | 15 | #define OMNI3 2 |
hamohamo | 0:0a9ce35078a3 | 16 | #define MECANUM 3 |
hamohamo | 0:0a9ce35078a3 | 17 | |
hamohamo | 1:59244694c2bb | 18 | /*INFO |
hamohamo | 1:59244694c2bb | 19 | *Robot ROBOTNAME(四つ角のタイヤの半径(mm),計測輪の半径(mm),中心から角までの距離(mm),中心からフレームまでの距離(mm)); |
hamohamo | 1:59244694c2bb | 20 | *Core rbt(&ROBOTNAME,一周期の時間(s); |
hamohamo | 2:d88ff6dda390 | 21 | *rbt.addMOT(正転ピン,逆転ピン,2048,最大値,最小値,ID(0~3)); |
hamohamo | 1:59244694c2bb | 22 | *rbt.addENC(正転ピン,逆転ピン,分解能,モード(1~4),ID(0~7)); |
hamohamo | 2:d88ff6dda390 | 23 | *rbt.addPID(Kp,Ki,Kd,最大値,最小値,ID(0~7)); |
hamohamo | 1:59244694c2bb | 24 | *ROBOTNAME.setCWID(右前輪,右後輪,左後輪,左前輪のID); |
hamohamo | 1:59244694c2bb | 25 | *ROBOTNAME setSWID(前方,右方,後方,左方計測輪のID); |
hamohamo | 1:59244694c2bb | 26 | *IDは対応するもの同士で合わせてください |
hamohamo | 2:d88ff6dda390 | 27 | *addMOTやaddPIDのあとに->setLimit(max,min)をつけると値を制限できます |
hamohamo | 1:59244694c2bb | 28 | *rbt.START();ロボットの動作開始 |
hamohamo | 1:59244694c2bb | 29 | *rbt.LOOP();一周期の時間固定のため、ループの最後に書いてください |
hamohamo | 1:59244694c2bb | 30 | *rbt.WAIT(時間(us));ループ内の時間がその時間になるまで待機します |
hamohamo | 1:59244694c2bb | 31 | *rbt.setVelocity(速度のx成分,y成分,角速度); |
hamohamo | 1:59244694c2bb | 32 | *rbt.getStatus();ロボットの速度と位置を取得します |
hamohamo | 1:59244694c2bb | 33 | * |
hamohamo | 1:59244694c2bb | 34 | */ |
hamohamo | 1:59244694c2bb | 35 | |
hamohamo | 0:0a9ce35078a3 | 36 | class Core{ |
hamohamo | 0:0a9ce35078a3 | 37 | public: |
hamohamo | 0:0a9ce35078a3 | 38 | Core(Robot* robot,int mode,double dt); |
hamohamo | 2:d88ff6dda390 | 39 | Motor* addMOT(PinName plus,PinName minus,int period,int id); |
hamohamo | 0:0a9ce35078a3 | 40 | void addENC(PinName plus,PinName minus,int resolution,int mode,int id); |
hamohamo | 2:d88ff6dda390 | 41 | PID* addPID(double Kp,double Ki,double Kd,int id); |
hamohamo | 2:d88ff6dda390 | 42 | void setVelocity(double Vx,double Vy,double Vw); |
hamohamo | 2:d88ff6dda390 | 43 | void setPWM(double pwm,int id); |
hamohamo | 0:0a9ce35078a3 | 44 | void START(); |
hamohamo | 0:0a9ce35078a3 | 45 | bool LOOP(); |
hamohamo | 0:0a9ce35078a3 | 46 | void WAIT(double wt); |
hamohamo | 6:87fd489a9801 | 47 | Position getStatus(bool onground = true); |
hamohamo | 0:0a9ce35078a3 | 48 | Timer timer; |
hamohamo | 0:0a9ce35078a3 | 49 | Robot* rbt; |
hamohamo | 0:0a9ce35078a3 | 50 | std::vector<Motor*> Mots; |
hamohamo | 0:0a9ce35078a3 | 51 | std::vector<Encoder*> Encs; |
hamohamo | 0:0a9ce35078a3 | 52 | std::vector<PID*> PIDs; |
hamohamo | 2:d88ff6dda390 | 53 | ScrpSlave* scrp; |
hamohamo | 2:d88ff6dda390 | 54 | Core(Robot* robot,ScrpSlave* scrp,int mode,double dt); |
hamohamo | 2:d88ff6dda390 | 55 | void sendPWM(double pwm,int id); |
hamohamo | 2:d88ff6dda390 | 56 | void sendVelocity(double Vx,double Vy,double Vw); |
hamohamo | 2:d88ff6dda390 | 57 | void setPosition(double x,double y,double theta); |
hamohamo | 0:0a9ce35078a3 | 58 | private: |
hamohamo | 0:0a9ce35078a3 | 59 | int mode; |
hamohamo | 0:0a9ce35078a3 | 60 | double dt; |
hamohamo | 0:0a9ce35078a3 | 61 | unsigned long long t; |
hamohamo | 0:0a9ce35078a3 | 62 | Position pos,vel; |
hamohamo | 0:0a9ce35078a3 | 63 | }; |
hamohamo | 0:0a9ce35078a3 | 64 | |
hamohamo | 0:0a9ce35078a3 | 65 | #endif |