Project in progress
Hydraulic press brake control

Hydraulic press brake control © GPL3+

Control cylinder synchronization and position via closed loop stepper drive hydraulic valves. and linear glass scales.

  • 41 views
  • 0 comments
  • 0 respects

Components and supplies

About this project

Code

Press brake controlArduino
control synchronization a height hydraulic cylinders on a press brake.
//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

Comments

Similar projects you might like

I Let Everyone On The Internet Control My X-Mas Decoration

Project showcase by Tobi_Lxtr

  • 5,568 views
  • 7 comments
  • 41 respects

SCADA Control of a Water Pumping Station

Project showcase by Muntadhar Jafar

  • 5,371 views
  • 1 comment
  • 15 respects

Mega Bread - Atari Joystick Linking for Robotics Control

Project in progress by Pigeon-Kicker

  • 1,466 views
  • 3 comments
  • 10 respects

Home Automation Control Panel

Project in progress by Jay

  • 33,432 views
  • 10 comments
  • 120 respects

Control electronics by sliding your phone

Project tutorial by Tanishq Jaiswal

  • 14,838 views
  • 13 comments
  • 61 respects

Arduino Home Automation Control Board IoT

Project tutorial by Team My Arduino Home

  • 8,410 views
  • 3 comments
  • 19 respects
Add projectSign up / Login