EP13 - Scope View
Video: https://youtu.be/phwl3J8G7QY
#PLC #TwinCAT3 #Beckhoff #Motion_Control #Scope_View #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 (Port 851) 🔍
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 (display width, record time and ring buffer) 🔍
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) Walk-through of the Plotted Values and the Zooming In Tool
A.1.4.2.1) The Foot Pedal and the State Machine
Remember:
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 when we cross threshold somewhere around here.
you'll see the state rise up on the very next PLC scan.
Let's see what it actually looks like,
yeah state 300, and then...
state 310 okay so it is what we expected.
Now we can zoom out,
So, what we're looking for really 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 sections that could be unusual.
Like when we reach State 500, 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.
A.1.4.2.2) Motion (Velocity and Position)
Remember:
Let's look at our motion here real quick zooming in a little more got this blue velocity 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,
also we see in green a pretty linear change in position 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 out,
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.
A.1.4.3) Using Cursors 🔍
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 counter intuitive here you have to add a new cursor so I'm going to add this one,
and select it,
right now it shows as a bright green,
but you could change this color if you wanted,
so as I move along here and we take our dark magenta cursor 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....
A.2) Final Thoughts and Debugging Ideas
There's a professional version of it that gives you some reporting capabilities and things like that.
More here
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 the licensing fee, this comes free with TwinCAT's engineering XAE stuff that you use to program their hardware. 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.
B) Next Episode
So that's basically it all 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.
Z) 🗃️ Glossary
File | Definition |
---|