larvaworld.lib.model.modules.brain

Classes

Brain

Base brain class for agent behavioral control.

DefaultBrain

Default larva brain implementation with full sensory integration.

Module Contents

class larvaworld.lib.model.modules.brain.Brain(conf: Any, agent: Any | None = None, dt: float | None = None, **kwargs: Any)

Bases: larvaworld.lib.param.NestedConf

Base brain class for agent behavioral control.

Orchestrates sensory processing and locomotor control for autonomous agents in simulation. Integrates multiple sensory modalities (olfaction, touch, thermosensation, wind) with memory and locomotor modules.

Attributes:

olfactor: Olfactory sensor module for odor detection toucher: Tactile sensor module for contact sensing windsensor: Wind sensor module for air flow detection thermosensor: Temperature sensor module for thermal gradients locomotor: Locomotor module for movement control agent: Parent agent instance (polymorphic: LarvaRobot, LarvaSim, etc.) dt: Simulation time step (seconds) modalities: Dict of sensory modalities with sensors and processing functions

Example:
>>> brain = Brain(conf=brain_conf, agent=my_agent, dt=0.1)
>>> brain.sense(pos=agent.pos, reward=False)
>>> print(f"Total sensory input: {brain.A_in}")
olfactor
toucher
windsensor
thermosensor
agent = None
dt = None
locomotor: larvaworld.lib.model.modules.locomotor.Locomotor
modalities
init_sensors() None
sense_odors(pos: Any | None = None) dict[str, Any]
sense_food_multi(**kwargs: Any) dict[Any, int]
sense_wind(**kwargs: Any) dict[str, float]
sense_thermo(pos: Any | None = None) dict[str, float]
sense(pos: Any | None = None, reward: bool = False) None
property A_in: float
property A_olf: float
property A_touch: float
property A_thermo: float
property A_wind: float
class larvaworld.lib.model.modules.brain.DefaultBrain(conf: Any, agent: Any | None = None, dt: float | None = None, **kwargs: Any)

Bases: Brain

Default larva brain implementation with full sensory integration.

Extends base Brain with automatic sensor module construction and integrated locomotor stepping. Provides complete sensorimotor loop for autonomous larva agents.

Args:
conf: Brain configuration dict with keys:
  • ‘olfactor’: Olfactory sensor config (or None)

  • ‘toucher’: Tactile sensor config (or None)

  • ‘windsensor’: Wind sensor config (or None)

  • ‘thermosensor’: Thermal sensor config (or None)

  • ‘memory’: Memory module config (or None)

  • ‘locomotor’: Locomotor module config

agent: Parent agent instance (LarvaRobot, LarvaSim, or compatible).

Must have attributes: model, radius, pos, touch_sensorIDs

dt: Simulation time step (seconds). Defaults to agent.model.dt **kwargs: Additional keyword arguments passed to parent Brain

Returns:

Tuple of (linear_velocity, angular_velocity, crawl_flag)

Example:
>>> brain = DefaultBrain(conf=brain_config, agent=my_larva, dt=0.1)
>>> lin_vel, ang_vel, crawling = brain.step(pos=larva.pos, on_food=False)
step(pos: Any, on_food: bool = False, **kwargs: Any) tuple[float, float, bool]