Unformatted text preview:

6.01, Spring Semester, 2008—Assignment 4, Issued: Tuesday, Feb. 26 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.01—Introduction to EECS ISpring Semester, 2008Assignment 4, Issued: Tuesday, Feb. 26Overview of this week’s workIn software lab• Work through the software lab.• Submit whatever work you have finished at the end of the lab into the tutor.Before the start of your design lab on Feb 28 or 29• Read the class notes and review the lecture handout.• Do the on-line tutor problems in section PS.5.2.• Read the entire description of the design lab, so that you will be ready to work on it whenyou get to lab.In design lab• Take the nanoquiz in the first 15 minutes; don’t be late.• Work through the design lab with a partner, and take good notes on the results of your work.At the beginning of your next software lab on Mar 4 or 5• Submit online tutor problems in section PS.5.3.• Submit written solutions to software lab, and to all the design lab questions. All written workmust conform to the homework guidelines on the web page.• You will need SoaR in this software lab, so if you don’t have SoaR installedon your own machine, use a lab laptop or Athena station.• Get the lab4 files via athrun 6.01 update or from the home page. We havegiven you several that have Skeleton in the name. You should make a copyof those files and rename them to remove the Skeleton. You will get failingimports otherwise.6.01, Spring Semester, 2008—Assignment 4, Issued: Tuesday, Feb. 26 2Software Lab: Combinations of state machinesIn class we discussed three methods of making new state machines out of old ones: serial composi-tion, parallel composition, and feedback composition. Below (and in the file SimpleSMSkeleton.py)is the skeleton of the SerialSM class. We’ve provided the constructor method, which take statemachines as input and construct a new, composite state machine.class Ser ialSM :def __init_ _ ( self , sm1 , sm2 ):self . m1 = sm1self . m2 = sm2# Be careful to kee p the timing con s ist e nt . The input to m2 has# to be the c urren t outpu t of m1 , not the ou t p u t after it is# step p ed .def step ( self , input = None ):# Y o ur code heredef c urr entO utp ut ( self ):# Y o ur code hereQuestion 1: Write the step and currentOutput methods for a serial SM. Test it by combiningtwo incr machines (the definition is in SimpleSMSkeleton.py). Draw a picture showinghow the machines are connected. First, figure out what the result ought to be by filling outa table like this one (remember that, by definition, output1= input2:step input1state1output1state2output20123Then test to be sure your machine is doing the right thing.Question 2: Compare the results of composing a sum machine (defined inSimpleSMSkeleton.py), which outputs the sum of all of its inputs so far with anincr machine. Predict what the result ought to be by filling out a table like this one:step input1state1output1state2output20123Then be sure you’re getting the right result.6.01, Spring Semester, 2008—Assignment 4, Issued: Tuesday, Feb. 26 3Feedback The following class defines a feedback state machine. Its init method takes a statemachine, sm, and returns a state machine with no inputs, which consists of sm with its output fedback to its input. We’ll define the output of the feedback machine to be the same as the output ofsm.class Fe edba ckSM :def __i nit__ ( self , sm ):self .m = smdef step ( self , input = None ):return self . m . step ( self. m . c urr ent Out put ())def c urr entO utp ut ( self ):return self . m . c urr ent Out put ()Now, we can use this to couple two machines together, with the outputs of one machine serving asthe inputs to the other, and vice versa.def si mul ator SM (m1 , m2 ):return Feed back SM ( Ser ialSM (m1 , m2 ))Question 3: In the code file, you’ll find the definition of makeIncr, which takes an initial stateas an argument, and then thereafter updates its state to be its input plus 1. If we make thefollowing coupled machine, we get a potentially surprising string of outputs:>>> fizz = simul ator SM ( makeIncr (10) , ma keInc r (100))>>> run ( fizz )1001110213104151061710819110Explain why this happens. Draw a picture of the objects involved in this machine and sayexactly what state variables they contain. Fill in a table describing the inputs, states, andoutputs of each component machine at each step.6.01, Spring Semester, 2008—Assignment 4, Issued: Tuesday, Feb. 26 4Question 4: Imagine a robot driving straight toward a wall. We would like to use a statemachine to model this system, where the state is the distance from the robot to the wall inmeters (pick an initial distance for your initial state) and the input is the robot’s currentforward velocity in meters per second. Assume that each state transition corresponds to thepassage of 0.2 seconds. Write a primitive state machine to model this system. Hint: thedistance should go down as the machine steps.Question 5: Now, let’s think of the controller that this robot might be executing. Assume therobot would like to stop at some distance dDesiredfrom the wall. The controller can bemodeled as a state machine that receives, as input, the current distance to the wall andgenerates, as output, a velocity. For now, assume there’s no inertia involved, and so thecontroller can choose any new velocity it wants, independent of its previous velocity. Inparticular, let’s assume it selects a new velocity that is equal to k(d − dDesired), where dis the current distance to the wall, dDesiredis the desired distance to the wall, and k is a“gain” constant. Write a primitive state machine to model this controller.Question 6: Now, use the simulatorSM function to put these two machines together. Run thecoupled machine. Try a large value of k and a small value of k. What happens? (By settingSimpleSM.verbose to True, you can get PrimitiveSM.step to print out information abouteach step of each primitive machine.)Question 7: You can plot data from inside soar. If all you want to do is plot, the bestthing is to make a brain with only a setup method, and put your plotting commands inthere. Then, when you run the brain, you’ll see your data plotted in a window. TheSimpleSMBrainSkeleton.py file defines a setup function that will plot some data.We have modified run, in the SimpleSMSkeleton.py file, so that it returns a list of all theoutputs generated by the machine. So, you can just


View Full Document

MIT 6 01 - Assignment 4

Documents in this Course
Week 1

Week 1

3 pages

Op-Amps

Op-Amps

8 pages

Op-Amps

Op-Amps

6 pages

Syllabus

Syllabus

14 pages

Planning

Planning

14 pages

Load more
Download Assignment 4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Assignment 4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assignment 4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?