足回り動かすためのライブラリ
使用例
#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(); } }
imc.cpp@11:80800fd9f4af, 2021-10-29 (annotated)
- Committer:
- hamohamo
- Date:
- Fri Oct 29 09:20:31 2021 +0000
- Revision:
- 11:80800fd9f4af
- Parent:
- 10:f434b6848059
asd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hamohamo | 10:f434b6848059 | 1 | #include "imc.hpp" |
hamohamo | 10:f434b6848059 | 2 | #include "mbed.h" |
hamohamo | 10:f434b6848059 | 3 | IMC::IMC(double K,double T,int id):K(K),T(T),ID(id){ |
hamohamo | 10:f434b6848059 | 4 | x = 0.0; |
hamohamo | 10:f434b6848059 | 5 | mv = 0.0; |
hamohamo | 10:f434b6848059 | 6 | } |
hamohamo | 10:f434b6848059 | 7 | double IMC::simulate(double x,double u,double dt){ |
hamohamo | 10:f434b6848059 | 8 | this->x = x + (-x + K*u)/T*dt; |
hamohamo | 10:f434b6848059 | 9 | return this->x; |
hamohamo | 10:f434b6848059 | 10 | } |
hamohamo | 10:f434b6848059 | 11 | void IMC::Update(double Value,double Target,double dt){ |
hamohamo | 10:f434b6848059 | 12 | mv = (Target - Value + simulate(x,mv,dt))*(1.0/K); |
hamohamo | 11:80800fd9f4af | 13 | |
hamohamo | 11:80800fd9f4af | 14 | if(Target == 0.0) mv = 0.0; |
hamohamo | 10:f434b6848059 | 15 | if(mv<Min) mv = Min; |
hamohamo | 10:f434b6848059 | 16 | if(mv>Max) mv = Max; |
hamohamo | 10:f434b6848059 | 17 | } |
hamohamo | 10:f434b6848059 | 18 | double IMC::getmv(){ |
hamohamo | 10:f434b6848059 | 19 | return mv; |
hamohamo | 10:f434b6848059 | 20 | } |
hamohamo | 10:f434b6848059 | 21 | double IMC::getx(){ |
hamohamo | 10:f434b6848059 | 22 | return x; |
hamohamo | 10:f434b6848059 | 23 | } |
hamohamo | 10:f434b6848059 | 24 | void IMC::setLimit(double max,double min){ |
hamohamo | 10:f434b6848059 | 25 | Max = max; |
hamohamo | 10:f434b6848059 | 26 | Min = min; |
hamohamo | 10:f434b6848059 | 27 | } |
hamohamo | 10:f434b6848059 | 28 | IMC::~IMC(){} |