Hydraulic press brake control via stepper driven valves.

Hello; I'm replacing controls on my press brake. My press has two hydraulic cylinders (left and right) that need to be synchronized as they move. My design uses a 2 spool hydraulic valve with stepper motors attached that have 200 ppr encoders attached. they rotate about 60 degrees each direction from center to either raise or lower the cylinders. I have attached linear glass scales to each cylinder to read there position. I have a dual pedal switch for up and down. For now I also have switches for height controls. I have hit a snag. I cannot get the motors to move correctly. They just oscillate when I push the down or up switch. I've tried to change the delay but cannot get any better result. I tried to put the code here it says it's over 9000 so I've attached it. sorry for that.

press-brake-step-control-mega9-14-18.ino (12 KB)

microsprintbuilder:
I have hit a snag. I cannot get the motors to move correctly. They just oscillate when I push the down or up switch

Before I look at your program I would like more information about this.

Have you any program that makes the motors move properly?

What do you mean by "oscillate" - do you mean (for example) that they move 50 steps in one direction and then 50 steps in the other direction and repeat that indefinitely?

...R

Are the steppers big enough to drive the valves ?

So I've found my bad code and fixed the oscillation. I did this by commenting out code. I was using if, if else and else instead of just 3 if's. Now I have another problem. It appears that the arduino cant keep up. It locks up and starts blinking the yellow light. I changed things up to lessen the load by switching to just the glass scales on the cylinders for sync and changing to the 3 encoder board by robogaia and using accel stepper keep track and to run the motors. it works great on the bench using a couple mpg wheels instead of the glass scales the motors move like they should. but when I put in the machine and use the glass scales it doesn't seem to read the scales and make adjustments and then after a couple minutes it locks up and the yellow light begins blinking. I'm starting to think I need to use a pc linuxcnc. attached is my revised code

//Robogaia.com
// the sensor communicates using SPI, so include the library:
#include <SPI.h>
#include <AccelStepper.h>

// Define two steppers and the pins they will use
AccelStepper stepperL(AccelStepper::DRIVER, 2, 3);
AccelStepper stepperR(AccelStepper::DRIVER, 6, 7);

int chipSelectPin1=10;
int chipSelectPin2=9;
int chipSelectPin3=8;
const int rCylHmBtn= 43; // right cylinder home switch
const int lCylHmBtn= 45; // left cylinder home switch
const int upSwBtn = 41; // up pedal switch
const int dnSwBtn = 39; // down pedal switch
const int htSwBtn = 49; // switch to stop press at set hight
const int stopSwBtn = 47; // switch to stop press on return home
// varibles in code
int rCylHm = 0; // var right cylinder home switch
int lCylHm = 0; // var left cylinder home switch
int dnSw = 0; //  var down pedal switch
int upSw = 0; // var up pedal swithc
int htSw = 0; // var switch to stop press at set hight
int stopSw = 0; // var switch to stop press on return home
int stpDn = -67; // number of steps to open valve completly going down
int stpUp = 67; // number of steps to open valve completly going up
int lReq = 0; // requested posision number for left stepper 
int rReq = 0; // requested posision munber for right stepper
long rPos = 0; // right cylinder position
long lPos = 0; // left cyinder position
//end calibration values
//////////////////////////////////////////////


//*****************************************************
void setup() 
//*****************************************************
{
 // Serial.begin(9600);
  stepperL.setMaxSpeed(1500);
  stepperL.setAcceleration(1000);
  stepperR.setMaxSpeed(1500);
   stepperR.setAcceleration(1000);
  
  pinMode (rCylHmBtn, INPUT);
  pinMode (lCylHmBtn, INPUT);
  pinMode (upSwBtn, INPUT);
  pinMode (dnSwBtn, INPUT);
  pinMode (htSwBtn, INPUT);
  pinMode (stopSwBtn, INPUT);
  
  pinMode(chipSelectPin1, OUTPUT);
  pinMode(chipSelectPin2, OUTPUT);
  pinMode(chipSelectPin3, OUTPUT);
  
  digitalWrite(chipSelectPin1, HIGH);
  digitalWrite(chipSelectPin2, HIGH);
  digitalWrite(chipSelectPin3, HIGH);

  LS7366_Init();

  

  delay(100);
}

//*****************************************************
void loop() 
//*****************************************************
{

     dnSw = digitalRead(dnSwBtn);
     upSw = digitalRead(upSwBtn);
     htSw = digitalRead(htSwBtn);
     stopSw = digitalRead(stopSwBtn);
     lPos = getEncoderValue(1);
     rPos = getEncoderValue(2);
          
        Serial.print(" L Cyl = ");
        Serial.print(lPos);
         
        Serial.print(" R Cyl = ");
        Serial.print(rPos);

        Serial.print (" R pos #  ");
        Serial.print (rReq);

        Serial.print (" L pos #  ");
        Serial.print (lReq);
        
        Serial.print("\r\n");

        if (dnSw == LOW && upSw == LOW){
           lReq = (0);
           rReq = (0);
        }
      
    
        if (dnSw == HIGH && htSw == LOW){
            if (stepperL.distanceToGo() == 0 && stepperR.distanceToGo() == 0){
                  if (lPos == rPos){
                  lReq = (stpDn);
                  rReq = (stpUp);
                  }
                  
                  if (lPos < rPos){
                  lReq = (0);
                  rReq = (stpUp);
                  }
                  
                  if (lPos > rPos){
                  lReq = (stpDn);
                  rReq = (0);
                  }
        }}
      
        if (upSw == HIGH && stopSw == LOW){
              if (stepperL.distanceToGo() == 0 && stepperR.distanceToGo() == 0){
                  if (lPos == rPos){
                  lReq = (stpUp);
                  rReq = (stpDn);
                  }
                  
                  if (lPos < rPos){
                  lReq = (0);
                  rReq = (stpDn);
                  }
                  
                  if (lPos > rPos){
                  lReq = (stpUp);
                  rReq = (0);
                  }
                
        }}
               
    stepperL.moveTo(lReq);
    stepperR.moveTo(rReq);
    
    stepperL.run();
    stepperR.run();
   
}//end loop


//*****************************************************  
long getEncoderValue(int encoder)
//*****************************************************
{
    unsigned int count1Value, count2Value, count3Value, count4Value;
    long result;
    
    selectEncoder(encoder);
    
     SPI.transfer(0x60); // Request count
    count1Value = SPI.transfer(0x00); // Read highest order byte
    count2Value = SPI.transfer(0x00);
    count3Value = SPI.transfer(0x00);
    count4Value = SPI.transfer(0x00); // Read lowest order byte
    
    deselectEncoder(encoder);
   
    result= ((long)count1Value<<24) + ((long)count2Value<<16) + ((long)count3Value<<8) + (long)count4Value;
    
    return result;
}//end func

//*************************************************
void selectEncoder(int encoder)
//*************************************************
{
  switch(encoder)
  {
     case 1:
       digitalWrite(chipSelectPin1,LOW);
       break;
     case 2:
       digitalWrite(chipSelectPin2,LOW);
       break;
     case 3:
       digitalWrite(chipSelectPin3,LOW);
       break;
      
  }//end switch
  
}//end func

//*************************************************
void deselectEncoder(int encoder)
//*************************************************
{
  switch(encoder)
  {
     case 1:
        digitalWrite(chipSelectPin1,HIGH);
        break;
     case 2:
       digitalWrite(chipSelectPin2,HIGH);
       break;
     case 3:
       digitalWrite(chipSelectPin3,HIGH);
       break;
         
  }//end switch
  
}//end func



// LS7366 Initialization and configuration
//*************************************************
void LS7366_Init(void)
//*************************************************
{
   
    
    // SPI initialization
    SPI.begin();
    //SPI.setClockDivider(SPI_CLOCK_DIV16);      // SPI at 1Mhz (on 16Mhz clock)
    delay(10);
   
   digitalWrite(chipSelectPin1,LOW); //Select LS7366R 1
   SPI.transfer(0x88); //Instruction to write to MDRO
   SPI.transfer(0x20); //byte to select index_reset CNTR
   SPI.transfer(0x03); //byte to select quadrature mode 00=non 01=X1 02=X2 03=X4
   SPI.transfer(0x80);//byte to select 0x00=asychronous index 0x80= sychronous index
   digitalWrite(chipSelectPin1,HIGH); //deselect LS7366R 1
   
   
   digitalWrite(chipSelectPin2,LOW); //Select LS7366R 2
   SPI.transfer(0x88); //Instruction to write to MDRO
   SPI.transfer(0x20); //byte to select index_reset CNTR
   SPI.transfer(0x03); //byte to select quadrature mode 00=non 01=X1 02=X2 03=X4
   SPI.transfer(0x80);//byte to select 0x00=asychronous index 0x80= sychronous index
   digitalWrite(chipSelectPin2,HIGH); //deselect LS7366R 2


   digitalWrite(chipSelectPin3,LOW); //Select LS7366R 2
   SPI.transfer(0x88); //Instruction to write to MDRO
   SPI.transfer(0x20); //byte to select index_reset CNTR
   SPI.transfer(0x03); //byte to select quadrature mode 00=non 01=X1 02=X2 03=X4
   SPI.transfer(0x80);//byte to select 0x00=asychronous index 0x80= sychronous index
   digitalWrite(chipSelectPin3,HIGH); //deselect LS7366R 2
   
}//end func

microsprintbuilder:
So I've found my bad code and fixed the oscillation. I did this by commenting out code. I was using if, if else and else instead of just 3 if's. Now I have another problem. It appears that the arduino cant keep up. It locks up and starts blinking the yellow light. I changed things up to lessen the load by switching to just the glass scales on the cylinders for sync and changing to the 3 encoder board by robogaia and using accel stepper keep track and to run the motors. it works great on the bench using a couple mpg wheels instead of the glass scales the motors move like they should. but when I put in the machine and use the glass scales it doesn't seem to read the scales and make adjustments and then after a couple minutes it locks up and the yellow light begins blinking. I'm starting to think I need to use a pc linuxcnc. attached is my revised code

Most of that is technical stuff that probably means a lot to you but I (and others, I suspect) know nothing about the machine you are trying to drive or any of the components.

Can pick one specific symptom and post the program that illustrates it together with links to the datasheets of all components that are attached to the Arduino?

If that symptom can be sorted out then we can consider the next one.

...R

I've started a project page with all that. I need to update it to where I am.

https://create.arduino.cc/projecthub/microsprintbuilder/hydraulic-press-brake-control-2ba96c

symptom is encoder input is not updating.

it does on the bench when the count is slow using mpg wheels instead of the linear glass scales on the machine.

https://www.ebay.com/itm/2Axis-3-Axis-Linear-Scale-Linear-Encoder-DRO-Digital-Readout-for-Milling-Lathe/113058011463?ssPageName=STRK%3AMEBIDX%3AIT&var=413409537290&_trksid=p2060353.m2749.l2649

microsprintbuilder:
symptom is encoder input is not updating.

Can you post a simple program that illustrates that?

...R

That old brake looks familiar, do you have the manual or hydraulic schematic for it?

Hi microsprintbuilder.

Did you managed to synchronise 2 hydraulic rams on your hydraulic press?

I have same a challenge but I’m only beginner in Arduino programming.

See my links to topic: Two Hydraulic Cylinders to be Synchronized by Arduino

https://forum.arduino.cc/index.php?topic=618122.msg4188162#msg4188162

Vladuinoire:
Hi microsprintbuilder.

Did you managed to synchronise 2 hydraulic rams on your hydraulic press?

I have same a challenge but I’m only beginner in Arduino programming.

See my links to topic: Two Hydraulic Cylinders to be Synchronized by Arduino

Two Hydraulic Cylinders to be Synchronized by Arduino - Project Guidance - Arduino Forum

[/quot

Please don't resurrect old threads. Start a new one and reference this old thread if you wish. The correct logic for your situation is to designate ONE cylinder as MASTER and make the second cylinder follow it's movement.

Paul

Vlad sent this email to my plant:

Hi Paul.

You commented yesterday on the Arduino.cc forum : The correct logic for your situation is to designate ONE cylinder as MASTER and make the second cylinder follow it's movement.

Do you have any links to more information how to build this system for brake press to synchronise work for 2 hydraulic rams?

Any advice will be appreciative.

Thanks

Vlad

Naughty naughty!

My logic would be to continuously monitor the position of cylinder 1 and cylinder 2. The idea is to move cylinder 2 the correct direction to make it match cylinder 1.

Then check you foot control and move cylinder 1 if commanded to move. The above logic will make cylinder 2 move also.

The Arduino will be so fast it will seem like both cylinders are moving at the same time.

Otherwise you will need the expensive solution.

Paul

Hello Vladuinoire; paul is incorrect. if you make one cylinder the master and the other to sync you will have a problem when the master is to far ahead. The slave will never catch up. I tried this using a Arduino and gave up because reading two linear glass scales and doing the logic was locking up the board. So I thought. It turns out my code was causing the lockup. I didn't find it until I switched to a mesa board and using linuxcnc. I made a custom comp and it did finally work after switching to closed loop drives. After all that I found that one cylinder was leaking and so old no parts where available so I ripped it all apart put new cylinders on and went mechanical sync.