Code Monkey home page Code Monkey logo

cpo-lab2's Introduction

CPO-lab2

list of group members:

192050214 Mu Yuankai 192050208 Jia Yuebin

variant description:

eDSL for finite state machine (Mealy).

synopsis:

Display as a state graph (GraphViz dots) or table (ASCII).

Provide a complex example, such as the controller of an elevator, a traffic light at an intersection, and so on.After modification, delete the example of the traffic light at the intersection, the main example is the controller of the elevator

To work together:

Complete the FSM class together

Personal work:

Mu Yuankai finished FSM.py code module writing. Jia Yuebin completed the test modules and collected relevant data.

Code Introduction:

src/stateMachine/elevator/FSM.py:

class StateMachineis a class of finite state machine .

member variables:

self.handlers = {}  # State transfer function dictionary
self.startState = None  # initial state
self.endStates = []  # Final state list
self.runResult = 0  # The result of function run
self.state = []  # To collect all state
self.trans = {}  # Transfer process information
self.trans_to = {} # "Key" state can be transferred to "value" state

member methods:

def add_state(self, name, handler, trans_to, end_state=0):
    '''
    Function introduction:Add state
    :param name:Name of the added state
    :param handler:State transition function of the state
    :param trans_to:The next state that this state allows to move to
    :param end_state:Is the state final state or not.
    :return:
    '''
def add_trans_status(self, state, move):
    '''
    Function introduction:Add state transition information
    :param state:State name.
    :param move:Actions performed in this state/
    :return:
    '''
def set_start(self, name):
    '''
    Function introduction:Set start state.
    :param name:State name.
    :return:
    '''
def run(self, cargo):
    '''
    Function introduction:Running FSM.
    :param cargo:Input action list.
    :return:
    '''
def visualize(self):
    '''
    Function introduction:Create dot code for graphviz.
    :return:
    '''

The elevator case

The state transition generation diagram is under src/stateMachine/elevator.

The initial state is "START", and the final state is "STATIC" or "ERROR".You can draw the transition rules from the state transition diagram.

conclusion:

According to the elevator example, different actions are performed by entering different values through the state machine.Understand the basic purpose of a finite state machine: to "run" in response to a series of events

cpo-lab2's People

Contributors

jbscwy avatar moce96 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.