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
Diff: main.cpp
- Revision:
- 12:84a6dcb60422
- Parent:
- 11:4eb579687dda
- Child:
- 13:3a1f4e09789b
diff -r 4eb579687dda -r 84a6dcb60422 main.cpp
--- a/main.cpp Wed Aug 26 02:49:40 2020 +0000
+++ b/main.cpp Wed Aug 26 14:37:19 2020 +0000
@@ -4,7 +4,6 @@
#include "ExperimentServer.h"
#include "QEI.h"
#include "MotorShield.h"
-#include "HardwareSetup.h"
#define NUM_INPUTS 2
#define NUM_OUTPUTS 3
@@ -23,7 +22,7 @@
AnalogIn currentC(PF_13); //MOTOR C CURRENT SENSOR
AnalogIn currentD(PA_4); //MOTOR D CURRENT SENSOR
-MotorShield motors(1000); //initialize the motor shield with a period of 1000 ticks or xxx kHZ
+MotorShield motorShield(12000); //initialize the motor shield with a period of 12000 ticks or ~20kHZ
int main (void)
{
@@ -37,8 +36,8 @@
while(1) {
if (server.getParams(input_params,NUM_INPUTS)) {
- float v1 = input_params[0]; // Voltage for first second
- float v2 = input_params[1]; // Voltage for second second
+ float v1 = input_params[0]; // Duty cycle for first second
+ float v2 = input_params[1]; // Duty cycle for second second
// Setup experiment
t.reset();
@@ -48,15 +47,15 @@
encoderC.reset();
encoderD.reset();
- motors.motorAWrite(0, 0); //turn motor A off, motors.motorAWrite(DUTY CYCLE, DIRECTION), DIRECTION = 0 is forward
+ motorShield.motorAWrite(0, 0); //turn motor A off, motorShield.motorAWrite(DUTY CYCLE, DIRECTION), DIRECTION = 0 is forward
// Run experiment
while( t.read() < 2 ) {
// Perform control loop logic
if (t.read() < 1)
- motors.motorAWrite(v1, 0); //run motor A at "v1" duty cycle and in the forward direction
+ motorShield.motorAWrite(v1, 0); //run motor A at "v1" duty cycle and in the forward direction
else
- motors.motorAWrite(v2, 0); //run motor A at "v2" duty cycle and in the forward direction
+ motorShield.motorAWrite(v2, 0); //run motor A at "v2" duty cycle and in the forward direction
// Form output to send to MATLAB
float output_data[NUM_OUTPUTS];
@@ -70,7 +69,7 @@
}
// Cleanup after experiment
server.setExperimentComplete();
- motors.motorAWrite(0, 0); //turn motor A off
+ motorShield.motorAWrite(0, 0); //turn motor A off
} // end if
} // end while