Modified experiment example for lab 3 of 2.74
Dependencies: ExperimentServer MotorShield QEI_pmw
Diff: main.cpp
- Revision:
- 25:8c5c5eeff8e7
- Parent:
- 24:4d2f1b7746de
--- a/main.cpp Mon Sep 27 19:55:59 2021 +0000 +++ b/main.cpp Mon Sep 26 15:55:11 2022 +0000 @@ -33,16 +33,16 @@ QEI encoderC(PC_6, PC_7, NC, 1200, QEI::X4_ENCODING); // MOTOR C ENCODER (no index, 1200 counts/rev, Quadrature encoding) QEI encoderD(PD_12, PD_13, NC, 1200, QEI::X4_ENCODING);// MOTOR D ENCODER (no index, 1200 counts/rev, Quadrature encoding) -MotorShield motorShield(12000); //initialize the motor shield with a period of 12000 clock ticks or ~20kHZ +MotorShield motorShield(24000); //initialize the motor shield with a period of 12000 clock ticks or ~10kHZ void current_control() //Current control function { float error = 0; theta = encoderA.getPulses()*(6.2831/1200.0); velocity = encoderA.getVelocity()*(6.2831/1200.0); - current = -(motorShield.readCurrentA()*(30.0/65536.0)-15.0); //read current for motor A in amps. Note: this is a slightly different current sensor so its a different conversion than last lab. + current = -(motorShield.readCurrentA()*(52.8/65536.0)-26.4); //read current for motor A in amps. Note: this is a slightly different current sensor so its a different conversion than last lab. error = current_d - current; - + volt = 0; //CHANGE THIS TO SET CURRENT CONTROLLER VALUES duty = volt/12.0; @@ -53,7 +53,7 @@ duty = -1; } if (duty >= 0){ - motorShield.motorAWrite(duty, 0); //run motor A at "v1" duty cycle and in the forward direction + motorShield.motorAWrite(duty, 0); } else if (duty < 0){ motorShield.motorAWrite(abs(duty), 1);