def makeLineLocalizer(numObservations, numStates, ideal, xMin, xMax, robotY): #! pass """ Create behavior controlling robot to move in a line and to localize itself in one dimension @param numObservations: number of discrete observations into which to divide the range of good sonar observations, between 0 and C{goodSonarRange} @param numStates: number of discrete states into which to divide the range of x coordinates @param ideal: list of ideal sonar readings @param xMin: minimum x coordinate for center of robot @param xMax: maximum x coordinate for center of robot @param robotY: constant y coordinate for center of robot @returns: an instance of {\tt sm.SM} that implements the behavior """ # Size of a state in meters stateWidthMeters = (xMax - xMin) / float(numStates) preprocessor = PreProcess(numObservations, stateWidthMeters) navModel = makeRobotNavModel(ideal, xMin, xMax, numStates, numObservations) estimator = seGraphics.StateEstimator(navModel) driver = move.MoveToFixedPose(util.Pose(xMax, robotY, 0.0), maxVel=0.5) return sm.Cascade(sm.Parallel(sm.Cascade(preprocessor, estimator), driver), sm.Select(1))
def wrapTextUI(m): """ @param m: An instance of C{sm.SM} @returns: A composite machine that prompts the user for input to, and prints the output of C{m} on each step. """ return sm.Cascade(sm.Cascade(TextInputSM(), m), sm.PureFunction(textOutput))
def wrapWindowUI(m, worldColors, legalInputs, windowName='Belief', initBelief=None): """ @param m: A machine created by applying C{se.makeStateEstimationSimulation} to a hallway world, which take movement commands as input and generates as output structures of the form C{(b, (o, a))}, where C{b} is a belief state, C{a} is the action command, and C{o} is the observable output generated by the world. @param worldColors: A list of the colors of the rooms in the hallway, from left to right. @returns: A composite machine that prompts the user for input to, and graphically displays the output of C{m} on each step. """ def drawWorld(size): y = 0 for x in range(size): window.drawRect((x, y), (x + 1, y + 1), color=worldColors[x]) def processOutput(stuff): (dist, (o, a)) = stuff drawWorld(dim) drawBelief(dist, window, dim) return (o, a) def processInput(stuff): if stuff == 'quit': print 'Taking action 0 before quitting' return 0 else: return int(stuff) dim = len(worldColors) if not initBelief: initBelief = dist.UniformDist(range(dim)) ydim = 1 window = DrawingWindow(dim * 50, ydim * 50 + 10, -0.2, dim + 0.2, -0.2, ydim + 0.2, windowName) drawWorld(dim) drawBelief(initBelief, window, dim) return sm.Cascade( sm.Cascade( sm.Cascade(TextInputSM(legalInputs), sm.PureFunction(processInput)), m), sm.PureFunction(processOutput))
def systemSM(circuit, inComponents, motorNodes, initState): # circuit takes input which is a dictionary of values (or list of them) # output is a le.Solution instance. cSM = CircuitSM(circuit.components, inComponents, circuit.groundNode) # motor input is Solution instance, output is (vel, angle) motorSM = sm.Cascade(MotorAccel(initState, motorNodes), sm.R(initState)) # world has Solution as input, ((vel, angle), sol) as output wSM = sm.Parallel(motorSM, sm.Wire()) if inComponents: # there's another input besides motor feedback return Feedback2(sm.Cascade(cSM,wSM), MotorFeedback()) else: # only motor feedback return Feedback(sm.Cascade(cSM,wSM), MotorFeedback())
def makeStateEstimationSimulation(worldSM, verbose = False): """ Make a machine that simulates the state estimation process. It takes a state machine representing the world, at construction time. Let i be an input to the world machine. The input is fed into the world machine, generating (stochastically) an output, o. The (o, i) pair is fed into a state-estimator using worldSM as its model. The output of the state estimator is a belief state, b. The output of this entire composite machine is (b, (o, i)). @param worldSM: an instance of C{ssm.StochasticSM} @returns: a state machine that simulates the world and executes the state estimation process. """ return sm.Cascade(sm.Parallel(worldSM, sm.Wire()), sm.Parallel(StateEstimator(worldSM, verbose = verbose), sm.Wire()))
def spireFlow(incr): return sm.Cascade(SpyroGyra(incr), XYDriver())