here

Dependencies:   QEI mbed

Committer:
Showboo
Date:
Mon Nov 20 01:20:16 2017 +0000
Revision:
3:81d97506bd46
Parent:
2:4fb5c1e8a19a
Assignment 4 updated, IR readings found. Left Motor not turning for some reason, maybe someone can find this out.

Who changed what in which revision?

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