Implementation:Google deepmind Dm control Fruitfly V2
| Knowledge Sources | |
|---|---|
| Domains | Robotics Simulation, Neuroethology, Biomechanical Modeling |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
The fruitfly_v2 module implements a detailed fruit fly (Drosophila) walker model with configurable body parts (legs, wings, mouth, antennae), adhesion actuators, binocular vision cameras, and rich sensory observables for neuroethology research.
Description
The FruitFly class extends legacy_base.Walker and loads a detailed MJCF model from an XML file. During its _build method, it performs several configuration steps: it optionally retracts unused body parts (legs, wings, mouth, antennae) by computing rest quaternions from joint springrefs and removing associated actuators, tendons, and joints; it configures wing stroke plane and body pitch angles for flight via quaternion transformations; it sets up actuator dynamics filters for both joint and adhesion actuators; and it builds action-class index maps (_ctrl_indices, _action_indices) that map environment actions to MuJoCo controls organized by body part category (adhesion, head, mouth, antennae, wings, abdomen, legs, user).
Several helper functions at module level provide quaternion math utilities (neg_quat, mul_quat, rot_vec_quat, mul_jac_t_vec) and body frame transformations (change_body_frame, body_quat_from_springrefs). The apply_action method maps action-class indices to MuJoCo control vectors, while get_action_spec constructs a bounded action specification from actuator control ranges.
The FruitFlyObservables class provides a rich set of sensory observables: thorax/abdomen height, world z-axis in multiple body frames (thorax, abdomen, head, hover up direction), force/touch/accelerometer/gyro/velocimeter sensors with buffered temporal aggregation, actuator activation, binocular eye cameras with configurable field of view and resolution, appendage positions in the egocentric frame, and self-contact force detection. Observable groups are organized into vestibular, proprioception, and orientation categories.
Usage
Use this module to create a fruit fly walker for locomotion, flight, or multi-modal sensory integration experiments. The walker is highly configurable: body parts can be independently enabled or disabled, timesteps can be adjusted, and additional user actions can be added. It integrates with the dm_control composer framework for use in locomotion tasks.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/locomotion/walkers/fruitfly_v2.py
- Lines: 1-675
Signature
class FruitFly(legacy_base.Walker):
def _build(self,
name: str = 'walker',
use_legs: bool = True,
use_wings: bool = False,
use_mouth: bool = False,
use_antennae: bool = False,
joint_filter: float = 0.01,
adhesion_filter: float = 0.01,
body_pitch_angle: float = 47.5,
stroke_plane_angle: float = 0.,
physics_timestep: float = 1e-4,
control_timestep: float = 2e-3,
num_user_actions: int = 0,
eye_camera_fovy: float = 150.,
eye_camera_size: int = 32):
...
def initialize_episode(self, physics, random_state): ...
def apply_action(self, physics, action, random_state): ...
def get_action_spec(self, physics): ...
class FruitFlyObservables(legacy_base.WalkerObservables):
def __init__(self, walker, buffer_size, eye_camera_size): ...
Import
from dm_control.locomotion.walkers.fruitfly_v2 import FruitFly
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | No | Name of the walker (default: 'walker') |
| use_legs | bool | No | Whether to use or retract the legs (default: True) |
| use_wings | bool | No | Whether to use or retract the wings (default: False) |
| use_mouth | bool | No | Whether to use or retract the mouth (default: False) |
| use_antennae | bool | No | Whether to use the antennae (default: False) |
| joint_filter | float | No | Timescale of filter for joint actuators; 0 disables (default: 0.01) |
| adhesion_filter | float | No | Timescale of filter for adhesion actuators; 0 disables (default: 0.01) |
| body_pitch_angle | float | No | Body pitch angle for initial flight pose in degrees (default: 47.5) |
| stroke_plane_angle | float | No | Wing stroke plane angle in degrees (default: 0.0) |
| physics_timestep | float | No | Simulation timestep in seconds (default: 1e-4) |
| control_timestep | float | No | Controller timestep in seconds (default: 2e-3) |
| num_user_actions | int | No | Number of additional custom actions with range [-1, 1] (default: 0) |
| eye_camera_fovy | float | No | Vertical field of view of eye cameras in degrees (default: 150.0) |
| eye_camera_size | int | No | Size in pixels of eye cameras (default: 32) |
Outputs
| Name | Type | Description |
|---|---|---|
| FruitFly instance | FruitFly | A configured fruit fly walker entity for use in dm_control composer tasks |
| action_spec | dm_env.specs.BoundedArray | Bounded action specification returned by get_action_spec(physics) |
Usage Examples
Basic Usage
from dm_control.locomotion.walkers.fruitfly_v2 import FruitFly
# Create a walking fruit fly (legs only)
walker = FruitFly(name='fly', use_legs=True, use_wings=False)
# Create a flying fruit fly
flying_fly = FruitFly(
name='fly',
use_legs=False,
use_wings=True,
body_pitch_angle=47.5,
stroke_plane_angle=0.,
)
# Access walker properties
root = walker.root_body
thorax = walker.thorax
end_effectors = walker.end_effectors