Go Down

Topic: Hydraulic press brake control via stepper driven valves. (Read 283 times) previous topic - next topic

microsprintbuilder

Sep 19, 2018, 04:21 pm Last Edit: Sep 19, 2018, 04:23 pm by microsprintbuilder
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.

Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.

hammy

Are the steppers big enough to drive the valves ?

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

Code: [Select]
//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


Robin2

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
Two or three hours spent thinking and reading documentation solves most programming problems.



Robin2

symptom is  encoder input is not updating.
Can you post a simple program that illustrates that?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

outsider

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

Go Up