Go Down

Topic: Parallel working (Read 1 time) previous topic - next topic

Midarin

Hello everybody,
I'm working to a little project where I will control 4 electrical cylinder with an Arduino uno.

The main task are:
- control with different button (up and down)
- save the set position in the EEPROM
- load the saved position from the EEPROM
- set the position to 0 (reset)

At the moment I've developed the program just for one of the mentioned cylinder. The code is the following:

Code: [Select]

/*
 * Test For the Controller of the actuators
 * This program it's use to control and save the position of 4 actuators (Spindelmotoren).
 * With the analog inputs the program read the actual position. This position should be also saved.
 * 2 digital outputs each actuator are used to raise up or lower the position to the desired value
 * 2 digital inputs are use one to save and the other to load the position
 * 1 digital input is use to reset/ set on 0 position all the actuators
 */

#include <EEPROM.h>

// constants don't change
const int savePin = 2;        // the input pin number of the Save Button
const int loadPin = 3;        // the input pin number of the Load Button
const int resetPin = 4;       // the input pin number of the Reset Button
const int upPin =  12;        // the output pin number of the Up signal
const int downPin =  13;      // the output pin number of the Down signal
const int posPin = A0;        // the input pin for the actual postion signal

// variables will change:
int saveState = 0;            // variable for reading the Save status
int loadState = 0;            // variable for reading the Load status
int resetState = 0;           // variable for reading the Reset status
int istValue = 0;             // variable to store the value coming from the sensor
int sollValue = 0;            // variable to store the value where the actuatore should be
int adress = 0;               // EEPROM adress


void setup()
{
  //start serial connection
  Serial.begin(9600); 
 
  // initialize the pin as an input:
  pinMode(savePin, INPUT);     
  pinMode(loadPin, INPUT);
  pinMode(resetPin, INPUT);
 
  // initialize the pin as an output:
  pinMode(upPin, OUTPUT);   
  pinMode(downPin, OUTPUT);   
}

void loop()
{
  // read the state of the pushbutton values:
  saveState = digitalRead(savePin);
  loadState = digitalRead(loadPin);
  resetState = digitalRead(resetPin);
  sollValue = analogRead(posPin);

 
  // check if the Save Button is pressed.
  if (saveState == HIGH)
  {     
    // Save data on variable
    istValue = analogRead(posPin);
    //print out the value of the pushbutton
    Serial.println("Save value:");
    Serial.println(istValue);
    Serial.println("Save Pin value:");
    Serial.println(analogRead(posPin));   
    // Save variable on EEPROM
    EEPROM.put(adress, istValue);
    delay(4000); 
  }

  // check if the Load Button is pressed.
  if (loadState == HIGH)
  {
    EEPROM.get(adress, istValue);
    // Save data on variable
    sollValue = istValue;
    Serial.println("Load value:");
    Serial.println(istValue);
    Serial.println("Load Pin value:");
    //Read Data from EEPROM
    istValue = analogRead(posPin);
   
    if (sollValue > istValue)
    {
      //Raise up the actuator
      digitalWrite(upPin, HIGH);
      istValue = analogRead(posPin);
    }
    else
    {
      digitalWrite(upPin, LOW);
    }
 
    if (sollValue < istValue)
    {
      //Lower the actuator
      digitalWrite(downPin, HIGH);
      istValue = analogRead(posPin);
    }   
    else
    {
      digitalWrite(downPin, LOW);
    }
  }
 
  // check if the Reset Button is pressed.
  if (resetState == HIGH)
  {
    if (sollValue != 0)
    {
      digitalWrite(downPin, HIGH);
      istValue = analogRead(posPin);
    }
    else
    {
      digitalWrite(downPin, LOW);
    }
  }   
}


I'd like to know how and if it is possible to implement the parallel movement for the 4 cylinder using just one arduino uno.
Save, Load and Reset button are the same for all the cylinder.

Thank you for your answers and sorry for the mistakes, english is not my main speak


PaulS

Quote
I'd like to know how and if it is possible to implement the parallel movement for the 4 cylinder using just one arduino uno.
Yes, it is possible.

You'll need to save the positions of all 4 cylinders, and measure the actual positions of all 4 cylinders as they are moving.
The art of getting good answers lies in asking good questions.

Midarin

Yes, it is possible.

You'll need to save the positions of all 4 cylinders, and measure the actual positions of all 4 cylinders as they are moving.
thank you for your reply
but how? if I do with an if() that mean they move until the statement it's reach, and if I do so they move one each if(), therefore no parallel movement :/ or if I check all the position in the same if() the move until the statement it's reach but, because the command it's done with digital output, the stay HIGH until the statement it's reached, therefore strange movement or the stay stuck until they reach the max.

thanks again!

PaulS

Quote
if I do with an if() that mean they move until the statement it's reach
If you do what with an if()?

You start the devices moving, and then loop to check the position of each one. When one gets to the desired position, you stop that one. When all 4 have stopped, you quit looping.
The art of getting good answers lies in asking good questions.

Midarin

#4
Jun 07, 2019, 09:33 am Last Edit: Jun 07, 2019, 02:39 pm by Midarin
If you do what with an if()?

You start the devices moving, and then loop to check the position of each one. When one gets to the desired position, you stop that one. When all 4 have stopped, you quit looping.
I start to think i've explained really bad the situation :/
The problem is the control of the cylinder. They move with 2 different digital signal: one to go up and one to go down. Now if the position of just one is reached, the the digital signal (up or down) must be putted to 0 (check the code to understand). The problem is that can't be done until all the positions are reached if a if loop is use, or I do a single loop for each cylinder but in this case it's not parallel anymore.
Just one other thing. If anybody has a solution please put an example for the code.

Thank you again!

PaulS

Quote
The problem is that can't be done until all the positions are reached if a if loop is use,
An if STATEMENT does NOT cause looping.

You can use an if statement in some other kind of loop, to see if a cylinder has reached the desired position. If it has, do whatever needs doing. If it hasn't, do whatever needs doing. In either case, it is for ONE cylinder at a time.
The art of getting good answers lies in asking good questions.

Go Up