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: Regrind RioRandHBridge Solenoid mbed
Fork of ECE4012-PHD by
Diff: main.cpp
- Revision:
- 3:597f8492fee2
- Parent:
- 2:819397348cd0
- Child:
- 5:94678bcfc8a2
--- a/main.cpp Wed Dec 02 15:43:38 2015 +0000
+++ b/main.cpp Thu Dec 03 06:36:21 2015 +0000
@@ -1,6 +1,6 @@
#include "mbed.h"
#include "Regrind.h"
-#include "TB6612FNG.h"
+#include "RioRandHBridge.h"
#include "Solenoid.h"
#define OG1_TO_OG2_DIST 1
@@ -19,13 +19,15 @@
Solenoid led4(LED4, LED_ON_DELAY, LED_OFF_DELAY);
DigitalOut onePPS_out(p29);
Solenoid solenoid(p30, SOLENOID_ON_DELAY, SOLENOID_OFF_DELAY); //Solenoid(PinName pin, float ondelay, float offdelay)
-TB6612FNG augerMotors(p21, p26, p25, p22, p24, p23, p27); //TB6612FNG( PinName pinPwmA, PinName pinAin1, PinName pinAin2, PinName pinPwmB, PinName pinBin1, PinName pinBin2, PinName pinNStby );
+RioRandHBridge augerMotors(p21, p25, p22, p23); //RioRandHBridge( PinName pinPwm1, PinName pinDir1, PinName pinPwm2, PinName pinDir2);
+DigitalIn reverseMotor1pb(p26);
+DigitalIn reverseMotor2pb(p24);
AnalogIn topMotorAdjuster(p19);
-AnalogIn bottomMotorAdjuster(p16);
+DigitalOut bottomMotorAdjuster(p16,0);
DigitalOut unused1(p17,0);
AnalogIn og1(p15);
AnalogIn og2(p20);
-AnalogIn og3(p18);
+DigitalOut og3(p18,0);
InterruptIn divertParticle(p5);
Timer totalT;
DigitalOut startColor(p6);
@@ -68,6 +70,12 @@
void divert(){
regrindArray[og2Ndx].divert = 1;
}
+void reverseMotor1(){
+ augerMotors.Dir1 = !augerMotors.Dir1;
+ }
+void reverseMotor2(){
+ augerMotors.Dir2 = !augerMotors.Dir2;
+ }
int main() {
//Start Clock
@@ -79,10 +87,14 @@
1pps.attach(&flip, 1.0);
*/
//Setup motors
- augerMotors.setPwmApulsewidth(0.0);
- augerMotors.setPwmBpulsewidth(0.0);
- augerMotors.motorA_ccw();
- augerMotors.motorB_ccw();
+ reverseMotor1pb.mode( PullUp );
+ reverseMotor2pb.mode( PullUp );
+ //reverseMotor1pb.attach_asserted( &reverseMotor1 );
+ //reverseMotor2pb.attach_asserted (&reverseMotor2);
+ augerMotors.setpwm1pulsewidth(0.0);
+ augerMotors.setpwm2pulsewidth(0.0);
+ augerMotors.motor1_ccw();
+ augerMotors.motor2_ccw();
//Spin up Motors until fluctuation of 10% seen
@@ -115,12 +127,13 @@
//Sample ADCs
og1_adc = og1.read()*3.3;
og2_adc = og2.read()*3.3;
- og3_adc = og3.read()*3.3;
+ //og3_adc = og3.read()*3.3;
//wait(0.01);
//pc.printf("og1: %f og2: %f og3: %f\n\r",og1_adc, og2_adc, og3_adc);
if((og1_calibration - og1_adc > THRESHOLD) && (og1Oneshot != 1)){ //Something passed through og1
og1Oneshot = 1;
+ divertParticle.rise(&divert);
//pc.printf("Regrind seen at OG 1 : %fV\n\r", og1_adc);
led2 = 1;
@@ -136,6 +149,7 @@
if((og2_calibration - og2_adc > THRESHOLD) && (og2Oneshot != 1)){
og2Oneshot = 1;
+ divertParticle.rise(NULL);
regrindArray[og2Ndx%REGRIND_ARRAY_SIZE].setVelocity(OG1_TO_OG2_DIST);
led3 = 1;
if(regrindArray[og2Ndx].divert == 1){
@@ -149,7 +163,7 @@
og2Oneshot = 0;
}//else if(og2 ...)
-
+ /*
if((og3_adc == 0) && (og3Oneshot != 1)){
og3Oneshot = 1;
led4 = 1;
@@ -162,7 +176,7 @@
og3Oneshot = 0;
}//else if(og3 ...)
-
+ */
//Check on 1pps clock
if((totalT.read_us() % 2000000) < 1000000){
led1 = 1;
@@ -176,8 +190,9 @@
//Check if data writing flag is set - if so, write to SD card
//Adjust PWM as necessary
- augerMotors.setPwmApulsewidth(topMotorAdjuster.read());
- augerMotors.setPwmBpulsewidth(bottomMotorAdjuster.read());
+ augerMotors.Dir1 = reverseMotor1pb;
+ augerMotors.setpwm1pulsewidth(topMotorAdjuster.read());
+ augerMotors.setpwm2pulsewidth(bottomMotorAdjuster.read());
//pc.printf("top: %f bottom: %f\n\r",topMotorAdjuster.read(),bottomMotorAdjuster.read());
} //while(1)
totalT.stop();
