6 01 Spring Semester 2008 Assignment 4 Issued Tuesday Feb 26 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6 01 Introduction to EECS I Spring Semester 2008 Assignment 4 Issued Tuesday Feb 26 Overview of this week s work In 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 when you 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 work must conform to the homework guidelines on the web page You will need SoaR in this software lab so if you don t have SoaR installed on 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 have given you several that have Skeleton in the name You should make a copy of those files and rename them to remove the Skeleton You will get failing imports otherwise 6 01 Spring Semester 2008 Assignment 4 Issued Tuesday Feb 26 2 Software Lab Combinations of state machines In class we discussed three methods of making new state machines out of old ones serial composition 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 state machines as input and construct a new composite state machine class SerialSM def init self sm1 sm2 self m1 sm1 self m2 sm2 Be careful to keep the timing consistent The input to m2 has to be the current output of m1 not the output after it is stepped def step self input None Your code here def currentOutput self Your code here Question 1 Write the step and currentOutput methods for a serial SM Test it by combining two incr machines the definition is in SimpleSMSkeleton py Draw a picture showing how the machines are connected First figure out what the result ought to be by filling out a table like this one remember that by definition output 1 input 2 step 0 1 2 3 input 1 state 1 output 1 state 2 output 2 Then test to be sure your machine is doing the right thing Question 2 Compare the results of composing a sum machine defined in SimpleSMSkeleton py which outputs the sum of all of its inputs so far with an incr machine Predict what the result ought to be by filling out a table like this one step 0 1 2 3 input1 state1 output1 state2 Then be sure you re getting the right result output2 6 01 Spring Semester 2008 Assignment 4 Issued Tuesday Feb 26 3 Feedback The following class defines a feedback state machine Its init method takes a state machine sm and returns a state machine with no inputs which consists of sm with its output fed back to its input We ll define the output of the feedback machine to be the same as the output of sm class FeedbackSM def init self sm self m sm def step self input None return self m step self m currentOutput def currentOutput self return self m currentOutput Now we can use this to couple two machines together with the outputs of one machine serving as the inputs to the other and vice versa def simulatorSM m1 m2 return FeedbackSM SerialSM m1 m2 Question 3 In the code file you ll find the definition of makeIncr which takes an initial state as an argument and then thereafter updates its state to be its input plus 1 If we make the following coupled machine we get a potentially surprising string of outputs fizz simulatorSM makeIncr 10 makeIncr 100 run fizz 100 11 102 13 104 15 106 17 108 19 110 Explain why this happens Draw a picture of the objects involved in this machine and say exactly what state variables they contain Fill in a table describing the inputs states and outputs of each component machine at each step 6 01 Spring Semester 2008 Assignment 4 Issued Tuesday Feb 26 4 Question 4 Imagine a robot driving straight toward a wall We would like to use a state machine to model this system where the state is the distance from the robot to the wall in meters pick an initial distance for your initial state and the input is the robot s current forward velocity in meters per second Assume that each state transition corresponds to the passage of 0 2 seconds Write a primitive state machine to model this system Hint the distance should go down as the machine steps Question 5 Now let s think of the controller that this robot might be executing Assume the robot would like to stop at some distance dDesired from the wall The controller can be modeled as a state machine that receives as input the current distance to the wall and generates as output a velocity For now assume there s no inertia involved and so the controller can choose any new velocity it wants independent of its previous velocity In particular let s assume it selects a new velocity that is equal to k d dDesired where d is the current distance to the wall dDesired is 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 the coupled machine Try a large value of k and a small value of k What happens By setting SimpleSM verbose to True you can get PrimitiveSM step to print out information about each step of each primitive machine Question 7 You can plot data from inside soar If all you want to do is plot the best thing is to make a brain with only a setup method and put your plotting commands in there Then when you run the brain you ll see your data plotted in a window The SimpleSMBrainSkeleton 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 the outputs generated by the machine So you can just copy the setup and step definitions from SimpleSMBrainSkeleton py file to the file with your state machine definitions call run inside of setup to get some data and then plot it using graphDiscrete If you select that file as …
View Full Document