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: feederController.cpp
- Revision:
- 1:4d3738338cf1
- Parent:
- 0:617334d8e3bb
--- a/feederController.cpp Thu Feb 02 19:18:12 2017 +0000
+++ b/feederController.cpp Sat Feb 04 01:27:29 2017 +0000
@@ -1,63 +1,26 @@
#include "mbed.h"
#include "USBSerial.h"
#include "HBridge.h"
+#include "feeder.h"
+#include "IAP_LPC11U.h"
extern "C" void mbed_mac_address(char *);
/************
TODO LIST:
*************
-* Move defs to .h file
-* Move tape pickup into main loop. Interrupts on it dont seem to be entirely reliable (spurrious)
* printf needs to be replace with a function that putc instead for non-formatted strings
* Convert lanes to a class so they there isn't duplicate code
+* Store lane distance in EEPROM
+* Store retrievable aribitrary text for the lane in EEPROM (loaded part, openpnp part feeder name, whatever)
*************/
-// HARDWARE PIN DEFS
-#define PIN_LED P0_7
-#define PIN_VINREF P0_23
-
-#define PIN_LED_YELLOW_0 P0_9
-#define PIN_LED_YELLOW_1 P1_13
-
-#define PIN_BTN_GREEN_0 P0_22
-#define PIN_BTN_GREEN_1 P1_14
-
-#define PIN_BOARD_FEED P0_1
-
-#define PIN_GATE_0 P0_11
-#define PIN_GATE_1 P0_12
-#define PIN_GATE_2 P0_13
-#define PIN_GATE_3 P0_14
-
-#define PIN_LANECTL_0 P0_16
-#define PIN_LANECTL_1 P1_15
-
-#define PIN_RS485_DIR P0_17
-#define PIN_UART_TXD P0_18
-#define PIN_UART_RXD P0_19
-
-#define PIN_SOLCTL_0 P1_19
-#define PIN_SOLCTL_1 P1_25
-
-#define PIN_BTN_LED_0 P1_29
-#define PIN_BTN_LED_1 P1_22
-
-#define PIN_H1_IN1 P0_20
-#define PIN_H1_IN2 P0_2
-#define PIN_H1_IN3 P1_26
-#define PIN_H1_IN4 P1_27
-
-#define PIN_H2_IN1 P1_28
-#define PIN_H2_IN2 P1_31
-#define PIN_H2_IN3 P0_8
-#define PIN_H2_IN4 P1_21
-
// SETTINGS
-#define TAPE_MAX_PULL_TIME 2 // seconds
+#define TAPE_MAX_PULL_TIME 3 // seconds
+#define TAPE_MIN_PULL_TIME 1 // seconds
-#define FEED_FWD_ENC_PULSE 2 // actually this + 1
+#define FEED_FWD_ENC_PULSE 2 // it's actually this value + 1
// encoder pulses: >(lane0FeedDistance * FEED_FWD_ENC_PULSE)
// 3 for 1 position, 5 for 2 positions
@@ -95,10 +58,6 @@
int lane0FeedDistance = 1; // 1 = 2mm, 2 = 4mm
int lane1FeedDistance = 1;
-// LOOP COUNT FOR BUTTONS (incase Timer is too slow)
-int button0PressCount = 0;
-int button1PressCount = 0;
-
// FEEDER END BUTTON STATES
int button0LastState = 0;
int button1LastState = 0;
@@ -115,9 +74,9 @@
Timeout lane0Feedout;
Timeout lane1Feedout;
-// PICKUP STOPPER
-Timeout lane0Pickupout;
-Timeout lane1Pickupout;
+// TAPE PICKUP STOPPER
+Timer tape0PullTime;
+Timer tape1PullTime;
/*****************************************************************************
**** HARDWARE
@@ -173,21 +132,17 @@
void stopTapeL0()
{
- if (LN0_TAPEGATE)
- {
- tape0Takeup = 0;
- tapeMotor0.Coast();
- }
+ tape0PullTime.stop();
+ tape0Takeup = 0;
+ tapeMotor0.Coast();
}
void stopTapeL1()
{
- if (LN1_TAPEGATE)
- {
- tape1Takeup = 0;
- tapeMotor1.Coast();
- }
+ tape1PullTime.stop();
+ tape1Takeup = 0;
+ tapeMotor1.Coast();
}
@@ -306,14 +261,14 @@
{
feedMotor0.Brake();
- lane0Feedout.attach(&coastLane0, 0.020);
+ lane0Feedout.attach(&coastLane0, 0.010);
}
void stopLane1Reverse()
{
feedMotor1.Brake();
- lane1Feedout.attach(&coastLane1, 0.020);
+ lane1Feedout.attach(&coastLane1, 0.010);
}
/*****************************************************************************
@@ -342,15 +297,13 @@
LED_0 = 0;
LED_1 = 0;
- // clear terminal screen
+ // clear terminal screen - ignore compiler warning
pc.printf("\x1Bc\x1B[2J");
pc.printf("\r\nFeeder POST...\r\n\r\n");
- char mac[6];
- mbed_mac_address(mac);
- uint32_t devId = mac[3] << 16 | mac[4] << 8 | mac[5];
- pc.printf("Feeder ID: %d [%#04x::%#04x::%#04x]\r\n\r\n", devId, mac[3], mac[4], mac[5]);
+ UID feederID = IAP_ReadUID();
+ pc.printf("Feeder UID: {%#10x-%#10x-%#10x-%#10x }\r\n\r\n", feederID.word0, feederID.word1, feederID.word2, feederID.word3);
pc.printf("Gate 0 (L0 Feed): %d\r\n", LN0_FEEDGATE.read());
pc.printf("Gate 1 (L1 Feed): %d\r\n", LN1_FEEDGATE.read());
@@ -395,14 +348,16 @@
// timer for button debouncing. oldass hardware buttons are bouncy!
Timer button0Time;
Timer button1Time;
+ float t0 = 0;
+ float t1 = 0;
while(true)
{
/**********************************************************************
- ** PC USB COMMS
+ ** PC USB COMMS - 2.01uS
**********************************************************************/
- // no pc comms checking when feeding, can't afford the time
- if (lane0State == IDLE && lane1State == IDLE)
+ // no pc comms checking when feeding, no need
+ if ((lane0State == IDLE || lane0State == PICKING) && (lane1State == IDLE || lane1State == PICKING))
{
while (pc.readable())
{
@@ -519,12 +474,9 @@
}
}
}
-
-
- LED_0 = 1; // for timing check with oscope/logic analyser
/**********************************************************************
- ** BUTTON CHECK
+ ** BUTTON CHECK - 3.65uS
**********************************************************************/
if (lane0State != FEEDING)
{
@@ -542,7 +494,6 @@
button0Time.stop(); // no need to keep counting
pc.printf("Picking 0\r\n");
- button0PressCount = 0;
setLane0Picking(); // open solenoid while button is down
}
}
@@ -550,7 +501,6 @@
else if (!b0 && b0 != button0LastState) // low transition - button released
{
button0LastState = b0;
- button0PressCount = 0;
if (lane0State == PICKING) // not just a bounce
{
@@ -565,7 +515,6 @@
button0Time.reset();
button0Time.start();
}
- button0PressCount = 0;
}
button0LastState = b0;
@@ -584,7 +533,6 @@
button1Time.stop();
pc.printf("Picking 1\r\n");
- button1PressCount = 0;
setLane1Picking();
}
}
@@ -592,7 +540,6 @@
else if (!b1 && b1 != button1LastState) // low transition - button released
{
button1LastState = b1;
- button1PressCount = 0;
if (lane1State == PICKING)
{
@@ -608,12 +555,11 @@
button1Time.start();
}
button1LastState = b1;
- button1PressCount = 0;
}
}
/**********************************************************************
- ** ENCODER CHECK
+ ** ENCODER CHECK - 3.38uS
**********************************************************************/
b0 = LN0_FEEDGATE;
@@ -672,33 +618,44 @@
lane1Feedout.attach(&stopLane1Reverse, 0.020);
pc.printf("Idle 1\r\n");
}
+ LED_0 = 1;
/**********************************************************************
- ** COVER TAPE CHECK
+ ** COVER TAPE CHECK - Gate closed: 41.98uS, Gate open 30.48uS
**********************************************************************/
b0 = LN0_TAPEGATE;
b1 = LN1_TAPEGATE;
+ if (tape0Takeup)
+ t0 = tape0PullTime.read(); // very slow..
+ if (tape1Takeup)
+ t1 = tape0PullTime.read(); // very slow..
// LANE 0
- if (!b0 && !tape0Takeup)
+ if (!b0 && !tape0Takeup) // cover tape slacked enough to interrupt gate
{
+ tape0PullTime.reset();
+ tape0PullTime.start();
+
tape0Takeup = 1;
tapeMotor0.Forward();
- lane0Pickupout.attach(&stopTapeL0, TAPE_MAX_PULL_TIME);
}
- else if (b0)
+ else if ((b0 && t0 > TAPE_MIN_PULL_TIME) ||
+ (!b0 && tape0Takeup && t0 > TAPE_MAX_PULL_TIME))
{
stopTapeL0();
}
// LANE 1
- if (!b1 && !tape1Takeup)
+ if (!b1 && !tape1Takeup) // gate opened
{
+ tape1PullTime.reset();
+ tape1PullTime.start();
+
tape1Takeup = 1;
tapeMotor1.Forward();
- lane1Pickupout.attach(&stopTapeL1, TAPE_MAX_PULL_TIME);
}
- else if (b1)
+ else if ((b1 && t1 > TAPE_MIN_PULL_TIME) ||
+ (!b1 && tape1Takeup && t1 > TAPE_MAX_PULL_TIME))
{
stopTapeL1();
}