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.
Diff: main.cpp
- Revision:
- 34:599634375ba0
- Parent:
- 31:bfb4629ca327
- Child:
- 35:5857105c9956
--- a/main.cpp Thu Mar 16 21:17:42 2017 +0000
+++ b/main.cpp Thu Mar 16 21:38:57 2017 +0000
@@ -5,22 +5,10 @@
#include "parser.h"
#include <cmath>
-volatile uint8_t state = 0;
volatile float w3 = 0; //Angular velocity
volatile float duty = 0.5;
volatile int count_i3 = 0;
-volatile int prev_count_i3 = -1;
-const float angularVelocities[29] = {0, 0, 0, 56.3705020, 153.953598,
-221.162308, 436.561981, 652.034058, 669.472534, 671.117249, 703.662231,
-704.767273, 695.868835, 676.609924, 689.303345, 685.318481, 680.420166,
-681.527283, 683.529175, 700.758423, 742.759216, 737.354797, 733.224365,
-716.746521, 714.952209, 717.483154, 723.597839, 727.788757, 727.957336};
-const float dutyCycles [29] = { 0, 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.35,
- 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43,
- 0.44, 0.45, 0.50, 0.55, 0.60, 0.65, 0.70, 0.75,
- 0.80, 0.85, 0.90, 0.95, 1};
-const float angle = 6.283; //2*pi for 1 revolution
Timer dt_I3;
Timer motorTimer;
Ticker controlTicker;
@@ -28,7 +16,6 @@
volatile float fi0 = 0; //number of revs done
volatile int goalRevs = 50;
volatile float fi = 2*3.1415*goalRevs;
-volatile float goalW = 0; //desired angular velocity
volatile float accError = 0;
volatile float prevError = 0;
@@ -75,13 +62,11 @@
dt_I3.reset();
count_i3++;
- //PRINT("d")
}
void i_edge(){
state = updateState();
motorOut((state-orState+lead+6)%6, duty);
- //PRINT("a")
}
void CHA_rise(){
@@ -115,32 +100,12 @@
state = updateState();
motorTimer.start();
motorOut((state-orState+lead+6)%6, 0.3f); //Kickstart the motor
- /*
- while (motorTimer.read() < 30) {
- motorOut((state-orState+1+6)%6, 0.75f);
- wait(0.002);
- motorOut((state-orState-1+6)%6, 0.75f);
- wait(0.002);
- }
- stopMotor();
- */
+
while (count_i3 <= goalRevs) {
-
- pc.printf("Speed: %f, goal speed: %f, duty cycle: %f, revs done: %d \n\r",w3, goalW, duty, count_i3);
- /*
- if(duty < 0.00f) {
- stopMotor();
- return 0;
- }
-
- if(motorTimer.read() >= 30) {
- stopMotor();
- return 0;
- }
- */
+ pc.printf("Speed: %f, duty cycle: %f, revs done: %d \n\r",w3, duty, count_i3);
}
while (abs(w3) > 10){
- pc.printf("Speed: %f, goal speed: %f, duty cycle: %f, revs done: %d \n\r",w3, goalW, duty, count_i3);
+ pc.printf("Speed: %f, duty cycle: %f, revs done: %d \n\r",w3, duty, count_i3);
}
stopMotor();
return 0;
