Exercise 1 - Policy Writing

The aim of this exercise is to write a policy in PonderTalk and integrate it into the example system. In the Body Sensor Node (BSN) example the Glucose Monitor and the Insulin Pump are currently unused.

The aim is to write a policy that detects when the glucose level goes over 180 mg/dl and instructs the insulin pump to give a small injection of insulin every 10 seconds.  Once the glucose level has gone down, the pump should be shut off again. (Note: do not attempt this in real life, the author has no idea about medical matters!)

The BSN Example documentation will explain more fully what all the basic policies etc are that are used for the exercises.

Running

  1. You should edit the file ex1.p2 which is in the top level directory of the Ponder2Tutorial
  2. Make sure that the BSN controller is running (./ant bsn)
  3. Try running your code with ./ant ex1 which will read all the tutorial files and your ex1.p2 file
  4. Click on the glucose and pump buttons to get glucose monitor and pump windows
  5. Raise the glucose level over 180, the pump should start
  6. Drop the glucose level, the pump should stop

Implement the policies below little by little and keep trying out what you have done.  In fact if you run ./ant ex1 now, it will run without errors but not really do anything.

Policies

The policies are described in a Policy pseudo-code.

Pump Discovery

You need a policy to add a newly discovered pump and one to remove it. See PonderTalk example files tut5.p2 for a similar one.

new pump policy

on event newPump(name)
    create new pumpadaptor in /bsn/name

lost pump policy

on event lostPump(name)
    remove /bsn/name

High/Low Policies

You need one policy to detect a high glucose level and one to detect a low level.  See PonderTalk example file tut6.p2 for a similar policy. Also see the managed object documentation for information about all the managed objects used in this tutorial.

Note: The names you should be using are IPUMP1 and GLUCOSE1 as that is how they will identify themselves when they enter the system.

glucose high policy

on event bsnvalue(name, newValue)
    if name == GLUCOSE1 && newValue > 180
        /bsn/GLUCOSE1.set(rate=10)
        /bsn/IPUMP1.inject(dose=3)

glucose normal policy

on event bsnvalue(name, newValue)
    if name == GLUCOSE1 && newValue <= 180
        /bsn/GLUCOSE1.set(rate=2)

Finally

You can see how the example should run by running ./ant bsn and ./ant ex1done

home