23.08.2015 Views

Here - Agents Lab - University of Nottingham

Here - Agents Lab - University of Nottingham

Here - Agents Lab - University of Nottingham

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1 agent - script ACMEThermostat implements Thermostat in SmartHome {23 cond : Conditioner ;4 therm : Thermometer ;5 threshold : double ;6 condSpeed : double ;78 plan - for Init ( conditioner : Conditioner thermometer : Thermometer ){9 cond = conditioner ; therm = thermometer ; threshold = 1; condSpeed = 0.50;10 }1112 plan - for AchieveTemperature using : cond , therm , log @ mainRoom {13 log ( msg : " achieving temperature "+ targetTemp +" from "+ currentTemp )14 completed - when : java . lang . Math . abs ( targetTemp - currentTemp ) < threshold {15 every - time currentTemp > ( targetTemp + threshold ) && ! isCooling16 => startCooling ( speed : condSpeed )17 every - time currentTemp < ( targetTemp - threshold ) && ! isHeating18 => startHeating ( speed : condSpeed )19 }20 if ( isHeating || isCooling ){21 stop ()22 }23 }2425 plan - for KeepTemperature using : cond , therm , userView {26 quitPlan : boolean = false ;2728 completed - when : quitPlan {29 do - task AchieveTemperature ( targetTemp : desiredTemp )3031 every - time changed desiredTemp => atomically : {32 if (is - doing - any AchieveTemperature ) {33 drop -all - tasks AchieveTemperature34 }35 do - task AchieveTemperature ( targetTemp : desiredTemp )36 }3738 every - time changed currentTemp : !is - doing - any AchieveTemperature39 => do - task AchieveTemperature ( targetTemp : desiredTemp )40 }4142 every - time told newThreshold => {43 threshold = newThreshold44 }4546 every - time changed thermostatStatus : thermStatus . equals == ThermostatStatus . OFF47 => atomically : {48 if ( isCooling || isHeating ){49 stop ()50 }51 drop -all - tasks AchieveTemperature52 quitPlan = true53 }54 }55 }5657 plan - for SelfTest () using : log @ mainRoom , cond {58 log ( msg :" Simple thermostat "+ myName )59 log ( msg :" Using the conditioner " + name in cond )60 }61 }Fig. 3. Definition <strong>of</strong> a script in simpAL.139

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!