Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLC Ladder Diagram to Arduino Sketch Conversion

Status
Not open for further replies.

Helepolis

Mechanical
Dec 13, 2015
198
Hi all,

I'm trying to operate a linear actuator (SMC LEY25B-300) using an Arduino based PLC (Controllino MAXI), in retrospect i would have used a regular PLC with ladder logic but it's to late for that (for now).
Anyway, I've figured how everything should work but I'm stuck on the programming part.
The controller of the actuator is LECP6 PNP type.

The PLC is programmable just like any other Arduino board which sounded just like what needed at first, as the first prototype was controlled by two Arduino UNO boards (instead of the actuator we used rack and pinion driven by a servo motor).
Now that we are upgrading the prototype to something more robust with industrial parts, coding for the actuator isn't as straight forward as i thought.
I'm having a hard time with getting the timing right between the commands, so after searching for a while i learned that there is a possibility to create a ladder logic diagram and then converting it to an Arduino sketch.

So if anybody has any experience and can suggest a good program, guide or anything else that you think might help, will be much appreciated.
 
Replies continue below

Recommended for you

Thanks for the help!

I found that post already (prior to posting here).
I asked the question for the same reason you mentioned yourself, there isn't much info and what is out there, is a mess and nothing concrete.
So i thought that I'm missing something.

Anyway, thank you again!
 
Just a random guess, if you are having timing problems it could be that you are using interrupts and putting too much code in them.
I made that mistake on a similar project. Try to do as little as possible in the interrupts, just increment or toggle a variable and then check the variable in your main loop to see if the interrupt was triggered.
 
mudandsnow said:
Just a random guess, if you are having timing problems it could be that you are using interrupts and putting too much code in them.
I made that mistake on a similar project. Try to do as little as possible in the interrupts, just increment or toggle a variable and then check the variable in your main loop to see if the interrupt was triggered.
Thanks, sounds very reasonable. But the thing is that I'm not using the interrupts just yet.
Tried to make the actuator move between two positions (initial and final) to simulate a simplified version of the ventilation sequence that we need from our machine, so there isn't much going on in the code.
But the most peculiar thing happens when i run the code, if i leave the code to run just the initialization of the actuator and the commands to move to position 1 (initial) everything seems to work fine.
But when i add the second part, that moved the actuator to position 2 (final), which is basically a copy-paste when the only difference is a single input pin change that corresponds with the position 2 the whole thing stops from working.
After playing with the code Iv'e noticed that if i add the "delay" function it helps, but it adds up to more than 8 seconds of delay time, that makes the operation very inefficient.
I just cant understand why adding the same piece of code that initiates only after the first part was compiled completely ruins the WHOLE thing.
 
That does sound strange. Could be a copy-paste error, maybe you missed one of the changes you should make to the copy. That's where I usually screw up my copy-pasting. You could try locating the problem by commenting out portions of the position 2 code until the position 1 code starts working. If you post your code I'll see if I can find anything.

I am curious what you mean by 'ventilation'? Is this a building vent or a human lung emulator or something else?
 
mudandsnow said:
I am curious what you mean by 'ventilation'? Is this a building vent or a human lung emulator or something else?
It's part of an MVP prototype for a therapeutic machine for lung treatment.

About the code, it's crazy simple, about 15 lines for each direction. But i had it rewritten so many times that it stopped working all together.
I'll get it back to working order (with the cumulative delay) and post it, because I'm at a loss.
 
It's hard to bother with version tracking for such short code but I recommend saving a copy of your code every time you have a successful test. I found having an 'InProgress' folder and a 'Working' folder makes it a lot easier to revert to working code.

Funny coincidence, my linear actuator that used Arduino was for lung stuff too. Not treatment though, just simulation. VacuMed makes a much nicer one than I made. I'm guessing you need something different but this could give you some ideas.

 
Thanks for the advice and the link!
It was my first suggestion as a possible solution, to use a rotating link with a connecting rod, this will give a perfect sinusoidal air flow but for some reason it was rejected.
Instead the linear actuator was opted as a solution, I'm guessing that the fact that this an MVP prototype and the link-rod solution requires much more calculations to control the flow withing the set parameters.
 
That rotating link seems so much simpler and safer than making a linear actuator change speed throughout its stroke and turn around at adjustable end points. The one thing I liked about the linear actuator is it allowed us to try non-sinusoidal breath patterns but in the end that wasn't really needed and it could have been done with a rotating link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor