here

Dependencies:   QEI mbed

Committer:
Showboo
Date:
Mon Nov 20 01:20:16 2017 +0000
Revision:
3:81d97506bd46
Parent:
1:18f0113ac5a2
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 1:18f0113ac5a2 1 /*
Showboo 1:18f0113ac5a2 2 #include "mbed.h"
Showboo 1:18f0113ac5a2 3 #include "QEI.h"
Showboo 1:18f0113ac5a2 4 #include "header.h"
Showboo 1:18f0113ac5a2 5 int main_old() {
Showboo 1:18f0113ac5a2 6 pid lman, rman;
Showboo 1:18f0113ac5a2 7 lman.kp = .004f;
Showboo 1:18f0113ac5a2 8 lman.ki = .0f;
Showboo 1:18f0113ac5a2 9 lman.kd = .0f;
Showboo 1:18f0113ac5a2 10 rman.kp = .5f;
Showboo 1:18f0113ac5a2 11 rman.ki = .1f;
Showboo 1:18f0113ac5a2 12 rman.kd = .4f;
Showboo 1:18f0113ac5a2 13
Showboo 1:18f0113ac5a2 14 lpwmf.period(0.01f);
Showboo 1:18f0113ac5a2 15 lpwmf = 0; //Previously started on, replace with lpwmf = lbase to make it start on (not a good idea)
Showboo 1:18f0113ac5a2 16 rpwmf.period(0.01f);
Showboo 1:18f0113ac5a2 17 rpwmf = 0;
Showboo 1:18f0113ac5a2 18
Showboo 1:18f0113ac5a2 19
Showboo 1:18f0113ac5a2 20 t_time.start();
Showboo 1:18f0113ac5a2 21
Showboo 1:18f0113ac5a2 22 pid ir_lman, ir_rman;
Showboo 1:18f0113ac5a2 23 ir_lman.kp = .004f;
Showboo 1:18f0113ac5a2 24 ir_lman.ki = .0f;
Showboo 1:18f0113ac5a2 25 ir_lman.kd = .0f;
Showboo 1:18f0113ac5a2 26 ir_rman.kp = .5f;
Showboo 1:18f0113ac5a2 27 ir_rman.ki = .1f;
Showboo 1:18f0113ac5a2 28 ir_rman.kd = .4f;
Showboo 1:18f0113ac5a2 29 while(1){
Showboo 1:18f0113ac5a2 30 float dt = t_time.read();
Showboo 1:18f0113ac5a2 31 t_time.reset();
Showboo 1:18f0113ac5a2 32 float error = (LeftEncoder.getPulses() - RightEncoder.getPulses())/16.0f; //Can be pos or neg, Range from 0 - 255 for one revolution
Showboo 1:18f0113ac5a2 33 if(error == 0){
Showboo 1:18f0113ac5a2 34 resetpid(&lman);
Showboo 1:18f0113ac5a2 35 resetpid(&rman);
Showboo 1:18f0113ac5a2 36 }
Showboo 1:18f0113ac5a2 37 float adjust_l = getFix(&lman, error, dt);
Showboo 1:18f0113ac5a2 38 LeftIR = 1;
Showboo 1:18f0113ac5a2 39 RightIR = 1;
Showboo 1:18f0113ac5a2 40 float leftread = LeftReceiver.read();
Showboo 1:18f0113ac5a2 41 float rightread = RightReceiver.read();
Showboo 1:18f0113ac5a2 42 float error_IR = (rightread - leftread);
Showboo 1:18f0113ac5a2 43 if(error_IR < 0.02f){
Showboo 1:18f0113ac5a2 44 resetpid(&ir_lman);
Showboo 1:18f0113ac5a2 45 resetpid(&ir_rman);
Showboo 1:18f0113ac5a2 46 }
Showboo 1:18f0113ac5a2 47 //float adjust_l = getFix(&ir_lman, error, dt);
Showboo 1:18f0113ac5a2 48 lpwmf = constrain(0.0f, 0.3f, lbase + adjust_l);
Showboo 1:18f0113ac5a2 49 rpwmf = rbase+.2f;
Showboo 1:18f0113ac5a2 50 }
Showboo 1:18f0113ac5a2 51 }
Showboo 1:18f0113ac5a2 52 */