ST practice ideas.

TurpoUrpo

Lifetime Supporting Member
Join Date
May 2008
Location
Switzerland
Posts
1,571
Hello

I would like to practice using ST (scl on siemens actually) more. But im short on ideas on programs i could try to do.

So please all you experienced programmers. Give me some specs on programs to do, preferably something used in real deal machines. So no traffic light please;)

Harder the better, thats what gives me the "kicks" :D

Thank you in advance.
 
I like the filter idea

You can implement a Runge-Kutta ODE solver. I started one. Getting the basics to work is easy but writing a more general routine takes a little thinking.

You can make a FOPDT or SOPDT temperature system simulator using the RK ODE solver or simply use linear state space methods. Then control the temperature system simulator using FB41. I believe Pandiani has done this. Then add a Smith Predictor to offset the dead time.

A sliding mode control, SMC, temperature can be written and compared with the built in FB41.

How about an alpha-beta-gamma filter? ABG filters are a very simple form of the Kalman filter. ABG filters are good for calculating a smoothed position, velocity and acceleration from an encoder. There are always people wanting to know how to compute speeds.

Write a Savitsky-Golay filter for smoothing data.

Write a quick sort program that can sort a list of numbers in place. I see this request a lot.

I can think of many more, what areas interest you? I think of some motion control related projects. Ramping algorithms would be useful for temperature too.

I can help.
 
He he will have ample amount of things now to get those kicks!!!
Ok
What does the numerator part of the equation 1.2 denotes?
Once the value of 's' is calculated then we need to use the equation 1.0c to get value of H.

What i infer is that user just needs to enter the desired low pass cut of frequency and pop shall the answer come. The Holy H.
 
What does the numerator part of the equation 1.2 denotes?
s is the Laplace operator. It is a frequency.

Once the value of 's' is calculated then we need to use the equation 1.0c to get value of H.
s is not calculated. s is a frequency. To get the response of the filter s is incremented from a low frequency to a high frequency. In my example I do a logarithmic frequency sweep.
The filter is express in the continuous domain. A computer needs to work in the discrete time periods so a conversion must be done. The Tustin approximation is used for that.

What i infer is that user just needs to enter the desired low pass cut of frequency and pop shall the answer come. The Holy H.
See my example. It is only a second order Butterworth filter but it shows the steps required to implement a digital fitler.
http://www.deltamotion.com/peter/Mathcad/Mathcad - Butterworth NG.pdf
The last page shows how the noisy input is greatly filtered at the expense of a little phase delay.
 
Well, atleast you took hard literally :)

The point is that most of suggestions need lot of other understanding on fields im not yet good at. Control related problems are of big interest for me.

I saw the thread about pandianis FOPDT or SOPDT. Dont remember witch one. I remember he also posted the ready code. But i have been unable to find it from thread jungle. I did download when he posted it, but had no time at that point to look at it. And now im missing the code.

I'll take on the quick sort first. Need to look at filter desings and runge-kutta with more time. Im more than happy to read more about those subjects if you want to write about.

Thanks
 
Think in terms of useful not hard

The point is that most of suggestions need lot of other understanding on fields im not yet good at.
I have all the code. It just needs to be translated into SCL. You will be learning by doing. There is nothing quite like stepping through code to get an understand of what it is doing. Do you program in C?

I saw the thread about pandianis FOPDT or SOPDT. Dont remember witch one. I remember he also posted the ready code. But i have been unable to find it from thread jungle. I did download when he posted it, but had no time at that point to look at it. And now im missing the code.
I have the code somewhere but I don't want to post other people's work. I think we can get Pandiani to post it again.

I'll take on the quick sort first. Need to look at filter desings and runge-kutta with more time. Im more than happy to read more about those subjects if you want to write about.
Thanks
I think that is a good place to start. You should look for code on the internet that does a sort in place and does not need to use recursive calls.

You can find all of the information you need on Wikipedia
http://en.wikipedia.org/wiki/Runge-Kutta
Wolfram is another good site
http://mathworld.wolfram.com/Runge-KuttaMethod.html
Most useful code you can find already written on the internet by just searching. All you need to do is to translate it into SCL and test it.

Another thing that you can write is a general outline for a multi tasking state machine. Each task is made of a select statement with many states.

Each state has three sections:
1 Code that is executed once when the state is entered.
2 Code that is executed each scan the state is active.
3 Code that is and code that is executed when leaving that state.

Instead of scanning all the code in a very inefficient way this state machine would only execute the code in the active state for each task.

This kind of code would make organizing big state machines easy.
 
About the state machine, then I have a couple of ideas I have never had the time to implement.

1. The state machine could have "auto" and "single-step" transition modes.
The auto mode would be the normal mode.
Single step would mean that the state machine would remain in a state even if one or more transitions would be active. Only when the operator activates a button does the next state become active. In order to manage that nothing harmful can happen (i.e. overheating from remaining too long in a certain state), then each state shal have a flag "allow single step".

2. It would be nice if there was a debugging mode, which could be enable/disabled in case there is a tricky problem to locate.
Each state, and each transition shall have a text description. When a transition is activated, or a state is activated, the texts are logged to a FIFO log. There should be timestamps in the log.
The log will then contain entries like:
13:05:00.0000 "Enter INI state"
13:05:10.0000 "Transition T002 triggered"
13:05:10.0000 "State S001 activated"
13:05:10.0200 "Transition T014 triggered"
13:05:10.0200 "State S006 activated"
etc.

SCL/ST handles texts very easily, so it shouldnt be that much work.

The trouble with state machines is the splitting of states and transitions means that a running machine can be hard to troubleshoot by just looking into the program online. More debugging aid will be really welcome.
 
2. It would be nice if there was a debugging mode, which could be enable/disabled in case there is a tricky problem to locate.
I did this for my current project using Graph7. This is a new machine which is being developed as a research centre project and the final version may be significantly different from the initial version. The debug mode allows the user to step through the program using a button on the screen, shows which step the program is in (number and description) and whether or not the transition state has ben reached. It allows the development team (who are not very experienced with Step7) to make small changes to the program to cater for modifications in the equipment without having to wait for me to come on site (never mind the related hotel and travel costs) and has worked really well in practice.

I didn't really need it myself, this time, but for a more complex future project I'll definitely implement it again.
 
1. The state machine could have "auto" and "single-step" transition modes.
The auto mode would be the normal mode.
It is easy enough to add a play and pause input that set and reset a bit that is used for one more condition to be met before going to the next step.

Single step would mean that the state machine would remain in a state even if one or more transitions would be active.
This is easy too. Just clear the play bit on entry to the step or when exiting the last step.

Only when the operator activates a button does the next state become active. In order to manage that nothing harmful can happen (i.e. overheating from remaining too long in a certain state), then each state shal have a flag "allow single step".
So what if play is active and the rest of the conditions are not met?

2. It would be nice if there was a debugging mode, which could be enable/disabled in case there is a tricky problem to locate.
On fault clear the play bit.

Each state, and each transition shall have a text description. When a transition is activated, or a state is activated, the texts are logged to a FIFO log. There should be timestamps in the log.
Good idea. A whole DB can be used as an circular buffer of UDT that are pointers to strings and a value.

The log will then contain entries like:
13:05:00.0000 "Enter INI state"
13:05:10.0000 "Transition T002 triggered"
13:05:10.0000 "State S001 activated"
13:05:10.0200 "Transition T014 triggered"
13:05:10.0200 "State S006 activated"
etc.
Good idea! We do that now. We can even log the variables that are changed and what they are changed too.

SCL/ST handles texts very easily, so it shouldnt be that much work.
Yes but handling strings is not what a PLC should be used for. We store the message number and a value. The software in the laptop or PC formats and displays it.

The trouble with state machines is the splitting of states and transitions means that a running machine can be hard to troubleshoot by just looking into the program online. More debugging aid will be really welcome.
We log the transitions between the states, variable and I/O changes, Profibus and Ethernet communications and Motion commands. We had to do this because you don't want to pause a motion application as it may pause in a dangerous state plus it is hard to instantly start and stop something heavy.

It is much safer to log all the data so that the events leading up to a point can be studied. So how are would be it be to put the time, a message and a value in a UDT and store that in a circular queue of about 1024 entries? Not that hard.

Logging the variables would probably require a function where the time, variable name and new value are logged. I really like the circular queue of 1024 or more UDTs of time, message number and value.

Now how does one read this circular queue up and display it?

I was doing this back in the early 80s. We also had a time out for many states. We displayed a message using a video card to a monitor that said what the state was doing and what it was waiting for to go to the next state. If the state timed out we would flash what the state was waiting for. It pretty much told the electricians which photo eye or limit switch wasn't working. The extra effort required to put in all the diagnostics was paid back with fewer or short tech support calls.
 
I am not sure what you mean by "play bit".

Sure, these things are reasonably easy to implement, if only one has thought about it from the onset.

Logging to PLC memory is not an issue any longer. The PLC can catch every single transition and log it with millisecond precision.
Performance is greatly increased compared to yesterdays PLCs so even storing strings in a buffer wont mean any serious penalty (at least for my purposes). Memory is generally abundant, and even a log with 1000 entries would only need around 50kB.

I once had a machine that was slaved to another machine, and absolutely could not be allowed to stop in the middle of the sequence. Each state could last from a few milliseconds to 1-2 seconds. I ended writing a crude logger in a hurry in order to troubleshoot the program.

Ideally, there shall be a nice HMI that displays all the states and transitions. And with the log entries displayed in a rolling window.
 
I have all the code. It just needs to be translated into SCL. You will be learning by doing. There is nothing quite like stepping through code to get an understand of what it is doing. Do you program in C?

I have done some programs with c++. I dont think reading plain c should be a problem.

I got little offtrack and made SelectionSort first, as its easier to do than QuickSort. Attached is code for SCL functions,DB I used to test it is also on scl file and another file for example call in OB1.

There is still one strange issue, the input anypointer needs to be given like this "P#DB1.DBX 0.0 REAL 20" at the moment even when db data is declared as array. It will miss the datatype (always bytes not caring what type of array it really is) if given "Buffer.Data".

Plese feel free to comment on.

Next ill look more deeply on the quicksort.

Thanks.
 
Arrays, STRUCT and UDTs are always passed with type=byte. If you want to know the type, you have to pass in an array element as well.
 
Is it good otherwise? Than the "fix" for s7 not compiling code as I want?

Do you think wich one is better, have block user also pass one array element or just type in the element type?

Example:
call selectionSort
in: ANY : data.array
in: type INT;

or:
call selectionSort
in: ANY : data.array
in: oneElementOfArray : ANY;

?
Thanks
 

Similar Topics

Compactlogix controller, program has 28 conveyors that use TON's to start the conveyors. The TT sounds a warning horn during start and the DN...
Replies
10
Views
485
Out of interest, I'd like some thoughts on what would be considered best practice with regards to a 2-position turntable control scheme (see...
Replies
17
Views
1,129
I'm looking for some starter kits but there aren't so many on the market, so I'm thinking about buying individual components for my needs. I just...
Replies
15
Views
2,446
I'm building a S7-300 rack to work on my Siemens Classic Step 7 programming skills. I've worked now and then with Siemens hardware, usually...
Replies
19
Views
6,503
Hello everyone, I am looking to get a job as a junior automation engineer. I know the basics of PLC programming with Rockwell and Siemens PLCs...
Replies
4
Views
1,771
Back
Top Bottom