Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Dm control Make Fruitfly

From Leeroopedia
Revision as of 12:43, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Dm_control_Make_Fruitfly.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Robotics Simulation, Biomechanical Modeling
Last Updated 2026-02-15 04:00 GMT

Overview

This script transforms the pre-fused Drosophila mesh model into a complete, physics-ready MuJoCo fruitfly walker with properly configured joints, collision geometry, actuators, sensors, tendons, and cameras.

Description

The make_fruitfly module is a build-time script that produces the final fruitfly.xml MuJoCo model file used at runtime by the fruitfly walker. It takes a pre-generated fused model (drosophila_fused.xml) and a defaults file (drosophila_defaults.xml) and performs an extensive sequence of model transformations using the dm_control MJCF API and low-level MuJoCo bindings.

The transformation pipeline consists of approximately 40 named steps including: combining the fused fly model with a defaults XML; rescaling from millimeters to centimeters and switching to radians; renaming and reorganizing body elements (thorax, legs, wings, abdomen, head); computing anatomically-correct reference frames for each leg segment using quaternion math utilities; inferring and placing collision geometries (capsules, ellipsoids, cylinders, spheres) for legs, wings, mouth, antennae, and abdomen; configuring joint ranges, defaults, and child classes for all articulated parts; creating fixed tendons for abdomen and tarsus coupling; adding general and adhesion actuators; excluding self-collision pairs; adding sensors (accelerometer, gyro, velocimeter, touch, force); and adding tracking cameras and lights.

The module provides several quaternion math utility functions (mul_quat, quat_to_mat, mat_to_quat, neg_quat, rot_vec_quat, quat_z2vec) and a key body transformation function change_body_frame that re-frames a body while maintaining all child element positions. The script recompiles the physics model multiple times to obtain updated body positions and inertial properties during the build process. Empirical mass values for the fruitfly body parts are defined at module level.

Usage

Run this script as a standalone command-line tool to regenerate the fruitfly.xml model file. It is a build-time asset generation tool, not intended for import at runtime. The generated model is then used by the fruitfly walker class during simulation.

Code Reference

Source Location

Signature

ASSET_DIR = os.path.dirname(__file__) + '/' + ASSET_RELPATH
BASE_MODEL = 'drosophila_defaults.xml'
FLY_MODEL = 'drosophila_fused.xml'
FINAL_MODEL = 'fruitfly.xml'

_MASS = {
    'head': 0.15, 'thorax': 0.34, 'abdomen': 0.38,
    'leg': 0.0162, 'wing': 0.008,
}  # milligrams

# Quaternion math utilities
def mul_quat(quat_a, quat_b): ...
def quat_to_mat(quat): ...
def mat_to_quat(mat): ...
def neg_quat(quat_a): ...
def rot_vec_quat(vec, quat): ...
def quat_z2vec(vec): ...

# Body frame transformation
def change_body_frame(body, frame_pos, frame_quat): ...

# Main build pipeline
def main(argv: Sequence[str]): ...

Import

# This is a standalone build script, not typically imported.
# Run directly:
# python dm_control/locomotion/walkers/assets/build_fruitfly/make_fruitfly.py

I/O Contract

Inputs

Name Type Required Description
drosophila_defaults.xml XML file Yes Base model with default classes and compiler settings
drosophila_fused.xml XML file Yes Pre-generated fused fly mesh model (output of fuse_fruitfly.py)
Mesh assets .stl/.obj files Yes Mesh files referenced by the fused model, located in the assets directory

Outputs

Name Type Description
fruitfly.xml XML file Complete physics-ready MuJoCo model of the fruitfly walker with joints, collisions, actuators, sensors, cameras, and tendons

Usage Examples

Basic Usage

# Run as a standalone script to generate fruitfly.xml:
# python make_fruitfly.py

# The utility functions can also be used programmatically:
from dm_control.locomotion.walkers.assets.build_fruitfly.make_fruitfly import (
    mul_quat, quat_to_mat, mat_to_quat, change_body_frame
)
import numpy as np

# Multiply two quaternions
q1 = np.array([1.0, 0, 0, 0])  # identity
q2 = np.array([0.0, 0, 0, 1])  # 180-degree rotation about z
q3 = mul_quat(q1, q2)

# Convert quaternion to rotation matrix
mat = quat_to_mat(q2)

# Re-frame a MJCF body while preserving child positions
# change_body_frame(body, new_pos, new_quat)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment