The Dog Nanny

by Melissa Dunkerley


For my final project I decided to program a robot to take care of my dog Colin. The agent's main job is to let Colin outside in the back yard when he wants to go out, play frisbee or ball with him when he brings one of them over to the agent, and bring him in the house when either Colin wants to go inside, he is barking, or he has been outside for an hour and a half. THe agent also checks the weather and ground conditions when bringing Colin inside the house, so that if it is raining or snowing, or if the ground is wet, the agent "locks" Colin in the mudroom for 20 minutes to dry off, by closing the halfdoor. After 20 minutes, the agent opens the halfdoor and lets Colin into the rest of the house.

Here are the various rules, facts and explanations that make up the domain for:

               
The Dog Nanny

This program is designed to control an agent with several responsibilities:

The agent is in charge of letting my dog (Colin) outside when he wants to go out, playing frisbee or ball with Colin when he brings one of them over to the agent, and taking him back in the house when he wants to go in. The agent must also take Colin in the house when he starts to bark or when the dog has been outside for more than 90 minutes. WHen the dog is brought in, the agent checks the weather and ground conditions to decide whether or not the dog needs to dry off in the mud room for 20 minutes. If this is the case, the agent will close the half_door to keep Colin from getting mud all over the house, and after 20 minutes, the agent will open the half_door if it is still closed. If it isn't snowy or wet, the mudroom half_door is left open, and Colin can just roam freely.

The agent makes these decisions based on messages which are sent to it via sensors in the floor and in the dog's collar. When Colin wants to go outside, he sits by the back door. The sensor in his collar sends a message to the sensor in the floor by the back door, so that no matter where the agent is located, he receives a message from the sensor in the floor which tells him that Colin wants to go out. The same occurs when Colin wants to go inside. Colin goes and sits by the deck stairs when he wants to go inside, so a sensor placed near the stairs will sense if Colin has been sitting there for a while, and send a "message" to the agent telling it that Colin wants to go back in the house. Sensors will also be used to tell when Colin wants to play. The agent will have a sensor that can tell when the frisbee or tennis ball are close by... when Colin brings them over to the agent. This is how the agent knows that Colin wants to play.

The agent does various actions also based on not only the current physical domain conditions, but also based on Time. The agent only lets Colin out after 8am and before 10pm. If the dog is still outside after 90 minutes has passed, the agent brings him in. In this program, T1 is set to the time of day in terms of minutes. So, 8am is represented as T1= 480, and 10pm is represented as T1= 1320. At T1=24*60 min, (midnight) everything is reset to the conditions I stated above.

Also, the agent has to make sure that the dog is not outside for longer than 90 minutes, and that he is inside for at least 1 hour before he goes back outside. To account for this, I have another time variable T2, which keeps track of how long Colin has been at his current location. T2 gets reset to zero every time Colin is brought outside, and every time he is brought inside. This allows the agent to make decisions such as whether or not Colin has been outside too long and needs to come inside (after 90 minutes), or that Colin can't be let outside again because he just came back in the house less than 30 minutes ago. T2 is also used by the agent when the weather or ground conditions outside are snowy, rainy, or wet, and the agent needs to open the mudroom door after 20 minutes (T2=20). Since T2 is reset to zero when Colin is brought in the house, after Colin has been shut in the mudroom for 20 minutes, T2 = 20 and the agent knows to let Colin out. Note that T2 doesn't get reset at this time, it continues to increment based on how long the dog has been in the house, regardless of whether he is in the mudroom or not.

At midnight, several of the variables are reset for the next day, and the following facts become true (if they weren't already):

INITIAL CONDITIONS


wants_to_be(Colin, house).
is_located(Colin, house).
open(halfdoor).
reset(T1,0).
reset(T2,0).

How long the dog has been in it's current location is reset to 0 minutes, because it doesn't really matter what the value of T2 is, as long as it is >30 when Colin wants to go out the next morning. According to the rules I have set, since Colin can't go out before T1= 480 (8am) anyway, and since T1 and T2 increment at the same rate, by the time 8am rolls around T2 will be equal to 480, and therefore greater than 30.

The following rules apply between the hours of 8am and 10pm:

do(move(Colin, outside),T1,T2):-
                   is_located(Colin, house),
                   wants_to_be(Colin, outside),
                   T1 =>480,                    % It is after 8am
                   T1 =<1320,                     % It is before 10pm
                   T2 =>30.                     % The dog hasn't been outside in the last
                                                         % 30 minutes.

do(move(Colin, house),T1,T2):-
                   is_located(Colin, outside),
                   T2 = > 90.                                                          % Colin has been outside for 90 minutes.

do(move(Colin, house),T1,T2):-
                   is_located(Colin, outside),
                   is_barking(Colin).                                %Colin is barking and disturbing the
                                                                            % neighbors

do(move(Colin, house),T1,T2):-
                   is_located(Colin, outside),
                   wants_to_be(Colin, house).                    % Colin wants to go in the house

plays_with(agent, Colin):-
                   is_located(Colin, outside),
                   brings_over(Colin, frisbee).                    % Colin brings the frisbee over to
                                                                            % the agent, so the agent plays
                                                                            % with Colin by throwing the
                                                                            % frisbee.

plays_with(agent, Colin):-
                   is_located(Colin, outside),
                   brings_over(Colin, ball).                    % Colin brings the ball over to
                                                                            % the agent, so the agent plays
                                                                            % with Colin by throwing the ball.

do(close(halfdoor),T2):-
                   rain(weather),                                                           % lock Colin in mudroom if it is
                   do(move(Colin, house), T2).                    % raining, when he is brought in
                                                                            % the house.

do(close(agent, halfdoor),T2):-
                   wet(ground),                     % lock Colin in mudroom if the
                   do(move(Colin,house), T2).                    % ground is wet, when he is
                                                                            % brought in the house.
do(close(agent, halfdoor),T2):-
                   snow(weather),                    % lock Colin in mudroom if it is
                   do(move(Colin,house), T2).                    % snowing, when he is brought in
                                                                            % the house.

do(open(agent, halfdoor),T2):-
                   dry(ground),                                                           % open the mudroom door if the
                   wet(ground),                                                           % ground is dry and the weather is
                   do(move(Colin,house),T2),                    % nice, but the halfdoor going
                   closed(halfdoor).                                        % into the house is closed.

do(open(agent, halfdoor),T2):-
                   T2 is 20,                                                           % open the halfdoor if the dog has
                   closed(halfdoor).                                       % been shut in the mudroom for 20
                                                                            % minutes.

To Control T1 and T2:

reset(T2, 0):-                                                           % reset the "Time Colin has been
                   do(move(Colin,house),T1,T2).                    % in current location" to zero
                                                                            % when he is brought in the house.

reset(T2, 0):-                                                           % reset the "Time Colin has been
                   do(move(Colin,outside),T1,T2).                    % in current location" to zero
                                                                            % when he is brought outside.

reset(T1, 0):-                                                           % reset Current Time (in minutes)
                   T1 is 1440.                                           % to zero at midnight.

increment(T1, T2, 1).                                   % The agent assesses the current
                                                                            % situation every minute, upon
                                                                            % when it increments both T1 and T2
                                                                            % by 1 minute.


Here is a brief explanation of what is in my program:

ACTIONS:



1. move(Colin, location)

-> Moves Colin to a new location

2. plays_with(agent, Colin)

-> The Agent Plays with Colin

3. close(agent, halfdoor)

-> Agent must close the halfdoor between the mudroom and the house.

4. open(agent, halfdoor)

-> Agent must open the halfdoor between the mudroom and the house.

5. reset(T, integer)

-> Reset the value T to integer.

6. increment (Time1, Time2, integer)

-> Increment Time1 and Time2 by integer.



PRIMITIVE RELATIONS:



1. is_located(Colin, location)

-> Colin is currently located at "location"

2. wants_to_be(Colin, location)

-> According to the sensors in Colin's collar, he wants to be located at "location"

3. is_barking(Colin)

-> Colin is barking

4. brings_over(Colin, object)

-> Colin brings over a certain object to the agent to play with.

5. rain(weather)

-> The weather is currently raining

6. snow(weather)

-> The weather is currently snowing

7. wet(ground)

-> The ground is currently wet

8. dry(condition)

-> The current condition (either ground or weather) is currently dry... no snow or rain

9. closed(halfdoor)

-> The halfdoor is currently closed

10. open(halfdoor)

-> The halfdoor is currently open