PID Integrator component - pid

I'm trying to understand PIDs and there is just one thing in the general equation that I can't figure out, that is what does the Tau in the integration mean? in the pdf equation 10.1 there is
ki * integral[ e(tau) dtau ] but it doesn't say that it means by tau
http://www.cds.caltech.edu/~murray/books/AM08/pdf/am06-pid_16Sep06.pdf

Tau is just time. You're integrating that shaded area of the curve from tau = 0 to tau = t. You might see this written integral[e(t) dt]. But you can't write t here, because t is already in use in the equation. So tau is just a substitute for t. Doesn't matter what variable names you use. You're integrating over time.

Related

Taking array as an input to function in Haskell

I'm trying to learn Haskell and I stumbled upon a problem in my Haskell code. I have a function,
main = print (qSort [distance (3,4), distance (1,2), distance (2,2)])
distance :: (Floating a ) => (a,a) -> (a,a,a)
distance (x2 , y2) = (x2*x2 + y2*y2, x2, y2)
that calculates distance between (0,0) and given point. How can change it to something like:
main = print (qSort (distance [(3,4),(1,2),(2,2)]))
so that distance can take a whole array as input?
Also, what way will be the best to try and get the points as input from the user? Looking at examples I can't really think of a way to get points.
I've tried fiddling with square brackets, but I keep getting errors. Any help would be appreciated!
Try putting map distance instead of distance in the second code.
But you have to lookup and understand what map does!
In this case, map is telling distance Hey, man, you're promoted! Yeah, you don't just work on loosers pairs, (a,a); you work on lists of them, [(a,a)], all at once!
(The technical term for promoted is lifted, btw.)
If you're really at the start, I suggest that you go though some tutorial/book. LYAH is a very good place to start.

Getting points along a line given heading, starting point and distance between points

I am currently working on my research and coding my theories to simulate scenarios.
I need a way to incrementally find points along a given heading (angle between a line and the positive x axis) given the heading, the starting point, and the distance between the points. The new points should be in the direction of the heading. I am somehow facing a difficulty on how I should go about doing this.
With enough time I can come up with a way myself, but given that sharpening my coding skills is not my final outcome here and I would rather spend more time experimenting with my theory, I was wondering if anyone could help me find a solution. I am working with C, so a solution in C would be preferred and not one that uses library functions available in other languages.
One solution is to create a unit vector in the direction you want
for example lets say you want 45 degrees, the unit vector would be
<1/sqrt(2), 1/sqrt(2)>. this distance would be 1 since its a unit vector so you can scale it by the distance you want per point. so lets say you want each point to be 1/3 of a unit, then you would just multiply the unit vector and get
<1/(3sqrt(2)), 1/(3sqrt(2))> and then you can just do a loop. so if you want 10 points in that direction it would just be
unitvector = calculateUnitVector()
unitvector *= distanceBetweenPoints
for(i = 0 ; i < 10; i++){
drawPoint(startPoint + unitVector * i)
}
i hope this helps.

Q-Learning in combination with neural-networks (rewarding understanding)

As far as my understanding is, it's possible to replace a look-up-table for Q-values (state-action-pair-evaluation) by a neural network for estimating these state-action pairs. I programmed a small library, which is able to propagate and backpropagate through a self-built neural network for learning wanted target-values for a certain in-out-put.
So I also found this site while googling, and googling through the whole web (as it felt for me): http://www.cs.indiana.edu/~gasser/Salsa/nn.html where the Q-learning combined with a neural network is shortly explained.
For each action, there's an extra output neuron, and the activation-value of one of these output-"units" tells me, the estimated Q-value. (One question: Is the activation value the same as the "output" of the neuron or something different?)
I used the standard sigmoid-function as activation-function, so the range of the function-values x is
0<x<1
So I thought, my target value should always be from 0.0 to 1.0 -> Question: Is that point of my understanding correct? Or did I missunderstand something about that?
If yes, there comes following problem:
The equation for calculating the target-reward / new Q-value is:
q(s,a) = q(s,a) + learningrate * (reward + discountfactor * q'(s,a) - q(s,a))
So how do I perform this equation to get the right target for the neural network, if targets should be from 0.0 to 1.0?!
How do I calculate good reward-values? Is moving toward the aim more worth it, than going away from it? (more +reward when nearing the aim than -reward for bigger distance to aim?)
I think there are some missunderstandings of mine. I hope, you can help me to answer that questions. Thank you very much!
Using a neural-network to store q-value is a good extension of table lookup. This makes it possible to use q-learning when the state space is continuous.
input layer ......
|/ \ | \|
output layer a1 a2 a3
0.1 0.2 0.9
Suppose you have 3 actions available. Above shows the outputs from the neural network using current state and learned weights. So you know a3 is the best action to go with.
Now the questions you have:
One question: Is the activation value the same as the "output" of the neuron or something different?
Yes, I think so. In the referred link, the author said:
Some of the units may also be designated output units; their activations represent the network's response.
So I thought, my target value should always be from 0.0 to 1.0 -> Question: Is that point of my understanding correct? Or did I missunderstand something about that?
If you choose sigmoid as your activation function, for sure you output will be from 0.0 to 1.0. There are different choices of activation functions, e.g., here. Sigmoid is one of the most popular choices though. I think the output value being from 0.0 to 1.0 is not a problem here. if at current time, you have only two available actions, Q(s,a1) = 0.1, Q(s,a2) = 0.9, you know that action a2 is much better than a1 with respective to q-value.
So how do I perform this equation to get the right target for the neural network, if targets should be from 0.0 to 1.0?! How do I calculate good reward-values?
I am not sure for this, but you can try to clamp the new target q-value to be between 0.0 and 1.0, i.e.,
q(s,a) = min(max(0.0, q(s,a) + learningrate * (reward + discountfactor * q'(s,a) - q(s,a))), 1.0)
Try to do some experiments for finding a proper reward value.
Is moving toward the aim more worth it, than going away from it? (more +reward when nearing the aim than -reward for bigger distance to aim?)
Normally you should give more reward when it's close to the aim if you use the classical update equation, so that the new q-value gets increased.

Geodesic distance between two points

Is there a library in C that can calculate the geodesic distance between two points?
It's generally not necessary to compute geodesic distances up to centimeter accuracy as you'd have to model local geography to the same scale.
There are two cases I can think of where such accuracy might be desired:
you're actually interested in the straight-line distance and know exact coordinates, including height above sea level
you're working with a toy model and are interested in general properties, not practical applicability
In the first case, I'd transform from geographical coordinates (φ,λ,h) to geocentric cylindrical coordinates (r,z,λ)
r = (a²/k + h)·cosφ
z = (b²/k + h)·sinφ
λ = λ
where
k = √(a²·cos²φ + b²·sin²φ)
In the second case, I'd use Vincenty's formulae.
You can find (hopefully correct) C implementations of both algorithms under my bitbucket account.
Yes, I've ported the geodesic routines in GeographicLib to C. See
http://geographiclib.sourceforge.net/html/C/index.html

Angle at corner of two lines

I search for the fastest or simplest method to compute the outer angle at any point of a convex polygon. That means, always the bigger angle, whereas the two angles in question add up to 360 degrees.
Here is an illustration:
Now I know that I may compute the angles between the two vectors A-B and C-B which involves the dot product, normalization and cosine. Then I would still have to determine which of the two resulting angles (second one is 180 degrees minus first one) I want to take two times added to the other one.
However, I thought there might be a much simpler, less tricky solution, probably using the mighty atan2() function. I got stuck and ask you about this :-)
UPDATE:
I was asked what I need the angle for. I need to calculate the area of this specific circle around B, but only of the polygon that is described by A, B, C, ...
So to calculate the area, I need the angle to use the formula 0.5*angle*r*r.
Use the inner-product (dot product) of the vectors describing the lines to get the inner angle and subtract from 360 degrees?
Works best if you already have the lines in point-vector form, but you can get vectors from point-to-point form pretty easily (i.e. by subtraction).
Taking . to be the dot product we have
v . w = |v| * |w| * cos(theta)
where v and w are vectors and theta is the angle between the lines. And the dot product can be computed from the components of the vectors by
v . w = SUM(v_i * w_i : i=0..3) // 3 for three dimensions. Use more or fewer as needed
here the subscripts indicate components.
Having actually read the question:
The angle returned from inverting the dot-product will always be less than 180 degrees, so it is always the inner angle.
Use this formula:
beta = 360° - arccos(<BA,BC>/|BA||BC|)
Where <,> is the scalar product and BA (BC) are the vectors from B to A (B to C).
I need to calculate the area of the circle outside of the polygon that is described by A, B, C, ...
It sounds like you're taking the wrong approach, then. You need to calculate the area of the circumcircle, then subtract the area of the polygon.
If you need the angle there is no way around normalizing the vectors and do a dot or cross-product. You often have a choice if you want to calculate the angle via asin, acos or atan but in the end that does not make a difference to execution speed.
However, It would be nice if you could tell us what you're trying to archive. If we have a better picture of what you're doing we might be able to give you some hints how to solve the problem without calculating the angle at the first place.
Lots of geometric algorithms can be rewritten to work with cross and dot-products only. Euler-angles are rarely needed.

Resources