Lab 3

A. First, spend a few minutes doing control manually for your double integrator:

Your objective is to manually control the input signal (torque, tau) by twisting the potentiometer, to bring the output signal (angular position, theta) to a desired value of 2, and keep it there, as soon and as well as possible after each reset.

Set up the scope so you can see theta and omega on channels 1 and 2. To avoid confusion, shift the traces so they don't overlap.

Ideally, you would trigger the scope at each "reset", so the traces would always restart from the left edge. Unfortunately, as far as I can tell, you can only get these scopes to show a continuous display when the time axis is free running, not when it is triggered. When it is triggered the scope waits until the whole sweep is complete before displaying it, and that of course gives you no guidance in controlling your potentiometer. If you solve this problem let me know.

If you are bad at being a controller, you may want to increase the time between resets.

Once you get good at being a controller, quantify your performace: how quickly can you acheive theta=2 (with omega=0), and how accurate are you.

B. Now, replace yourself with a digital controller. Write a program (under QNX) which does the following:

1. Reset the integrators (use a digital output to bring the Reset line to ground for 100mSec).

2. Read the angular velocity (omega) and angular position (theta) signals every 50mSec, for 5 seconds in total. (100 iterations)

3. Create an error measure epsilon = 2 - theta (because 2 is the desired value for theta)

4. Use PD control to form actuator input (torque, tau), with control gains Kp and Kd. Output tau to your analog computer. Be sure to respect the actuation limit of +/- 2 volts.

5. Accumulate in arrays the time t, actuator input tau, and plant outputs omega and theta.

6. Pick arbitrary value for Kp and Kd, and run the controller, monitoring results on the scope.

C. (optional) Use Stanley Tsao’s internet code to transmit your dataset (400 floats) from QNX to Matlab. On the Matlab side, wait for a dataset, clear a graph and draw the dataset. Repeat automatically, so that every time matlab receives a dataset it immediately draws it.

D. Get QNX threads working.

Turn your "real-time" code above into a thread that repeatedly does the reset and 100 iterations of control.

The RT thread should be launched (just once) by a more ordinary “user interface” thread.

The user interface thread then requests from the user values for Kp and Kd (use scanf for keyboard input). The new values of Kp and Kd immediately affect the realtime thread.

Tweak the values of Kp and Kd on the fly, to get the best performance.

Did your controller use omega as measured, or did it compute omega from dtheta/dt? If you wish, try it the other way.

Document your work and results. Compare to your ability to control this plant manually. Print your graphs for good & not so good choices of Kp and Kd, and zip & email your code.