CEB Press Control Code v19.01: Difference between revisions

From Open Source Ecology
Jump to navigation Jump to search
Line 3: Line 3:
=Notes=
=Notes=


To test solenoids sensing pressure and reversing solenoids upon pressure trigger, manually simulated logic is the following. This simulates a cylinder bouncing between full retraction and full extension, which are both high pressure trigger point.
To test solenoids sensing pressure and reversing solenoids upon pressure trigger, manually 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 on - while pressure low
Line 9: Line 9:
*Trigger is done manually simply by switching pin 13 on (touching jumper from ground to 13)
*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.
*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
*In real life, the solenoid should be off momentarily, and next step should follow immediately
Code:
Code:

Revision as of 00:52, 25 January 2019

https://github.com/OpenSourceEcology/OSE_CEB_Press_v19.01

Notes

To test solenoids sensing pressure and reversing solenoids upon pressure trigger, manually 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

  1. define SOLENOID_UP 4 //Extension. See pin mapping above.
  2. define SOLENOID_DOWN 5 //swap these pin numbers for wire inversion
  3. define SOLENOID_LEFT 6 //Extension.
  4. define SOLENOID_RIGHT 7 //swap these pin numbers for wire inversion
  1. define PRESSURE_SENSOR 13 //Needs pins adjacent so only 1 dupont connector is used
  2. define SELECTOR_RESET 12 //Activated when nothing is selected.
  3. define SELECTOR_QUARTER 11 //Reset is the shutdown/initialization procedure. All procedures are selected by
  4. define SELECTOR_HALF 10 //the WHILE function. QUARTER to FULL refers to brick thickness.
  5. define SELECTOR_THREEQUARTER 9 //Secondary cylinder timing is measured only.
  6. define SELECTOR_FULL 8 //Primary cylinder thickness setting is based on secondary cylinder motion.
  1. define PRESSURE_SENSOR_DEBOUNCE 20 //milliseconds to delay for pressure sensor debounce
  2. 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;
 }}