Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ExperimentServer QEI_pmw MotorShield
Revision 16:bbe4ac38c535, committed 2020-09-12
- Comitter:
- elijahsj
- Date:
- Sat Sep 12 16:10:06 2020 +0000
- Parent:
- 15:495333b2ccf1
- Commit message:
- changes to include encoder part;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 27 14:55:58 2020 +0000
+++ b/main.cpp Sat Sep 12 16:10:06 2020 +0000
@@ -19,7 +19,7 @@
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 ticks or ~20kHZ
+MotorShield motorShield(12000); //initialize the motor shield with a period of 12000 clock ticks or ~20kHZ
int main (void)
{
@@ -33,8 +33,8 @@
while(1) {
if (server.getParams(input_params,NUM_INPUTS)) {
- float v1 = input_params[0]; // Duty cycle for first second
- float v2 = input_params[1]; // Duty cycle for second second
+ float d1 = input_params[0]; // Duty cycle for first second
+ float d2 = input_params[1]; // Duty cycle for second second
// Setup experiment
t.reset();
@@ -53,17 +53,17 @@
while( t.read() < 2 ) {
// Perform control loop logic
if (t.read() < 1)
- motorShield.motorAWrite(v1, 0); //run motor A at "v1" duty cycle and in the forward direction
+ motorShield.motorAWrite(d1, 0); //run motor A at "v1" duty cycle and in the forward direction
else
- motorShield.motorAWrite(v2, 0); //run motor A at "v2" duty cycle and in the forward direction
+ motorShield.motorAWrite(d2, 0); //run motor A at "v2" duty cycle and in the forward direction
// Form output to send to MATLAB
float output_data[NUM_OUTPUTS];
output_data[0] = t.read();
- output_data[1] = encoderA.getPulses();
- output_data[2] = encoderA.getVelocity();
- output_data[3] = motorShield.readCurrentA();
+ output_data[1] = 0; //MODIFY: COPY IN YOUR ANSWER FROM PART 1
+ output_data[2] = 0; //MODIFY: COPY IN YOUR ANSWER FROM PART 1
+ output_data[3] = motorShield.readCurrentA()*(30.0/65536.0)-15;
// Send data to MATLAB
server.sendData(output_data,NUM_OUTPUTS);