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

使用例

#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:
Wed Oct 13 08:12:34 2021 +0000
Revision:
2:d88ff6dda390
Parent:
0:0a9ce35078a3
Child:
5:8dec5e011b3c
pepepe;

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 2:d88ff6dda390 4 err[0]=0.0;
hamohamo 2:d88ff6dda390 5 gain = 0.0;
hamohamo 2:d88ff6dda390 6 integral = 0.0;
hamohamo 0:0a9ce35078a3 7 }
hamohamo 0:0a9ce35078a3 8 void PID::Update(double Value,double Target,double dt){
hamohamo 0:0a9ce35078a3 9 err[1]=Target-Value;
hamohamo 0:0a9ce35078a3 10 integral+=(err[1]+err[0])/2.0*dt;
hamohamo 0:0a9ce35078a3 11 P=err[1];
hamohamo 0:0a9ce35078a3 12 I=integral;
hamohamo 0:0a9ce35078a3 13 D=(err[1]-err[0])/dt;
hamohamo 0:0a9ce35078a3 14 err[0]=err[1];
hamohamo 0:0a9ce35078a3 15 gain+=(Kp*P)+(Ki*I)+(Kd*D);
hamohamo 2:d88ff6dda390 16 if(gain<Min) gain = Min;
hamohamo 2:d88ff6dda390 17 if(gain>Max) gain = Max;
hamohamo 2:d88ff6dda390 18 if(integral<Min) integral = Min;
hamohamo 2:d88ff6dda390 19 if(integral>Max) integral = Max;
hamohamo 0:0a9ce35078a3 20 }
hamohamo 0:0a9ce35078a3 21 double PID::getGain(){
hamohamo 0:0a9ce35078a3 22 double rtn;
hamohamo 2:d88ff6dda390 23 if(gain<Min)rtn=Min;
hamohamo 2:d88ff6dda390 24 else rtn=gain;
hamohamo 2:d88ff6dda390 25 if(gain>Max)rtn=Max;
hamohamo 2:d88ff6dda390 26 else rtn=gain;
hamohamo 0:0a9ce35078a3 27 return rtn;
hamohamo 0:0a9ce35078a3 28 }
hamohamo 2:d88ff6dda390 29 void PID::setLimit(double max,double min){
hamohamo 2:d88ff6dda390 30 Max = max;
hamohamo 2:d88ff6dda390 31 Min = min;
hamohamo 0:0a9ce35078a3 32 }
hamohamo 0:0a9ce35078a3 33 PID::~PID(){}