Package populus :: Module ReactiveMind :: Class ReactiveMind
[frames] | no frames]

Class ReactiveMind


Base class for a reactive intelligence that works as a scheduler of reactive behaviors. It extends the steering behaviors library since the reactive behaviors are based on them. This class is a mix-in and it's meant to extend a given a motion model. Use it to create reactive agents through multiple inheritance with a motion model. Do not instantiate this class, it cannot stand by its own.

Nested Classes
  Motivation
This an nested helper class that realizes a motivation intended as a psychological pressure in doing something.
Instance Methods
 
__init__(self)
The constructor creates an instance of a ReactiveMind.
 
addMotivation(self, combiner)
Add a new motivation to control and affect the body motion.
bool
createSteeringBehavior(self, behaviorName, behaviorTask, priority=1, weight=1.0, tStep=0.0, profile={})
Create a new reactive behavior type.
 
forget(self, entry)
Forget an entry into the short term memory.
 
getBehaviorPriority(self, bhvKey)
...
 
getBehaviorTime(self, bhvKey)
...
 
getBehaviorTimeMarker(self, bhvKey, marker)
...
 
getBehaviorWeight(self, bhvKey)
...
 
investigateBehavior(self, type=None)
Print out information about all the instances of a running reactive behavior of the given type.
 
memorize(self, entry, time=5.0)
Memorize something into the short term memory.
 
modifyBehaviorPriority(self, bhvKey, newPriority)
...
 
modifyBehaviorWeight(self, bhvKey, newWeight)
...
 
plugPerception(self, visionModule, proxemicsModule)
Use this method to plug a vision and proximity perception mechanism into the ReactiveMind.
bool
remember(self, entry)
Check whether the entry is in the short term memory.
bool
requestStartBehavior(self, caller, type, **vars)
This method is used by an external module to request the execution of a reactive behavior.
bool
requestStopAllBehaviors(self, caller)
Stop all the behaviors requested by an external caller.
bool
requestStopBehavior(self, caller, type)
This method is used by an external module to request the termination of a reactive behavior.
 
setBehaviorTimeMarker(self, bhvKey, marker)
...
 
setBehaviorTimer(self, bhvKey, time)
...
int
startSteeringBehavior(self, type, delay=0.0, timer=0.0, start=0.0, end=0.0, uponStop=None, restart=False, name=None, **vars)
Start an instance of a reactive behavior.
 
stopBehaviorLater(self, bhvKey, time)
Stop a reactive behavior after a given time.
bool
stopSteeringBehavior(self, bhvId)
Stop execution of a reactive behavior identified by bhvId.

Inherited from SteerLibrary.SteerLibraryMixIn: convertForceIntoCosts, initSetOfCosts, spanDirections, steerForArrival, steerForAvoidObstacle, steerForAvoidObstacles, steerForAvoidObstaclesNEW, steerForCohesion, steerForFacing, steerForFlee, steerForKeepGroupSpace, steerForMinDistance, steerForSeek

    Update
 
update(self, dt)
Update the ReactibeMind.
Static Methods

Inherited from SteerLibrary.SteerLibraryMixIn: addCost, getCost, getMagnitude, setCost, setMagnitude

Method Details

__init__(self)
(Constructor)

 

The constructor creates an instance of a ReactiveMind.

Overrides: SteerLibrary.SteerLibraryMixIn.__init__

addMotivation(self, combiner)

 

Add a new motivation to control and affect the body motion.

Parameters:
  • combiner (callable) - The combiner algorithm to use in evaluating candidates to compute the final motivation's value.

createSteeringBehavior(self, behaviorName, behaviorTask, priority=1, weight=1.0, tStep=0.0, profile={})

 

Create a new reactive behavior type. Later will be possible to run an instance of this reactive behavior just using its behavior name.

Priority and Weight

  • Set a priority if you want this behavior override the effect of lower priority behavior.
  • The weight will be applied to all the motivational forces generated by this behavior and used during blending of motivation as a measure of its importance.

Running Frequency

  • Set a time step tStep as a way of controlling the frequency at which the behavior will motivate the body.

Profile

  • Use the profile to set default values to the behavior variables used inside the behavior's task.
Parameters:
  • behaviorName (string) - The name of this behavior type.
  • behaviorTask (callable) - The task to call when the behavior is running.
  • priority (int) - The behavior's priority.
  • weight (float) - The behavior's weight.
  • tStep (float) - The behavior's running frequency expressed as a time step.
  • profile (dict) - A set behavior variables with their default values.
Returns: bool
Return True if the behavior is been successfully created; False otherwise

Note: The method's name is incorrect. It does create reactive behaviors and not steering behaviors

forget(self, entry)

 

Forget an entry into the short term memory.

Parameters:
  • entry (Avatar or Prop) - The entity the agent has to forget.

Deprecated: Entries from the memory should *never* be purposely deleted. They should stay in memory for a while and than autonomously disappear. The short term memory is not a buffer therefore do not use it as such.

investigateBehavior(self, type=None)

 

Print out information about all the instances of a running reactive behavior of the given type.

Parameters:
  • type (string) - The behavior type to investigate.

memorize(self, entry, time=5.0)

 

Memorize something into the short term memory. The memory of the entity will last for time seconds.

Parameters:
  • entry (Avatar or Prop) - The entity the agent has to remember.
  • time (float) - For how long (in seconds) remember the entry.

plugPerception(self, visionModule, proxemicsModule)

 

Use this method to plug a vision and proximity perception mechanism into the ReactiveMind.

Parameters:
  • visionModule (AvatarVision) - The vision module of an Avatar instance.
  • proxemicsModule (AvatarProxemics) - The proximity module of an Avatar instance.

Attention: This is method is a workaround! In fact we need to have a better design in order to use perceptual data into the reactive code.

To Do: this method will disappear in the next refactoring phases.

remember(self, entry)

 

Check whether the entry is in the short term memory.

Parameters:
Returns: bool
True if the entry is in memory; False otherwise.

requestStartBehavior(self, caller, type, **vars)

 

This method is used by an external module to request the execution of a reactive behavior.

An external caller can use vars to set variables for the behavior profile.

Parameters:
  • caller - An external module who wants to run a reactive behavior.
  • type (string) - The requested reactive behavior.
  • vars - A list of variables for the reactive behavior. They have to match with the behavior's profile.
Returns: bool
True in case of success, False otherwise.

Note: An external caller cannot run multiple instances of the same behavior type.

requestStopAllBehaviors(self, caller)

 

Stop all the behaviors requested by an external caller.

Parameters:
  • caller - An external module who wants to stop all the behaviors previously requested.
Returns: bool
True in case of success, False otherwise.

requestStopBehavior(self, caller, type)

 

This method is used by an external module to request the termination of a reactive behavior.

Parameters:
  • caller - An external module who wants to stop a reactive behavior.
  • type (string) - The requested reactive behavior.
Returns: bool
True in case of success, False otherwise.

Note: If the caller never asked for running the behavior then the request will not take any effect.

startSteeringBehavior(self, type, delay=0.0, timer=0.0, start=0.0, end=0.0, uponStop=None, restart=False, name=None, **vars)

 

Start an instance of a reactive behavior. The type must be chosen from the available library of reactive behaviors.

Parameters:
  • type (string) - The reactive behavior type.
  • delay (float) - Set a delay time if you want to delay the behavior execution.
  • timer (float) - Set a timer if you want to stop the behavior after a certain time; if timer = 0 then the behavior will run continuously unless it will get stopped by an external call or internal logic in the task.
  • start (float) - Equivalent to delay, set when to start the behavior.
  • end (float) - Set when to stop the behavior.
  • uponStop (callable) - Set a produce that will be called when the behavior stops.
  • restart (bool) - If True, stops all the previously running instances of the this behavior type before starting a new one.
  • name (string) - Set a reference name to this reactive behavior.
  • vars - A list of behavior variables. They have to much with the behavior profile.
Returns: int
The behavior key in case of success, 0 otherwise.

Attention: The current implementation generates behavior keys by simply incrementing a counter.

stopBehaviorLater(self, bhvKey, time)

 

Stop a reactive behavior after a given time.

Parameters:
  • bhvKey (int) - The key who identifies the behavior.
  • time (float) - A delay time after which stop the behavior.

Attention: This is a experimental function which is intended to be used exclusively into the logic of a behavior task.

stopSteeringBehavior(self, bhvId)

 

Stop execution of a reactive behavior identified by bhvId. The identifier may be an instance key or an instance name.

Parameters:
  • bhvId (int or string) - A behavior identifier that might be a behavior key or a behavior name.
Returns: bool
True in case of success, False otherwise.

Note: The uponProc procedure will be called after stopping the behavior execution.

Attention: In the current implementation the behavior stopping will take place on the next update of the ReactiveMind and not immediately.

update(self, dt)

 

Update the ReactibeMind.

Parameters:
  • dt (float) - Delta time since the last simulation step.