Ann, You are spinning your wheels. You can't do a simulation with function in the time domain is you don't know what the input is going to be ahead of time and you don't because the input comes from a fuzzy controller. All these posts about time domain are NA for simulating how your plant will respond to your fuzzy logic controller.

See my previous post about the difference equations. You need to convert from the s domain to the z domain and then to a difference equation. A difference equation is an equation that computes the output based on a history of outputs and inputs. Each time period you calculate x(n) using the difference equation and you also calculate a u(n) using your fuzzy controller. Computers do their calculations using discrete time periods. I could tell you what the coefficients for the difference equation should be right now but that would take the fun of discovery out of it.

Each half second you are going to update the output of the fuzzy controller and feed it into the plant and then you can monitor to response. The new u(n) and x(n) will then be use to calculate the next u(n+1) and x(n+1). If your controller works x(n) will reach the set point at .65.

Your next should be how do you calculate the difference equation coefficients. Do you already have the fuzzy controller done?

You have lost 4 days now.

Peter Nachtwey Guinness isn't the same over here. :(

I'm sorry that I sound so stupid, my background is in computer science. The most frequently used experiment in fuzzy logic control is the inverted pendulum, and I have been working with that since I started.

Can you please look at this graph and equation

formatting link

and explain to me how the author goes from one to the other

I haven't had time to test it but try setting u to be fixed at 650. x(n) should rise to 65 and stay there is the steady state gain for your system is .1 If it does then try your fuzzy controller.

I haven't looked at the graph yet. I just got back from a piano recital by Lang Lang that has me still bemused.

You don't sound stupid at all, just more ignorant than you know and therefore confused. A little reading up on the tools you will use will go a long way toward dispelling that confusion. bed calls too urgently for me to give a course on getting the time response to a stimulus when the frequency response is known, or even what those terms mean. Suffice it to say for now that linear circuits' time behavior can be described by differential equations, and that difference equations are the discrete-time analogs of differential equations. (Summation stands in for integration.)

Read the z transforms article* on my website, if you haven't already. It is written to be understandable for folks from a computer science background who haven't forgotten their first few weeks of calculus. While brief, it does outline the similarities and differences between a signal and a system, and their respective representations in the z domain. All of these distinctions apply to the Laplace transform should you wish to derive it from the z transform (or from first principals).

If you find it helpful, I have a brand new book** out there which is aimed at you, the software engineer who suddenly needs to understand control theory. It explains the z transform in more detail, it goes into more detail about signals, their transforms, systems, transfer functions, and why transfer functions look like transforms of signals. It also covers the Laplace transform as well as a couple of methods for finding the z-domain transfer function of a continuous-time system that's bracketed by an ADC and a DAC.

I strongly recommend that you don't limit yourself to asking questions about control issues and trusting the answers you get. Like it or not, you are working on a control problem. You have a huge pile of prior art that you are ignoring -- you should at least seriously scratch the surface of it, rather than turning a blind eye.

Think of it this way: what will you do if you go to defend your thesis and there's someone on your committee who understands control theory, sees the closed loop controller, and starts raking you over the coals for it? Would you rather be able to show that you understand the basics, including traditional controllers for inverted pendula, or would you rather be reduced to a stammering demonstration of ignorance?

Tim, does your book have a complete set of Laplace to z transforms conversion. Your z transform page doesn't have the one that I used to calculate the difference equation above. I looked on the internet and could not find a good set z transform tables either. Fortunately I have my own tables or can calculate them by other means.

A warning to Anne. The difference equation above only works at .5 second updates. However, .5 seconds isn't really fast enough to do a good simulation. The update time isn't quite fast enough for the response of your system. At .1 second the closed loop response looks smooth and critically damped. The .gif you posted doesn't look that good. Try the .5 seconds just to see if you can match the results in the .gif but I would switch to .1 sec intervals for really testing the fuzzy controller.

A question for anybody. Does Octave use ordinary text that can be cut and pasted into these newsgroup threads? It would make doing examples easier.

It describes how to do the conversion. The method I present takes the zero-order hold action of the DAC into account -- the 'impulse invariance' method is cool theory, but unless you have a DAC that outputs impulses it's not too useful in real life.

The method is simple, and the results are exact, not an approximation: Find the Laplace domain step response, break it down into the time response elements, take it back up to the z domain using the appropriate sampling rate, then multiply by (z-1)/z.

Easier yet is to use MathCad, but you have to do the final multiply by cut and paste. I know that SciLab will do this in a snap; I believe Octave will but I don't know the commands.

The rule of thumb is to choose a sampling rate that is 10 times the highest frequency of interest in the system. For an unstable system like an inverted pendulum you'd probably want to choose to have the unstable pole be at no more than z = 1.1, which means to choose a sample interval that's 1/10 the coefficient of your unstable pole in the Laplace domain.

Yes. But I suggest you consider SciLab. It seems to be under more current development, I had a much easier time getting it working on my PC, and the scripting language is more object oriented. It's very control system oriented -- in fact, both state-space representations and polynomial transfer functions are native types.

But F(s) is the Transfer function ....i.e. the Laplace transform of the output divided by the input (X/U) -so- in order to find x(t) you need to multiply the Transfer function by the LT of U and *then* take the inverse

If the input is a constant value with time - it can be modelled as a step input (LT of 1 = 1/s ....which is an integration in the time domain!)

Leaving you with the problem of finding the inverse transform of:

for U(t) =1 for t >0 .....otherwise zero

X(s)= U(s)*F(s) = (1/s)*F(s)

Which in Partial fractions issss

A/s + B/s+0.15 + C/s+0.25 = 1/s*F(s)

Work it out! Then find the inverse transform - which should look like

x(t) = 1 - K1e^-at +K2e^-bt

EEEK

The controller value U is 'multiplied' by the Transfer function F(s) - as above

Ann, you are getting lots of bad advice and I don't think you are able to sort the good from the bad.. You DO NOT need to convert your transfer function in the s domain to the time domain. This non sense has set you back days and confused you. You need a difference equation. I do the same thing you are trying to do to test my control algorithms. I have a link to a pdf file that shows how I would simulate the control of your systems using a PID ( I-PD). ftp://ftp.deltacompsys.com/public/PDF/Mathcad%20-%20t0p2%20simple%20z%20NG.pdf This was done using Mathcad. You only need to replace my I-PD algorithm with your fuzzy logic algorithm and you are home free.

Notice the wavy control output ( the green line ). This line is much smoother if you reduce the sample time T from .5 second to .1 seconds. Also notice that the I-PD control is much better than the fuzzy logic example. This may be due to the slow update rates.

What is the frequency of interest? That is vague. Is the frequency of interest the highest open loop pole or the highest closed loop poles or the higher of the two. I use the higher of the two and 10 times is a bare minimum. Anne has a pole at .25 radians per second in her open loop system. The closed loop poles, in the solution I posted in the .pdf file, has a frequency of .5 radians/sec. .5 radians per second has a time constant of 2 seconds. Ann's sample time of .5 second is not 10 times higher than 2 seconds.

I agree with you that the digital method is neccessary in this case

Not sure how you arrived at the above difference equation Peter (What sampling period did you use??)

Anyway the kind of digitising process I use is as follows -for your system

X(s)= (0.00375/((s+0.15)*(s+0.25)))*U(s) Expands to

X(s)[s^2+0.4s+0.0375] = 0.00375 U(s) Which is the Laplace transform of the DE

x''(t)+0.4x'(t)+0.00375x(t) = 0.00375u(t) Which is a Linear DE of second order

Which is the best place to start talking about a dynamic system

Digital Domain

The variable z strictly arises from a discrete-time summation expression, related to the integral definition of the LT. z is usually *approximated* by various substitutions for s in the LTF The simple method is to replace 's' (A differentiator in the complex frequency domain) with

s=(1-z^-1)/Ts

Consider x' = [x(n)-x(n-1)]/Ts Ts = the sampling (1) interval

If z^-1 is taken as the Shift Operator -then the equivalent to (1) is:

x' = x(n)[1-z^-1]/Ts Which proves to be an extremely useful notation

For YOUR equation

X(s)[s^2+0.4s+0.0375] = 0.00375 U(s)

You have a choice of substitutions for s (other than the above) namely

Assume a zero order hold on the input (output from the controller is constant between samples) This sounds like the logical course to take -at least initially

The Tustin or Bilinear Transform

Prewarping

for 1. The z transform of your LT at a sampling frequency of a=0.1, b=0.01, c=0.001 is:

Transfer function:

1.85e-005 z + 1.826e-005

------------------------ z^2 - 1.96 z + 0.9608

Sampling time: 0.1

Transfer function:

1.873e-007 z + 1.87e-007

------------------------ z^2 - 1.996 z + 0.996

Sampling time: 0.01

Transfer function:

1.875e-009 z + 1.875e-009

------------------------- z^2 - 2 z + 0.9996

Sampling time: 0.001

There are several reasons for the other methods which are embedded in the transfer between domains and the frequencies of interest in your system Other practical considerations are the time it takes the controller to do the control calculation which is an inherent delay that must be dealt with.

I have plotted the above and they all have the same response to a step input - (which is the same as the analogue system) which indicates that the model is at least accurate for this input - The frequency response of the system should also be considered.

The above can be converted directly to the difference equation by simple algebraic means and all of these have the same form as Peters system:

x(n) = a*x(n-1) - b*x(n-2)+ c*u(n-1)+.d*x(n-2)

I'm sure i've missed loads but I think if you can get your head around this in a short time you are doing well -

Some one said earlier that you were getting bad advice here - I dont think that is true.....You did ask how to solve the LT and that is a good place to start before taking the process to z transform - difference equation - algorithm

My newsreader software marks the message for deletion in our local (off-line) newgroup message database. Why? What were you hoping might, perhaps, happen?

With my browser, I get the message, "Do you really want to delete this message?" If I say yes, another message appears that reads, "Message deleted." and it disappeared from my news server and shortly thereafter, all cooperating news servers. Not all news servers honor deletes. Google does not.

If the message doesn't originate with me, the message is instead, "This message doesn't appear to have come from you" and that's the end of it.

I thought that might be it. My newsreader has a delete capability. I've given it a whirl. OTOH, what I wrote wasn't too bad, so its no great disaster if it circulates, I guess.

That's why it's a rule of thumb, and not a hard-and-fast rule. For folks who have the wherewithal to do the math I suggest investigating performance at different sampling rates to see which one seems best.

That's what I use, also. I shade it down if it's a _very_ well behaved plant, and don't hesitate to go up if the plant has nasty nonlinearities (which indicates that any apparent open loop 'pole' is going to be moving around) or if the precision requirements are great.

Yes, I agree with you there -- I was giving her the rule of thumb so she'd know to set the sample rate higher. With an unstable pole in the system I'd go higher yet, to 20 or even 50x, assuming I had the processor resources to do it.

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.