Updated with the Algorithm

Dependencies:   QEI mbed

Fork of MM_rat_Assignment4-newwest by Evan Brown

Committer:
Showboo
Date:
Mon Nov 20 01:49:19 2017 +0000
Revision:
0:f7fc09f9c7ce
Child:
1:fb18b43590e6
Had to change workspaces

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Showboo 0:f7fc09f9c7ce 1 #include "mbed.h"
Showboo 0:f7fc09f9c7ce 2 #include "QEI.h"
Showboo 0:f7fc09f9c7ce 3 #include "header.h"
Showboo 0:f7fc09f9c7ce 4
Showboo 0:f7fc09f9c7ce 5 inline void pulse_ir(int in){
Showboo 0:f7fc09f9c7ce 6 LeftIR = in;
Showboo 0:f7fc09f9c7ce 7 FrontLeftIR = in;
Showboo 0:f7fc09f9c7ce 8 FrontRightIR = in;
Showboo 0:f7fc09f9c7ce 9 RightIR = in;
Showboo 0:f7fc09f9c7ce 10 }
Showboo 0:f7fc09f9c7ce 11
Showboo 0:f7fc09f9c7ce 12 int main() {
Showboo 0:f7fc09f9c7ce 13 pid lman, rman;
Showboo 0:f7fc09f9c7ce 14 lman.kp = .004f;
Showboo 0:f7fc09f9c7ce 15 lman.ki = .0f;
Showboo 0:f7fc09f9c7ce 16 lman.kd = .0f;
Showboo 0:f7fc09f9c7ce 17 rman.kp = .5f;
Showboo 0:f7fc09f9c7ce 18 rman.ki = .1f;
Showboo 0:f7fc09f9c7ce 19 rman.kd = .4f;
Showboo 0:f7fc09f9c7ce 20
Showboo 0:f7fc09f9c7ce 21 lpwmf.period(0.01f);
Showboo 0:f7fc09f9c7ce 22 lpwmf = 0; //Previously started on, replace with lpwmf = lbase to make it start on (not a good idea)
Showboo 0:f7fc09f9c7ce 23 rpwmf.period(0.01f);
Showboo 0:f7fc09f9c7ce 24 rpwmf = 0;
Showboo 0:f7fc09f9c7ce 25 pid ir_lman, ir_rman;
Showboo 0:f7fc09f9c7ce 26 ir_lman.kp = .004f;
Showboo 0:f7fc09f9c7ce 27 ir_lman.ki = .0f;
Showboo 0:f7fc09f9c7ce 28 ir_lman.kd = .0f;
Showboo 0:f7fc09f9c7ce 29 ir_rman.kp = .5f;
Showboo 0:f7fc09f9c7ce 30 ir_rman.ki = .1f;
Showboo 0:f7fc09f9c7ce 31 ir_rman.kd = .4f;
Showboo 0:f7fc09f9c7ce 32 t_time.start();
Showboo 0:f7fc09f9c7ce 33 while(1){
Showboo 0:f7fc09f9c7ce 34 float dt = t_time.read();
Showboo 0:f7fc09f9c7ce 35 float lspeed; float rspeed;
Showboo 0:f7fc09f9c7ce 36 pulse_ir(1);
Showboo 0:f7fc09f9c7ce 37 ProcessIR(dt, ir_lman, lspeed, rspeed);
Showboo 0:f7fc09f9c7ce 38 lpwmb = 0; rpwmb = 0;
Showboo 0:f7fc09f9c7ce 39 //lpwmf = lspeed; rpwmf = rspeed;
Showboo 0:f7fc09f9c7ce 40 pulse_ir(0);
Showboo 0:f7fc09f9c7ce 41 t_time.reset();
Showboo 0:f7fc09f9c7ce 42 }
Showboo 0:f7fc09f9c7ce 43 }