CEB Press Control Code v19.01
https://github.com/OpenSourceEcology/OSE_CEB_Press_v19.01
Notes
Nonselection Procedure
- We are using a four position switch for 1/4, 1/2, 3/4, and full bricks
- Switch has positions 0-4 - or 5 total
- The switch happens to have an off position (0) which does not make any connections
- We can use the non-selection condition to do a fifth pseudo-selection - the reset procedure
- Code is if (quarterSelected() == false && halfSelected == false && threequarterSelected == false && fullSelected == false ) {}
- Testing this:
Cylinder Bounce Code Simulation
To test solenoids sensing pressure and reversing solenoids upon pressure trigger, ma nually simulated logic is the following. This simulates a cylinder bouncing between full retraction and full extension, which are both high pressure trigger points.
- Turn solenoid UP on - while pressure low
- Turn solenoid UP off - as soon as pressure triggers, and move solenoid Down.
- Trigger is done manually simply by switching pin 13 on (touching jumper from ground to 13)
- The opposite action occurs until the pressure is triggered again. Length of pressure trigger doesn't matter.
- If the pressure trigger is longer that 2 seconds, then we don't know where in the program loop we are and either UP or DOWN will occur
- In real life, the solenoid should be off momentarily, and next step should follow immediately
Code:
//defines to make it easier for non-coders to make adjustments for troubleshooting and custom changes
//defines to make it easier for non-coders to make adjustments for troubleshooting and custom changes
- define SOLENOID_UP 4 //Extension. See pin mapping above.
- define SOLENOID_DOWN 5 //swap these pin numbers for wire inversion
- define SOLENOID_LEFT 6 //Extension.
- define SOLENOID_RIGHT 7 //swap these pin numbers for wire inversion
- define PRESSURE_SENSOR 13 //Needs pins adjacent so only 1 dupont connector is used
- define SELECTOR_RESET 12 //Activated when nothing is selected.
- define SELECTOR_QUARTER 11 //Reset is the shutdown/initialization procedure. All procedures are selected by
- define SELECTOR_HALF 10 //the WHILE function. QUARTER to FULL refers to brick thickness.
- define SELECTOR_THREEQUARTER 9 //Secondary cylinder timing is measured only.
- define SELECTOR_FULL 8 //Primary cylinder thickness setting is based on secondary cylinder motion.
- define PRESSURE_SENSOR_DEBOUNCE 20 //milliseconds to delay for pressure sensor debounce
- define DELAY 500 // 1/2 sec extra to compress brick via main Cyl (default 500ms)
//custom function declarations
bool lowPressure(); //function to read pressure sensor bool resetSelected(); // //bool quarterSelected(); // bool halfSelected(); // bool threequarterSelected(); // bool fullSelected(); //
//Global variables
unsigned long drawerExtTime = 0; //Time measurement for calibrating motion. unsigned long previousMillis = 0; //time measurement for expansion
void setup() {
//initialize pin I/O Inputs and turn everything off to avoid startup glitches
pinMode(PRESSURE_SENSOR, INPUT_PULLUP); pinMode(SELECTOR_HALF, INPUT_PULLUP); pinMode(SELECTOR_THREEQUARTER, INPUT_PULLUP); pinMode(SELECTOR_FULL, INPUT_PULLUP); pinMode(SOLENOID_RIGHT, OUTPUT); digitalWrite(SOLENOID_RIGHT, LOW); pinMode(SOLENOID_LEFT, OUTPUT); digitalWrite(SOLENOID_LEFT, LOW); pinMode(SOLENOID_DOWN, OUTPUT); digitalWrite(SOLENOID_DOWN, LOW); pinMode(SOLENOID_UP, OUTPUT); digitalWrite(SOLENOID_UP, LOW);
}
void loop() {
while (lowPressure() == true) { //goes only up to trigger of pressure, no matter how long pressure trigger is
digitalWrite(SOLENOID_UP, HIGH);
}
digitalWrite(SOLENOID_UP, LOW); // delay(2000); //gives time to release trigger (momentary switch should be used to make this easier)
while (lowPressure() == true) { //moves in reverse direction until next trigger
digitalWrite(SOLENOID_DOWN, HIGH);
}
digitalWrite(SOLENOID_DOWN, LOW); //moves on to next step, next step should continue until next trigger delay(2000);
} //reads pressure sensor state HIGH is false and LOW is true
//End of Loop
bool lowPressure() { //custom function definitions
if (digitalRead(PRESSURE_SENSOR) == HIGH) { delay(PRESSURE_SENSOR_DEBOUNCE); if (digitalRead(PRESSURE_SENSOR) == HIGH) { return true; } else { return false; } } else { return false; }}
//reads selector - HIGH is false, LOW is true- SELECTOR_RESET, SELECTOR_QUARTER, SELECTOR_HALF, SELECTOR_3QUARTERS, SELECTOR_FULL, bool resetSelected() { if (threequarterSelected() == false && halfSelected() == false && fullSelected() == false) { return true; } else { return false; }}
bool halfSelected() { if (digitalRead(SELECTOR_HALF) == HIGH) { delay(PRESSURE_SENSOR_DEBOUNCE); if (digitalRead(SELECTOR_HALF) == HIGH) { return false; } else { return true; } } else { return true; }}
bool threequarterSelected() { if (digitalRead(SELECTOR_THREEQUARTER) == HIGH) { delay(PRESSURE_SENSOR_DEBOUNCE); if (digitalRead(SELECTOR_THREEQUARTER) == HIGH) { return false; } else { return true; } } else { return true; }}
bool fullSelected() { if (digitalRead(SELECTOR_FULL) == HIGH) { delay(PRESSURE_SENSOR_DEBOUNCE); if (digitalRead(SELECTOR_FULL) == HIGH) { return false; } else { return true; } } else { return true; }}