A Bevy plugin for importing robots from URDF files and running physics simulations. Ground vehicles use Rapier physics, while drones are simulated using integrated dynamics models.
- Import URDF robot descriptions into Bevy
- Support for STL and OBJ mesh formats
- Rapier physics integration for ground vehicles
- Custom dynamics simulation for drone vehicles
- Event-driven sensor reading and motor control
- Multiple robot type support (ground vehicles, quadrupeds, drones)
Add to your Cargo.toml:
[dependencies]
bevy_urdf = "0.3.0" # Replace with actual versionAdd the necessary plugins to your Bevy app:
use bevy::prelude::*;
use bevy_urdf::{UrdfPlugin, StlPlugin, ObjPlugin, CameraControlPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((
UrdfPlugin,
StlPlugin,
ObjPlugin,
CameraControlPlugin,
))
.run();
}Load a robot in your startup systems:
use bevy_urdf::{LoadRobot, RobotLoaded};
fn setup(mut load_robot_events: EventWriter<LoadRobot>) {
load_robot_events.send(LoadRobot {
urdf_path: "robots/flamingo_edu/urdf/Edu_v4.urdf".to_string(),
mesh_dir: "assets/robots/flamingo_edu/urdf".to_string(),
});
}Subscribe to the loaded event and spawn the robot:
use bevy_urdf::{RobotLoaded, SpawnRobot, RobotType};
fn start_simulation(
mut robot_loaded_events: EventReader<RobotLoaded>,
mut spawn_robot_events: EventWriter<SpawnRobot>,
mut next_state: ResMut<NextState<AppState>>,
) {
for event in robot_loaded_events.read() {
spawn_robot_events.send(SpawnRobot {
handle: event.handle.clone(),
mesh_dir: event.mesh_dir.clone(),
robot_type: RobotType::NotDrone,
});
next_state.set(AppState::Simulation);
}
}The plugin uses an event-driven architecture for robot control and sensor feedback:
#[derive(Event)]
pub struct SensorsRead {
pub handle: Handle<UrdfAsset>,
pub transforms: Vec<Transform>,
pub joint_angles: Vec<f32>,
}For ground-based robots and vehicles:
#[derive(Event)]
pub struct ControlMotors {
pub handle: Handle<UrdfAsset>,
pub velocities: Vec<f32>,
}For aerial vehicles and drones:
#[derive(Event)]
pub struct ControlThrusts {
pub handle: Handle<UrdfAsset>,
pub thrusts: Vec<f32>,
}For underwater vehicles:
#[derive(Event)]
pub struct ControlThrusters {
pub handle: Handle<UrdfAsset>,
pub thrusts: Vec<f32>,
}Control the viewing angle of any active camera:
#[derive(Event)]
pub struct RotateCamera {
pub delta_yaw: f32,
pub delta_pitch: f32,
}RobotType::NotDrone- Ground vehicles, quadrupeds, manipulatorsRobotType::Drone- Aerial vehicles with thrust-based controlRobotType::Uuv- Underwater vehicles with thruster control
Run the included examples to see the plugin in action:
# Drone simulation
cargo run --example quadrotor --release
# Quadruped robot simulation
cargo run --example quadruped --release
# Underwater vehicle simulation
cargo run --example uuv --releaseBefore using URDF files with this plugin:
- Mesh Paths: Ensure all mesh file references use relative paths
- Unsupported Elements: Remove or replace
package://URIs - Gazebo Elements: Gazebo-specific nodes are not supported and should be removed
Example of supported mesh reference:
<!-- Good: relative path -->
<mesh filename="meshes/base_link.stl"/>
<!-- Not supported: package URI -->
<mesh filename="package://robot_description/meshes/base_link.stl"/>- Package URIs (
package://) are not supported - Gazebo-specific URDF elements are ignored
- Drone rotor animations are not yet implemented
- Limited to STL and OBJ mesh formats
Contributions are welcome! Please feel free to submit issues and pull requests.