Run unityhub: Editor Version matter: 2020.3.11f1 version.
Open
-> Robotics-Nav2-SLAM-Example/Nav2SLAMExampleProject
Unity-Robotics-Hub instrucs the setup for unity install ROS2
In your workspace you need to add ROS-TCP-Endpoint in your src
.
Make sure to checkout main-ros2
$ git checkout main-ros2
# in your work space
# build
$ colcon build --packages-select ros_tcp_endpoint --cmake-force-configure --cmake-clean-cache
[Optional] If bridge is necessary:
$ roslaunch rosbridge_server rosbridge_websocket.launch
You need to setup your IP address in unity and then launch this:
$ ros2 run ros_tcp_endpoint default_server_endpoint --ros-args -p ROS_IP:=127.0.0.1 -p ROS_TCP_PORT:=10000
$ ros2 run teleop_twist_keyboard teleop_twist_keyboard
Will appear the movements
$ ros2 topic echo /cmd_vel
In your workspace, add unity_slam_example in your src
folder.
Now you will have two folder in src
- unity_slam_example
- ROS-TCP-Endpoint
# In your workspace build first
$ colcon build --symlink-install
$ ros2 launch unity_slam_example unity_slam_example.py
$ chmod +x A1.x86_64
$ ./A1.x86_64
- For Connection (really uesful)
- Connecting ROS to Unity: Using ROS# and ROSBridge
-ROS2-Unity Setup Tutorial (Will visualizely help.)
-ROS2 UNITY MODELLING, SIMULATION, AND CONTROL
[Fixed] Error appeared in:
To build unity error appeared to build.
/Robotics-Nav2-SLAM-Example/Nav2SLAMExampleProject/Library/PackageCache/com.unity.robotics.warehouse@9fa61061d3/Scripts/Runtime/PerceptionRandomizers/FloorBoxRandomizerShim.cs
Fixed:
using System.Collections.Generic;
using System;
using Unity.Robotics.PerceptionRandomizers.Shims;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Perception.Randomization.Parameters;
using UnityEngine.Perception.Randomization.Randomizers;
using UnityEngine.Perception.Randomization.Randomizers.SampleRandomizers.Tags;
using UnityEngine.Perception.Randomization.Samplers;
using Unity.Simulation.Warehouse;
using UnityEngine.Perception.Randomization.Scenarios;
using Object = UnityEngine.Object;
[Serializable]
[AddRandomizerMenu("Robotics/Floor Box Randomizer")]
public class FloorBoxRandomizerShim : RandomizerShim
{
public int numBoxToSpawn;
public int maxPlacementTries = 100;
FloatParameter random = new FloatParameter {value = new UniformSampler(0f, 1f)};
SurfaceObjectPlacer placer;
GameObject parentFloorBoxes;
List<CollisionConstraint> constraints;
CollisionConstraint turtleConstraint;
AppParam appParam;
ShelfBoxRandomizerShim m_ShelfBoxRandomizerShim;
protected override void OnAwake()
{
if (WarehouseManager.instance == null)
{
var warehouseManager = GameObject.FindObjectOfType<WarehouseManager>();
appParam = warehouseManager.appParam;
}
// Add collision constraints to spawned shelves
var tags = tagManager.Query<ShelfBoxRandomizerTag>();
if (!Application.isPlaying)
tags = GameObject.FindObjectsOfType<ShelfBoxRandomizerTag>();
constraints = new List<CollisionConstraint>();
foreach (var tag in tags)
{
var shelf = new CollisionConstraint(tag.transform.position.x, tag.transform.position.z, tag.GetComponentInChildren<Renderer>().bounds.extents.x);
constraints.Add(shelf);
}
base.OnAwake();
}
protected override void OnScenarioStart()
{
var scenario = GameObject.FindObjectOfType<Scenario<ScenarioConstants>>();
m_ShelfBoxRandomizerShim = scenario.GetRandomizer<ShelfBoxRandomizerShim>();
base.OnScenarioStart();
}
protected override void OnIterationStart()
{
if (GameObject.Find("GeneratedWarehouse") == null)
return;
// Create floor boundaries for spawning
var bounds = new Bounds(Vector3.zero, new Vector3(appParam.width, 0, appParam.length));
placer = new SurfaceObjectPlacer(bounds, random, maxPlacementTries);
// Instantiate boxes at arbitrary location
parentFloorBoxes = new GameObject("FloorBoxes");
for (int i = 0; i < numBoxToSpawn; i++)
{
//GameObject o;
GameObject o = new GameObject();
if (!Application.isPlaying)
{
#if UNITY_EDITOR
o = PrefabUtility.InstantiatePrefab(m_ShelfBoxRandomizerShim.GetBoxPrefab()) as GameObject;
#endif
o.transform.parent = parentFloorBoxes.transform;
}
else
o = Object.Instantiate(m_ShelfBoxRandomizerShim.GetBoxPrefab(), parentFloorBoxes.transform);
o.AddComponent<FloorBoxRandomizerTag>();
o.AddComponent<RotationRandomizerTag>();
}
// Begin placement interation
placer.IterationStart();
var tags = tagManager.Query<FloorBoxRandomizerTag>();
if (!Application.isPlaying)
tags = GameObject.FindObjectsOfType<FloorBoxRandomizerTag>();
foreach (var tag in tags)
{
bool success = placer.PlaceObject(tag.gameObject);
if (!success)
{
return;
}
}
}
protected override void OnIterationEnd()
{
if (!Application.isPlaying)
Object.DestroyImmediate(parentFloorBoxes);
else
Object.Destroy(parentFloorBoxes);
}
}