designLab04.pdf

4
1 Design Lab 4 6.01 – Spring 2013 Hitting the Wall Goals: The goal of this lab is to understand fundamental limits on how quickly and accurately the robot can move from one location to another. We will find that achieving either speed or accuracy is easy, but achieving both simultaneously is difficult (or impossible). In this and the next two labs, we will explore increas- ingly sophisticated control schemes to improve performance. Do this lab with your assigned partner. Get today’s files. Open a terminal window (press ctrl + alt + t) and type > athrun 6.01 getFiles to set up files for today’s exercises in your Athena directory. These files are also available under the “Calendar” tab of the 6.01 website. 1 Proportional controller We wish to program the robot to move toward (or away from) a wall, so as to adjust its position to be half a meter from the wall. One strategy (which is called “bang-bang” control) is to move forward (with a fixed velocity V ) when the distance is greater than half a meter, and to move backward (with the same speed but opposite direction) otherwise. Check Yourself 1. What is good about this strategy? What is bad about it? A more sophisticated strategy is proportional control. In this strategy, the robot’s velocity is made proportional to the difference between its desired distance to the wall and its actual distance to the wall. We will call the proportionality constant K the gain. Implement a proportional controller by completing the definition of the step procedure in wallFinderBrain.py. Test your code with soar in the wallFinderWorld.py. When you stop the simulation, soar will plot the sequence of distances to the wall during the run. Find three different values of K: one for which the distance converges monotonically, one for which it oscillates and converges, and one for which it does not converge. monotonic convergence oscillatory convergence does not converge K= Make plots for each of these K values. Email your code and plots to your partner. Checkoff 1. Show your controller code and plots to a staff member, and discuss which gains generate which results, and speculate why.

Transcript of designLab04.pdf

Page 1: designLab04.pdf

1

Design Lab 4 6.01 – Spring 2013Hitting the Wall

Goals: The goal of this lab is to understand fundamental limits on how quickly andaccurately the robot can move from one location to another. We will find thatachieving either speed or accuracy is easy, but achieving both simultaneously isdifficult (or impossible). In this and the next two labs, we will explore increas-ingly sophisticated control schemes to improve performance.

Do this lab with your assigned partner.Get today’s files. Open a terminal window (press ctrl + alt + t) and type> athrun 6.01 getFilesto set up files for today’s exercises in your Athena directory. These files are also available underthe “Calendar” tab of the 6.01 website.

1 Proportional controllerWewish to program the robot tomove toward (or away from) awall, so as to adjust its position to behalf a meter from the wall. One strategy (which is called “bang-bang” control) is to move forward(with a fixed velocity V) when the distance is greater than half a meter, and to move backward(with the same speed but opposite direction) otherwise.

Check Yourself 1. What is good about this strategy? What is bad about it?

Amore sophisticated strategy is proportional control. In this strategy, the robot’s velocity is madeproportional to the difference between its desired distance to the wall and its actual distance to thewall. We will call the proportionality constant K the gain.Implement a proportional controller by completing the definition of the step procedure inwallFinderBrain.py. Test your code with soar in the wallFinderWorld.py. When you stopthe simulation, soar will plot the sequence of distances to the wall during the run.Find three different values of K: one for which the distance converges monotonically, one for whichit oscillates and converges, and one for which it does not converge.

monotonic convergence oscillatory convergence does not converge

K =

Make plots for each of these K values. Email your code and plots to your partner.

Checkoff 1. Show your controller code and plots to a staff member, and discuss whichgains generate which results, and speculate why.

Page 2: designLab04.pdf

Design Lab 4 6.01 Spring 2013

2

2 Modeling Behavior with Difference EquationsThe brain/robot system you just experimented with is an example of a simple control systemwitha single input (the desired distance to thewall) and a single output (the actual distance to thewall).We can think of the control system as having three subsystems: the “controller,” the “plant,” andthe “sensor.”

controller plant

sensor

+X Yerror command

Figure 1 Structure of Control System.

For today’s lab, the controller is the robot’s brain, the plant is the part of the system that is beingcontrolled (i.e., the robot’s locomotion system, whose input is an io.Action and whose output isthe robot’s position), and the sensor is the robot’s sonars.Make a mathematical model of the wall finder system as follows. Let do[n] (the ’o’ stands foroutput) represent the current distance from the robot to the wall, and let di[n] (the ’i’ stands forinput) represent the (current) desired distance to the wall. Also let v represent the forward velocityof the robot. Let T = 0.1 seconds represent the time between steps.

di[n]do[n]

When the robot receives a new command, we assume that the robot immediately changes its ve-locity and then holds the new velocity constant until it receives the next command (i.e., the robotaccelerates so fast that we can ignore the acceleration time).

Check Yourself 2. Given the following conditions, what is the distance to the wall on step 1?v[0] = 1 do[0] = 3

v[1] = 2 do[1] =

Assume the system has the structure shown in Figure 1. Assume that the sensormeasures the cur-rent distance do[n] and generates the sensed distance ds[n], which is equal to the current distancedelayed by one step time. Let e[n] = di[n] − ds[n] represent the error signal, which is the differ-ence between the input distance di[n] and the sensed distance ds[n]. On each step, the controllercommands a forward velocity v[n] in proportion to the error so that v[n] = Ke[n].

Check Yourself 3. Fully label the following diagram. Include do[n], di[n], ds[n], v[n], e[n].

controller plant

sensor

+−

Page 3: designLab04.pdf

Design Lab 4 6.01 Spring 2013

3

Determine difference equations (using constants T and K) to relate the input and output signals ofthe following system components.

• the controller

• the model of the plant

• the model of the sensor

Make block diagrams for each of the elements in the system. Use only delays (R), gains, andadders. Enter your diagrams in the boxes below.

+++ −0.1

−1

+ R

R−1

+ −5 −0.1 + R

R−1

Di Do

controller plant

sensor

Combine these equations to derive a single difference equation for the system. Solve the differenceequation for the current output do[n] in terms of• previous values of the output (do[n− 1], do[n− 2], ...) and• current and previous values of the input (di[n], di[n− 1], ...).

do[n] = ∗ do[n− 1]+ ∗ do[n− 2]

+ ∗ di[n]+ ∗ di[n− 1]+ ∗ di[n− 2]

Checkoff 2. Explain your system diagram and difference equations to a staff member.

Page 4: designLab04.pdf

Design Lab 4 6.01 Spring 2013

4

3 Simulating Behavior with State MachinesWe can use the state machine class developed in software lab 4 to simulate the behavior of thewallFinder system. We have provided a template file called wallFinderModel.py. The templatefile will automatically load staff versions of the SM class from Software Lab 4. We recommend thatyou use these staff versions while you are developing your new code. If you have time at the endof this lab, it would be very cool to use your own versions of this code instead of ours.

Write a procedure called wallFinderModel that takes two inputs — the gain K, and the initialdistance to the wall start — and returns a state machine. Run the state machine to simulate theresponse of the wall finder system as it approaches its final location, half a meter from the wall.Code to generate plots has already been included in wallFinderModel.py. To make plots, startidle with the -n switch,

> idle -n

Simulate the behaviors for the same gains you used in Checkoff 1. In what ways are the statemachine simulations similar/different from results from soar?

4 Limitations of the ModelThere are several features of the robot that are built into soar but not in the simple block dia-grams. For example, the speed of the robot is limited by its motors to approximately 0.5m/s. Thislimitation is not built into our simple state machine models of ideal delays, adders, and gains.

One way to reduce the effects of the velocity limitation is to move the starting position of the robotcloser to the desired location. A world called wallFinderCloseWorld.py has been provided forthat purpose.

Compare results for wallFinderCloseWorld.py to the statemachinemodel. What featuresworkbetter/worse relative to wallFinderWorld.py?

Checkoff 3. Explain your plots for the state machine simulations to a staff member. Ex-plain how these plots are similar/different from those from soar (Checkoff1). Speculate on why the results might differ.