Lecture_Duke_RBS
Lecture_Duke_RBS
ICT219 1
More on Obstacle Avoidance
• Continuing to develop our obstacle-avoidance code, Champandard uses
the concept of steering behaviours (Reynolds, 1999)
resulting motion
steering force
existing motion
ICT219 2
Steering, seeking and fleeing
• Velocities and steering forces are both limited at some max value
truncate(steering_force, MAX_STEERING_FORCE) //cap force to max
velocity = velocity + steering_force; // accumulate vectors to get new vel
truncate(velocity, MAX_VELOCITY) //cap animat speed to max
Motion->move(velocity) //use interface to locomotion layer to apply the new vel
resulting motion
existing motion
• The desired force is computed from the distance and bearing to the
target and relative to the existing velocity of the animat
• It is well to slow the animat down as it approaches a target because
at maximum velocity it will overshoot and oscillate
• Fleeing behaviour may be computed ICT219by simply negating the seeking3
vector, so that the direction of travel is away from the target
A Basic Obstacle-Avoidance Algorithm
function avoid_obstacles2
check the Vision senses for free space in front, left and right
if a frontal collision is projected (using Tracewalk)
find the furthest obstacle on left or right
determine the best side to turn towards
compute the desired turn to seek the free space
endif
ICT219 6
Formalisms
• Symbols – we already use representations in basic programming
left_obstacle_distance = 4.0; // distance to left obstacle is 4 units
left_obstacle_colour = ‘’blue’’; // colour blob there is in the blue
left_obstacle_identity = ‘’unknown’’; // nothing from the recogniser though
right_obstacle_distance = 12.0; // distance to left obstacle is 4 units
distance (right_obstacle,12.0);
• More natural since most attributes would be fetched from the world by a
function ICT219 7
Formalisms
• Frames – are a labelled package of slots, each with a value. The values
might be pointers to other frames, or actors, which may launch
procedural code
frame_left_obstacle:
distance: (4.0)
colour: (blue)
identity: (frame_fountain)
on_proximity: <avoid_right 50.0f>
Bird Container
is-a is-a
ICT219 8
Formalisms
• Conceptual Graphs – more compact and flexible than semantic
networks. Relationships get the status of nodes, and is-a links are made
implicit
OBJ PIE
eg. Bayesian
network
• This processes is very creative and may loop back (like the Software
Development Life Cycle)
ICT219 11
Rule Based Systems - Basics
• This is a real success story of AI – tens of thousands of working
systems deployed into many aspects of life
ICT219 12
RBS Components
• Working memory – a small allocation of memory into which only
appropriate rules are copied
ICT219 13
Rule Based Systems - Architecture
ICT219 14
Rule Based Systems – Forward Chaining
• To reason by forward chaining, the interpreter follows a recognise-act
cycle which begins from a set of initial assertions (input states set in the
working memory) and repeatedly applies rules until it arrives at a
solution (data driven processing)
• Match – identify all rules whose antecedent clauses match the initial
assertions
• Conflict resolution – if more than one rule matches, choose one
• Execution – the consequent clause of the chosen rule is applied, usually
updating the state of working memory,
ICT219 finally generating output 15
Rule Based Systems - Backward Chaining
• In backward chaining, the interpreter begins from a known goal state
and tries to find a logically supported path back to one of the initial
assertions (goal-directed inference)
en D
• Match – identify all rules whose consequent clauses match the working
memory state (initially the hypothesised goal state)
• Conflict resolution – if more than one rule matches, choose one
• Execution – the state of working memory is updated to reflect the
antecedent clause of the matched rule
ICT219 16
Rule Based Systems – Conflict Resolution
• The interpreter must choose one path to examine at a time, and so
needs a method of conflict resolution in case of multiple rules
• Methods include:
- first come, gets served: choose the first rule that applies
- rules are ordered into priorities (by expert): choose the highest rank
- most specific rule is chosen: eg, apply the rule with most elements in
antecedent
- choose a rule at random, and use that
- keep a historical trace, and allow this to chose a different rule next
time
• If the first chosen rule leads to a dead end, it should be possible to try
another, provided a trace is kept
Explanation
Facility
• 1 and 4 are similar, but depend on what the animat has been doing,
thus a purely reactive agent cannot generate this behaviour
<rulebase>
<Rule> default values are called ‘ground’
<conditions>
<Symbol name="following" value="false" ground=“true”/>
ICT219 20
How to Use the Rulebase Interface
• Native symbols must be synchronised so as to relay input from sensors
into the RBS system at runtime
• This variable is now synchronised with the one in the working memory
• We can use Get and Set accessor methods to fetch and change the
values in working memory:
void Set (const string& symbol, const bool value ); //sets a native var
bool Get (const string& symbol) const;// returns boolean state of the var
• You can even add rules dynamically – not recommended to begin with!
ICT219 21
How the RBS Simulator Works
• FEAR has a RBS simulator in the ‘modules’ directory
• The working memory and rulebase set up with appropriate XML
• Needs native functions linked to sensors and effectors
• Interpreter (used for animat control) cycles through these steps:
1. Update working memory variables from inputs using CheckSensors();
2. Scans rules (top to bottom), looking for a match using ApplyRules().
Rules that do not match are skipped. If all rules match, the defaults are
applied, then overridden by rule specifications. If no matches are found,
the default values are applied.
3. Effector symbols are scanned by CheckEffectors(), and native function
calls are made if any are true.
• Calling the function Tick() executes one such cycle
• Once the system has been set up, most of the modifications can be
done by just modifying the rules (provided they don’t need new
sensors and effectors)
ICT219 22
Back into Quake 2
• The Stalker demonstration animat uses these methods to implement
wall-following
ICT219 23