足回り動かすためのライブラリ
使用例
#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(); } }
NK_tuner.cpp@11:80800fd9f4af, 2021-10-29 (annotated)
- Committer:
- hamohamo
- Date:
- Fri Oct 29 09:20:31 2021 +0000
- Revision:
- 11:80800fd9f4af
- Parent:
- 6:87fd489a9801
asd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hamohamo | 6:87fd489a9801 | 1 | #include "NK_tuner.hpp" |
hamohamo | 6:87fd489a9801 | 2 | |
hamohamo | 6:87fd489a9801 | 3 | Nk_tuner::Nk_tuner(double dt,double finish):dt(dt),finish(finish){} |
hamohamo | 6:87fd489a9801 | 4 | Nk_tuner::~Nk_tuner(){} |
hamohamo | 6:87fd489a9801 | 5 | double Nk_tuner::getK(double Value){ |
hamohamo | 6:87fd489a9801 | 6 | n++; |
hamohamo | 6:87fd489a9801 | 7 | K = (K*(n-1) + Value)/n; |
hamohamo | 6:87fd489a9801 | 8 | return K; |
hamohamo | 6:87fd489a9801 | 9 | } |
hamohamo | 6:87fd489a9801 | 10 | void Nk_tuner::Update(double Value){ |
hamohamo | 6:87fd489a9801 | 11 | static double mt = 0.0,mtt = 0.0,mtv = 0.0; |
hamohamo | 6:87fd489a9801 | 12 | static double old,timer; |
hamohamo | 6:87fd489a9801 | 13 | double tilt; |
hamohamo | 6:87fd489a9801 | 14 | timer += dt; |
hamohamo | 6:87fd489a9801 | 15 | tilt = (Value - old) / dt; |
hamohamo | 6:87fd489a9801 | 16 | if(mt < tilt) { |
hamohamo | 6:87fd489a9801 | 17 | mt = tilt; |
hamohamo | 6:87fd489a9801 | 18 | mtt = timer; |
hamohamo | 6:87fd489a9801 | 19 | mtv = Value; |
hamohamo | 6:87fd489a9801 | 20 | } |
hamohamo | 6:87fd489a9801 | 21 | if(Value <= 0.632*K) T = timer; |
hamohamo | 6:87fd489a9801 | 22 | old = Value; |
hamohamo | 6:87fd489a9801 | 23 | if(timer >= finish){ |
hamohamo | 6:87fd489a9801 | 24 | L = mtt-(mtv/mt); |
hamohamo | 6:87fd489a9801 | 25 | T = T - L; |
hamohamo | 6:87fd489a9801 | 26 | old = 0.0; |
hamohamo | 6:87fd489a9801 | 27 | mt = 0.0; |
hamohamo | 6:87fd489a9801 | 28 | mtt = 0.0; |
hamohamo | 6:87fd489a9801 | 29 | mtv = 0.0; |
hamohamo | 6:87fd489a9801 | 30 | } |
hamohamo | 6:87fd489a9801 | 31 | } |