CS380:Lab02

From IPRE Wiki
Jump to: navigation, search

Lab 2: CS380 Androids Design and Practice

This lab will explore Finite State Machines, the Kinect, and Robocup Soccer.

You may want to refer to Calico Lua and also Calico Graphics.

FSM

Examples of Finite State Machines:

Consider the following use of a Finite State Machine:

require('fsm')

State = {}
State.__index = State

the_string = "this is the string"

function State.new(name)
    local state = {}
    setmetatable(state, State)
    state._NAME = name
    return state
end

stateA = State.new("Alpha")
stateB = State.new("Beta")

stateA.entry = function ()
    print("   entry "..stateA._NAME)
end

stateA.update = function ()
    print("   update " .. stateA._NAME)
    print(the_string)
    char = the_string:sub(1, 1)
    if char == "g" then
        stateA.done = true
    end
    the_string = the_string:sub(2, -1)
    return "got a"
end

stateA.exit = function ()
    print("   exit A")
end

stateB.entry = function ()
    print("   entry B")
end

stateB.update = function ()
    print("   update B")
    return "got b"
end

stateB.exit = function ()
    print("   exit B")
end

sm = fsm.new(stateA);
sm:add_state(stateB);

function notify(message)
    return function ()
                print("   Transition: " .. message);
           end
end

sm:set_transition(stateA, "got a", stateB, notify("a to b"));
sm:set_transition(stateB, "got b", stateA, notify("b to a"));

sm:entry();
while 1 do
    sm:update();
    print("Current State: " .. sm.currentState._NAME);
    if sm.currentState.done ~= nil then
        break;
    end
end

You'll need to save this file in a directory with the fsm.lua file too.

Change the code to either Accept or Reject a setting of the_string such that the_string is a valid representation of a floating point number with optional scientific notation:

  • Starts with a plus or minus, or nothing
  • Followed by one or more digits
  • Followed by an optional decimal place
  • If a decimal, then optionally followed by zero or more digits
  • Then can be optionally followed by an "e"
  • Followed by a plus or minus
  • followed by one or more digits
  • Some of the many examples to Accept:
    • "+1.8723e-2"
    • "-9.3e+10"
    • "1"
    • "-0"
    • "2."
    • "2e100"
    • "-2."
    • "+2."
    • "+2.8"
    • "+2.8e+10"
    • "+9.34234e-32"
    • "-0.0e-1"
    • "-0.0e-00000000000000000"
  • Some of the many examples to Reject:
    • ".8723e-2"
    • "-.3e+10"
    • "1e+"
    • "--0"
    • "2.."
    • "-2.000.0"
    • "+-2."
    • "+e2.8"
    • "+2.8a+10"
    • "+9.34+234e-32"
    • "-0.0e-"
    • "e-00000000000000000"

Kinect

You will need the Kinect TCP server

Using the code from Calico Kinect as a guide, do the following:

Record the positions of a skeleton, and play them back. You can use Python (or any other Calico language for this example; unfortunately Lua does not yet work with Calico libraries).