yasinyasar

5 engine equal aging

25 posts in this topic

How to make 5 engine equal aging software? is there an example?

Share this post


Link to post
Share on other sites

I doubt there is a sample program for such control. It is pretty straight forward. Give it a shot - if you run into any issues post your code here and we can help.

Share this post


Link to post
Share on other sites
Priority will be given to the operating hours of the level motors that will operate according to a common level transmitter with 5 motors. how can I do?

Share this post


Link to post
Share on other sites

 

8 hours ago, yasinyasar said:

 how can I do?

You can do it with ladder logic or structured text. We're not here to write code for you, but we are happy to help you troubleshoot your code.

Share this post


Link to post
Share on other sites

and please try to use normal size font, like everyone else. 

btw equal aging would assume you know (and keep track) of the age of each unit.  

Share this post


Link to post
Share on other sites
I am a new member and I am writing using translate. I'll pay attention from now on. I'm sorry. I memorize the running times of the engines, but I don't know how to sort them from smallest to largest. I don't want anyone to write a program. I just wanted help on how to proceed.

Share this post


Link to post
Share on other sites

with five engine times a simple bubble sort should do the trick.

Share this post


Link to post
Share on other sites

So you have 5 values and you need to figure out the smallest one? Are they time datatype or something else?

Array sort will sort the array smallest to largest but you will lose the position so you won't know which motor has the smallest value, you'll just know the smallest value.

I would place them in an array and use AryMin or AryMax to find the smallest or largest value.

Share this post


Link to post
Share on other sites

i guess the goal is to simply find the smallest value when starting one of the units. so for 5 values one should not need more than 4 comparisons.

// assume value in firt element of ARR[] is the smalest

smallest_unit_number := 1;
smallest_value := arr[smallest_unit_number];

// then check if there is a smaller one. ..
if arr[2]<arr[smallest_unit_number] then smallest_unit_number :=2;
if arr[3]<arr[smallest_unit_number] then smallest_unit_number :=3;
if arr[4]<arr[smallest_unit_number] then smallest_unit_number :=4;
if arr[5]<arr[smallest_unit_number] then smallest_unit_number :=5;

instead of "smallest" you could use "youngest", and instead of array "arr[]" use "AGE" you get something quite readable:

youngest_motor := 1;
youngest_age := AGE[youngest_motor];

if AGE[2]<AGE[youngest_motor] then youngest_motor :=2;
if AGE[3]<AGE[youngest_motor] then youngest_motor :=3;
if AGE[4]<AGE[youngest_motor] then youngest_motor :=4;
if AGE[5]<AGE[youngest_motor] then youngest_motor :=5;

This could of course be done in a loop too, but for such short list it is not necessary

Share this post


Link to post
Share on other sites
public static void selectionSort(int arr[]) {
   for (int i = 0; i < arr.length; i++) {
      int min = i;
      for (int j = i + 1; j < arr.length; j++) {
         if (arr[j] < arr[min]) {
            min = j;
         } 
      }
      int temp = arr[i];
      arr[i] = arr[min];
      arr[min] = temp;
   }
}

this is what i want to do but i can't write as st in sysmac.

Share this post


Link to post
Share on other sites

this can be implemented in just about any programming language and if you put your mind to it you can do it but ... as mentioned before it would serve no purpose in this case as it only manipulates values and looses track of index. in other words you sort the age values but lose information which of the five values corresponds to which motor. age is just the means to choose correct index so you know which motor to start next time. 

another thing to keep in mind is execution time. and with PLCs one need to be careful using loops for that (and some other) reason(s). are you familiar with code complexity (big omega)?

https://www.freecodecamp.org/news/big-omega-notation/

 

 

Share this post


Link to post
Share on other sites

I don't understand why we are trying to reinvent the wheel here. Put the data in an array, use AryMin and the position with the lowest value is returned. The array is left intact.

That position is the motor with the smallest runtime so you know to use it next

2 people like this

Share this post


Link to post
Share on other sites
1 hour ago, photovoltaic said:

I don't understand why we are trying to reinvent the wheel here. Put the data in an array, use AryMin and the position with the lowest value is returned. The array is left intact.

That position is the motor with the smallest runtime so you know to use it next

if you've in industrial  automation for any number of years this is common sense.  But if you're a programmer with little real world frame of reference it takes a while to grasp.  I've seen it many times @photovoltaic

2 people like this

Share this post


Link to post
Share on other sites

photovoltaic is right - no doubt things like this would often not be discussed if most plc programmer would simply go through instruction reference manual for the controller the are using.

but i would also have to totally agree with Bob... since my response was not just to topic starter and this specific case (using specific CPU). i like to provide general solutions that can be applied everywhere regardless of used controller and used instruction set

after programming various types of controllers for over 30 years, i have learned to appreciate data manipulation using basic instructions that are bound to be present on every platform  / PLC brand. i don't even recall half of product i have programmed for. btw. on this very forum there are plenty of posts where people are completely stuck and ask for help because they are in desperate need for some 'special' instruction. sadly that is not how real programming works...

don't get me wrong, i would happily use each and every resource at my disposal but historically when writing code to be used/managed by others (usually quite inexperienced people) it is often much preferred to show how something can be done rather than just do it. that way anyone can manipulate it if needed and apply in every project regardless of instruction set at hand.

there are many other reasons that are better left for a separate topic. 

 

  

1 person likes this

Share this post


Link to post
Share on other sites

fotovoltaik

We can find the smallest number using arrow min.We cannot rank 5 numbers from smallest to largest.I have a level meter. When level1 comes, young motor1 is activated. When level 2 comes, young motor2 is activated. When level3 comes, young motor comes into play. It continues in this way.

 

I thought a little bit and made the algorithm. I can sort the numbers.

Now I'm thinking about how to start the engines in this order. I will be glad if anyone has any ideas.

I am sharing the photo of the algorithm, if someone finds it useful, I will be happy.

 

Share this post


Link to post
Share on other sites

Oh ok, I see the challenge now. I'll ponder this and write up something for it

Share this post


Link to post
Share on other sites

create two arrays, call them AGE[] and INDEX[]

array AGE[] should contain age values of all motors.

array INDEX[] should simply contain numbers 1,2,3,4,5 before sorting starts.

then use any sort you like (bubble, insertion, whatever...). every sort algorithm also includes part where sorted values are swapped.

so your sorter should compare values in array AGE[] as expected (so far so good).

however (and this is the key), every time values of array AGE[] are swapped, also swap corresponding values in the array INDEX[] at the same time.

that's it... 

 

Share this post


Link to post
Share on other sites

here is one example in KRL:

DEF bubble_sort( )

;declare arrays
DECL REAL AGE[5] ; array of five REAL values 
DECL INT INDEX[5] ; same size but type is INT

; declare also counters and temp variables for swap
DECL INT i,j,tmp_int
DECL REAL tmp_real

; populate arrays before sorting...
AGE[1]=763.91   
AGE[2]=8161.8
AGE[3]=1008.9
AGE[4]=6731.8
AGE[5]=450.75

INDEX[1]=1
INDEX[2]=2
INDEX[3]=3
INDEX[4]=4
INDEX[5]=5

; now lets sort the values by age

FOR i=1 to 5
  FOR j=i+1 to 5
    IF AGE[i]>AGE[j] THEN
      ; --- swap values for age ---
      tmp_real=AGE[i]
      AGE[i]=AGE[j] 
      AGE[j]=tmp_real
      ; --- also swap value for index ---
      tmp_int=INDEX[i]
      INDEX[i]=INDEX[j]
      INDEX[j]=tmp_int
    ENDIF
  ENDFOR
ENDFOR

; example uses runtime variables
; therfore halt before program end
; to check the values after sorting
HALT

END

and here are values after sorting:

 

sorting parallel arrays.png

and same thing in TwinCat:

 

sorting parallel arrays in TwinCat.png

Share this post


Link to post
Share on other sites

Here's what I came up with, the variable Pumps_Required is assigned a value based on demand (0 = stop motors, 1-5 = desired number of motors to run)

The Start_Order[] array holds the order in which the pumps should be run - position 1 is for pump 1 etc.

 

 

Capture.JPG

Capture2.JPG

Edited by photovoltaic
Not enough coffee

Share this post


Link to post
Share on other sites

is that correct?
based on test values in Time_Array[], motors with lowest age are 3 and 5. so they should be the ones started before there is a need to run motors 4,2 and 1. 

but the last screenshot shows that both pumps 1 and 5 are on while pump 3 is off... this does not look right to me unless i misunderstood the problem or the screenshots of test data and output are not a matching set. because test data shows that pumps 1 and 5 are the largest and the smallest value. the only time both should be on is when demand is so high that all pumps need to be on. but pumps 2 and 3 are not on..

 

1 person likes this

Share this post


Link to post
Share on other sites
19 minutes ago, panic mode said:

is that correct?
based on test values in Time_Array[], motors with lowest age are 3 and 5. so they should be the ones started before there is a need to run motors 4,2 and 1. 

but the last screenshot shows that both pumps 1 and 4 are on while pump 3 is off... this does not seem right to me. 

 

Rushed debugging - yeah something isn't right..

1 person likes this

Share this post


Link to post
Share on other sites
27 minutes ago, panic mode said:

is that correct?
based on test values in Time_Array[], motors with lowest age are 3 and 5. so they should be the ones started before there is a need to run motors 4,2 and 1. 

but the last screenshot shows that both pumps 1 and 5 are on while pump 3 is off... this does not look right to me unless i misunderstood the problem or the screenshots of test data and output are not a matching set. because test data shows that pumps 1 and 5 are the largest and the smallest value. the only time both should be on is when demand is so high that all pumps need to be on. but pumps 2 and 3 are not on..

 

Fixed. Good catch Panic, thanks.

Share this post


Link to post
Share on other sites

good job...:-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now