EP3 - The PLC Task and Scan Times
Video: https://youtu.be/srTISZQgH5I
#PLC #TwinCAT3 #Beckhoff #Industrial_Automation
Table of Contents:
A) How to Open a Measurement Project (ScopeView)
Welcome back! This is episode 13 of learning motion control with PLC's.
On this episode I wanted to show you a tool that I've used for not only motion control but just throughout all the machines that I've program. It's just been completely invaluable.
That tool is the TwinCAT Scope View,
Note: this is now called the measurement scope in TC3
So what you do is create a new project in XAE
A.1) How to Setup a YT Scope
Now, do a new Scope YT Project so that's a Y-axis and Time,
So I'm gonna go ahead and make a new project,
and when it loads up you have this project right there,
So you could bring this into your other solution if you want,
but I'm gonna keep them separate now, no big deal
A.1.1) Selecting Variables for Data Measurement
Okay so the first thing we want to do here is add some data to our graph,
and we'll do that by going into the target browser
These are gonna be all of your routes that you've set up,
so you can scope from a bunch of different sources at the same time and all on one one graph it's pretty awesome .
you see my local machine here,
It doesn't help us much because we're running on a remote PLC.
So in here we've got our PLC task,
our NC task (which would be what's running the axes),
and then port 851.
Note: Back on TC2 every run time used to run on 801, 802, 803, and 804 because you are allowed up to four PLC runtimes concurrently with TwinCAT and I believe that's a per core thing so if you had two cores you could run eight tasks.
I've rarely found much of a need to run more than one run time other than collaborating between programmers and having basically being able to modularize your code into a run time, but it usually causes more grief than you really want to deal with.
So anyway that's why we're on port 851, it's always going to be there by default but you can change it if you want.
So this hopefully will look familiar,
We've got global variables,
just a whole lot, everything global in the system is going to show up in this list, we haven't defined any really in our project thus far.
So MAIN is here,
this all should look very familiar. This is our declarations from the top of the other program, so we're gonna add in a few things that we're using.
This velocity command is just my foot pedal once I've scaled it, so I'm going to add that by double clicking it.
I'm going to come down and find Axis B here, and select NcToPlc,
this is we're gonna get our status of our motor, so what we want to find here is actual position,
and we should be able to find where is actual velocity,
that should be enough to get going for now.
Let's head back over to MAIN and I'm gonna grab iState,
just because I like watching the state. That's something that's been incredibly helpful to watch machinery and you know watch sensors and find out if a sensors flickering on you and stuff like that, so let's get this going now.
Great, here are our variables,
A.1.2) Changing Settings for the Chart Display
One other thing I like to do on here if you click on the chart itself,
you have a default display width,
I'm gonna kick that up to about 30 seconds,
and then if you go up one more level to the project,
you've got still more settings, so we have a record time here,
kick that up to 60 seconds,
and this runs in your local computers memory so you can record you know 30 minutes if you want it depending on your scan rate and stuff like that and you can set skip rate and all that.
And ring buffer let's turn to true,
because then we can just trigger our our chart here in a second, and then we'll just manually trigger it out whenever we want and it's not going to fill our computer up it will just keep one minute of data and it'll drop the last second off as it predicts on the next second and so on.
A.1.3) Start Recording and Test our Program
So I'm ready to start recording there's this record up here,
so as soon as you have your variables defined you can go ahead and hit record.
And it will get online with the PLC over ATS and start pulling data,
Okay so now that the scope is running I still have my PLC set up ready to run with the program we made in the last video,
so I'm going to push the foot pedal down and we'll watch it run.
okay let's run it one more time,
Okay so that got us some data, I'm gonna stop our graphing we'll take a look at it,
A.1.4) Stop Recording and Analyse the Graph
Alright so hopefully you can see we've got some decent data here,
A.1.4.1) Changing the Background Color of the Chart
I'm actually gonna turn this chart black because I just like looking at it better that way,
A.1.4.2) Walkthrough of the Plot values
So this red line now is where my foot pedal crossed the threshold and started off the state machine so you can actually zoom in on that and we'll see right is when we cross threshold somewhere around here you'll see the state rise up on the very next PLC scan as it moves across here so this shows us around and let's see what it actually looks like yeah state 300 state 310 okay so it is actually rounded off there it seemed a little weird for a second there but what what we're looking for really
this is the state machine as it traverses across and it goes up and then there's our loop and then we go to state 500 so you can really use this to visualize machine cycles and find out like any long section like this you can go and say well what is taking that long does it match my design time is there something going wrong is there a sensor it's waiting for that it only needs to see briefly you know all that sort of stuff you can figure out with these grafts so hopefully that's pretty obvious how useful this can be but let's
look at our motion here real quick zooming in a little more got this blue here that is a trapezoidal move which we talked about in the last video so we accelerate up we hit our commanded velocity max which is 100 we traverse at that all the way over until we have to decelerate to make our zero point and we hit zero and so very quickly we jump back up this is so we see a pretty linear move there most of the time and then this position sort of sinusoidal there because we have these triangular moves and you can see
just a small nub there where our software is doing its work that or this is uh likely if you look back at this move here let's see let's zoom back in on the very leading edge of this trapezoid you can see a tiny bit of jerk limiting happening here so if this was a perfect slope then I mean this is the feedback velocity so we could have a little bit of like inertia stuff going on but this is very likely the jerk slowing down our a cell ramp so that's just the position is in green these are the velocities in blue and the
acceleration is the slope of the blue line could have mapped acceleration as well from the in-situ plc but we don't need to I think you get the gist here so I wanted to show you guys this the ring buffer option is good to know about and of course let's do cover cursors real quick so you right-click and cursor window has to be showing here it helps to show it because that's where you're gonna actually get your data but a little bit counterintuitive here you have to add a new cursor so I'm going to
add this one use bright green but you could change this color if you wanted so as I move along here let's change them to something darker so make sure you guys can see it a lot of colors dark magenta so we take our dark magenta cursor and we can walk it along here if you watch something like current velocity here you can just walk it right along and see it every scan of the PLC with our time here we can look at and every scan of the PLC we can see what that value is and doing that sort of thing for you know debugging analog systems is really
amazing so this is the scope view there's a professional version of it that gives you some reporting capabilities and things like that and you can actually trigger these from the PLC with some function blocks and export them automatically if you pay the licensing fee to do that but even without paying licensing fee this comes free with twin cats engineering xae stuff that you use to program their hardware and so you can do most of this right out of the box and get a ton of visibility into what's happening inside your code because a lot
of these state transitions are happening in two milliseconds three milliseconds whatever your scan time is and actually right now mine's at ten but still these things happen so quickly there's no way you'll be able to see it so looking at this code it's a great way to handle that as well as just moving back to the main program there you can put timers in all of these states and record them so you have state transition times history stuff like that so I've found that using a combination of a state history array
which I believe we talked about in the first PLC series but using a combination of a state history array and timers for moves and things like that instrumenting your code and then also being able to go and scope it those two things together make debugging and you know post-mortem analysis really nice so that's basically it that I wanted to show you on that and we will move on to some other motion types in the next video or at least I'll talk about them we're getting pretty well wrapped up with actual motion demos and things with
my tests and so with that said I'll see you in the next video and we'll talk about NCI and CNC machines and stuff like that get you on that one bye
Z) 🗃️ Glossary
File | Definition |
---|
Uncreated files | Origin Note |
---|---|
Next Part 🔜 | EP3 - The PLC Task and Scan Times |
Next Part 🔜 | EP3 - The PLC Task and Scan Times |