Convert Figma logo to code with AI

Unity-Technologies logoUnity-Robotics-Hub

Central repository for tools, tutorials, resources, and documentation for robotics simulation in Unity.

1,981
411
1,981
48

Top Related Projects

A flexible, high-performance 3D simulator for Embodied AI research.

Quick Overview

The Unity-Technologies/Unity-Robotics-Hub is a GitHub repository that provides tutorials, documentation, and working examples for robotics simulation in Unity. It aims to bridge the gap between Unity's game development capabilities and robotics applications, offering tools and resources for simulating and testing robotic systems.

Pros

  • Integrates Unity's powerful 3D rendering and physics engine with robotics simulation
  • Provides comprehensive tutorials and examples for various robotics applications
  • Supports ROS (Robot Operating System) integration for seamless communication with real-world robotic systems
  • Offers a user-friendly interface for both robotics engineers and game developers

Cons

  • Requires familiarity with Unity, which may have a learning curve for traditional robotics developers
  • Limited compared to some dedicated robotics simulation platforms in terms of specialized features
  • May require additional setup and configuration for complex robotics scenarios
  • Performance may be impacted when simulating large-scale or highly detailed robotic environments

Code Examples

// Example 1: Creating a simple robot joint
public class RobotJoint : MonoBehaviour
{
    public float minAngle = -90f;
    public float maxAngle = 90f;
    
    public void RotateJoint(float angle)
    {
        float clampedAngle = Mathf.Clamp(angle, minAngle, maxAngle);
        transform.localRotation = Quaternion.Euler(0, clampedAngle, 0);
    }
}

This code creates a basic robot joint with angle limits and a rotation method.

// Example 2: Subscribing to ROS topics
using Unity.Robotics.ROSTCPConnector;
using RosMessageTypes.Std;

public class ROSSubscriber : MonoBehaviour
{
    ROSConnection ros;

    void Start()
    {
        ros = ROSConnection.GetOrCreateInstance();
        ros.Subscribe<StringMsg>("/chatter", ChatterCallback);
    }

    void ChatterCallback(StringMsg msg)
    {
        Debug.Log("Heard: " + msg.data);
    }
}

This example demonstrates how to subscribe to a ROS topic and handle incoming messages.

// Example 3: Publishing to ROS topics
using Unity.Robotics.ROSTCPConnector;
using RosMessageTypes.Geometry;

public class ROSPublisher : MonoBehaviour
{
    ROSConnection ros;
    public string topicName = "unity_position";

    void Start()
    {
        ros = ROSConnection.GetOrCreateInstance();
        ros.RegisterPublisher<PoseMsg>(topicName);
    }

    void PublishPosition()
    {
        PoseMsg pose = new PoseMsg();
        pose.position = new PointMsg(transform.position.x, transform.position.y, transform.position.z);
        pose.orientation = new QuaternionMsg(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
        ros.Publish(topicName, pose);
    }
}

This code shows how to publish robot position data to a ROS topic.

Getting Started

  1. Clone the Unity-Robotics-Hub repository:
    git clone https://github.com/Unity-Technologies/Unity-Robotics-Hub.git
    
  2. Open Unity and create a new 3D project
  3. Import the Unity Robotics packages from the Package Manager
  4. Follow the tutorials in the repository's documentation to set up your first robotics simulation

For detailed instructions and examples, refer to the repository's README and documentation.

Competitor Comparisons

A flexible, high-performance 3D simulator for Embodied AI research.

Pros of Habitat-sim

  • Highly optimized for performance, allowing for faster simulation speeds
  • Supports photorealistic 3D environments and physics-based rendering
  • Extensive documentation and active community support

Cons of Habitat-sim

  • Steeper learning curve for beginners compared to Unity-based solutions
  • Limited integration with real-world robotics hardware
  • Primarily focused on AI research rather than general robotics applications

Code Comparison

Unity-Robotics-Hub:

using UnityEngine;
using Unity.Robotics.ROSTCPConnector;

public class RobotController : MonoBehaviour
{
    ROSConnection ros;
}

Habitat-sim:

import habitat_sim
import numpy as np

sim_settings = {
    "width": 256,
    "height": 256,
    "scene": "path/to/scene.glb"
}
cfg = habitat_sim.SimulatorConfiguration(sim_settings)

The Unity-Robotics-Hub code snippet demonstrates the integration with ROS, while the Habitat-sim code shows the setup of a simulation environment. Unity-Robotics-Hub is more accessible for those familiar with Unity and C#, while Habitat-sim offers more fine-grained control over simulation parameters using Python.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Unity Robotics Hub

License ROS ROS ROS Unity

This is a central repository for tools, tutorials, resources, and documentation for robotic simulation in Unity.

The contents of this repository are in active development. Its features and API are subject to significant change as development progresses.


We're currently working on lots of things! Please take a short moment fill out our survey to help us identify what products and packages to build next.


Introduction

Simulation plays an important role in robotics development, and we’re here to ensure that roboticists can use Unity for these simulations. We're starting off with a set of tools to make it easier to use Unity with existing ROS-based workflows. Try out some of our samples below to get started quickly.

Getting Started

Quick Installation Instructions

Brief steps on installing the Unity Robotics packages.

Pick-and-Place Tutorial

A complete end-to-end demonstration, including how to set up the Unity environment, how to import a robot from URDF, and how to set up two-way communication with ROS for control.

Object Pose Estimation Tutorial

A complete end-to-end demonstration in which we collect training data in Unity and use that data to train a deep neural network to predict the pose of a cube. This model is then deployed in a simulated robotic pick-and-place task.

Articulations Robot Demo

A robot simulation demonstrating Unity's new physics solver (no ROS dependency).

[New!] Navigation 2 SLAM Example

An example simulation environment, integrated with ROS 2 and [New!] Visualizations, which enables the exercise of ROS 2's Navigation 2 and slam_toolbox packages using a simulated Turtlebot 3.

Documentation

TutorialDescription
ROS–Unity IntegrationA set of component-level tutorials showing how to set up communication between ROS and Unity
URDF ImporterSteps on using the Unity package for loading URDF files
[New!] VisualizationsUsage instructions for adding visualizations for incoming and outgoing ROS messages

Component Repos

RepoFunctionality
ROS TCP EndpointROS node for sending/receiving messages from Unity
ROS TCP ConnectorUnity package for sending, receiving, and visualizing messages from ROS
URDF ImporterUnity package for loading URDF files

Additional Resources

Blog Posts and Talks

  • [New!] (October 4, 2021) Introducing: Unity Robotics Visualizations Package blog post
  • (August 13, 2021) Advance your robot autonomy with ROS 2 and Unity blog post
  • (March 2, 2021) Teaching robots to see with Unity blog post
  • (November 19, 2020) Robotics simulation in Unity is as easy as 1, 2, 3! blog post
  • (November 12, 2020) Unite Now 2020: Simulating Robots with ROS and Unity video
  • (August 26, 2020) Announcing Unity Robotic Simulation blog post
  • (May 20, 2020) Use articulation bodies to easily prototype industrial designs with realistic motion and behavior blog post

More from Unity

New Physics Features in Unity

New Features

  • Contact Modification API This API will allow users to define custom contact reactions, such as ignoring subsets of contact points, in order to help simulate holes, slippery surfaces, soft contacts, and more. It is available in Unity versions 2021.2a12+. Read more about the new Contact Modification API.
  • Collision detection modes exposed for ArticulationBody: discrete, sweep-based CCD, and speculative CCD. New continuous collision detection (CCD) modes will ensure that fast-moving objects collide with objects, instead of tunneling or passing through those objects, which can happen in the default “discrete” mode. This API is available in Unity versions 2020.3.5f1+. Read more about continuous collision detection.

Coming Soon

Here’s a peek into what our Physics Team is hard at work on…

  • Wheel Collider shapes. This feature will allow the user to specify the shape of the collider to be used for collision detection. Currently the collider shape is fixed to a cylinder, and collision detection is performed by casting a ray from the center of the cylinder. Custom shapes will improve the accuracy of simulating wheels over rough terrains, holes, etc. Read more about Wheel Collider.
  • Force/Torque Sensor API. This API will allow users to get the force and torque acting on an articulation body (useful for simulating a force/torque sensor!), as well as to get the motor torque applied by an articulation drive.
  • Query primitives. These simple, GameObject-less shapes allow for collision detection without requiring simulation (i.e., without calling Physics.Simulate). This feature will allow users to initialize objects in feasible locations, and can also be used for motion planning.

ROS 2

ROS2 support is now available! You can get started by following this tutorial.

Community and Feedback

The Unity Robotics projects are open-source and we encourage and welcome contributions. If you wish to contribute, be sure to review our contribution guidelines and code of conduct.

Support

For questions or discussions about Unity Robotics package installations or how to best set up and integrate your robotics projects, please create a new thread on the Unity Robotics forum and make sure to include as much detail as possible.

For feature requests, bugs, or other issues, please file a GitHub issue using the provided templates and the Robotics team will investigate as soon as possible.

For any other questions or feedback, connect directly with the Robotics team at unity-robotics@unity3d.com.

Newsletter

To get notified about new updates and features, sign up for our newsletter!

FAQs

FAQs

License

Apache License 2.0