足回り動かすためのライブラリ

使用例

#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();
}
}
Committer:
hamohamo
Date:
Fri Oct 29 09:20:31 2021 +0000
Revision:
11:80800fd9f4af
Parent:
6:87fd489a9801
asd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hamohamo 0:0a9ce35078a3 1 #include "pid.hpp"
hamohamo 2:d88ff6dda390 2 #include "mbed.h"
hamohamo 0:0a9ce35078a3 3 PID::PID(double kp,double ki,double kd,int id):Kp(kp),Ki(ki),Kd(kd),ID(id){
hamohamo 6:87fd489a9801 4 e[0]=0.0;
hamohamo 5:8dec5e011b3c 5 mv = 0.0;
hamohamo 2:d88ff6dda390 6 integral = 0.0;
hamohamo 0:0a9ce35078a3 7 }
hamohamo 6:87fd489a9801 8 void PID::Update(double Value,double Target,double dt,bool addmv){/*
hamohamo 5:8dec5e011b3c 9 e[2]=Target-Value;
hamohamo 5:8dec5e011b3c 10 P=(e[2]-e[1])/dt;
hamohamo 5:8dec5e011b3c 11 I= e[2];
hamohamo 6:87fd489a9801 12 D=(e[2]- 2*e[1] + e[0])/dt/dt;
hamohamo 5:8dec5e011b3c 13 e[0] = e[1];
hamohamo 5:8dec5e011b3c 14 e[1] = e[2];
hamohamo 6:87fd489a9801 15 integral += ((Kp*P)+(Ki*I)+(Kd*D))*dt;
hamohamo 6:87fd489a9801 16 mv += integral;*/
hamohamo 6:87fd489a9801 17 e[2] = Target - Value;
hamohamo 6:87fd489a9801 18 P = e[2];
hamohamo 6:87fd489a9801 19 integral += (e[2]+e[1])*dt/2.0;
hamohamo 6:87fd489a9801 20 I = integral;
hamohamo 6:87fd489a9801 21 D = (e[2]-e[1])/dt;
hamohamo 6:87fd489a9801 22 if(addmv) mv += ((Kp*P)+(Ki*I)+(Kd*D));
hamohamo 6:87fd489a9801 23 else mv = ((Kp*P)+(Ki*I)+(Kd*D));
hamohamo 6:87fd489a9801 24 e[1] = e[2];
hamohamo 11:80800fd9f4af 25 if(Target == 0.0) mv = 0.0;
hamohamo 5:8dec5e011b3c 26 if(mv<Min) mv = Min;
hamohamo 5:8dec5e011b3c 27 if(mv>Max) mv = Max;
hamohamo 6:87fd489a9801 28 if(integral<Min) integral = Min;
hamohamo 6:87fd489a9801 29 if(integral>Max) integral = Max;
hamohamo 0:0a9ce35078a3 30 }
hamohamo 5:8dec5e011b3c 31 double PID::getmv(){
hamohamo 0:0a9ce35078a3 32 double rtn;
hamohamo 5:8dec5e011b3c 33 if(mv<Min)rtn=Min;
hamohamo 5:8dec5e011b3c 34 else rtn=mv;
hamohamo 5:8dec5e011b3c 35 if(mv>Max)rtn=Max;
hamohamo 5:8dec5e011b3c 36 else rtn=mv;
hamohamo 0:0a9ce35078a3 37 return rtn;
hamohamo 0:0a9ce35078a3 38 }
hamohamo 2:d88ff6dda390 39 void PID::setLimit(double max,double min){
hamohamo 2:d88ff6dda390 40 Max = max;
hamohamo 2:d88ff6dda390 41 Min = min;
hamohamo 0:0a9ce35078a3 42 }
hamohamo 0:0a9ce35078a3 43 PID::~PID(){}