Skip to content
UBC-SnowbotsPublic

About

For our unity Simulations

Resources

Stars

2 stars

Watchers

3 watching

Forks

Latest commit

 

History

180 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimFlake

Unity simulator for the UBC Snowbots rover. It works with the ROS 2 Jazzy stack in RoverFlake2 on Ubuntu 24.04.

Workflow document (internal for rover members): https://docs.google.com/document/d/1W4p3Dt0q54WnVc1O408SYnV7q7jjMJXXKghRvAwRw5M/edit?tab=t.0

Setup (once)

You need Ubuntu 24.04 with ROS 2 Jazzy (RoverFlake2's setup installs it).

git clone https://github.com/UBC-Snowbots/SimFlake.git
cd SimFlake && ./setup.sh

setup.sh installs ros-jazzy-rosbridge-suite (the only ROS package the sim needs). It also offers to install Unity Hub and the exact Unity version the project uses. Then, in Unity Hub: Projects > Add > Add project from disk > SimFlake/rover_sim, and open it.

Using the sim

  1. Open a scene in Assets/Scenes. TaskWorlds/WaypointTask has everything; ArmScene is the arm on a table.
  2. Press Play. The sim starts rosbridge for you and the top-right of the Game view shows ROS: connected. It uses the ROS setup from your ~/.bashrc, or from the terminal you launched Unity from. You don't need to source anything first.
  3. Use it like the real rover: The sim stands in for RoverFlake2's motor_control_node (it takes /left_wheel_speeds + /right_wheel_speeds), so run the drive stack as on the rover: Esc > ROS starts wheel_speed_node (and joy, RViz, any command) with one click. Same tab, DRIVE INPUT = /CMD_VEL DIRECT skips RoverFlake2's drive control and drives straight from /cmd_vel.
    python3 tools/sim_check.py --drive        # is everything publishing? drives the rover a bit (publishes /cmd_vel)
    ros2 run teleop_twist_keyboard teleop_twist_keyboard
    ros2 run rover_hmi main_hmi_node          # cmd_vel + arm panel (the sim arm listens on /arm/command, no sim_helper needed)
    rviz2                                     # /camera/image_raw, /scan, /odom ...

Topics, conventions and how the ROS link works are documented in CLAUDE.md.

Windows and macOS

The sim runs on Windows 10/11 (x64) and macOS 10.13+ (Intel and Apple Silicon) as a standalone player. ROS stays on Linux: the player connects to a rosbridge running somewhere else. Not tested on real Windows / Mac hardware yet: please report what you see.

Get the player: someone on Linux runs tools/build_players.sh (needs the editor's Windows and Mac Build Support (Mono) modules) and shares Builds/Players/SimFlake-<commit>-windows.zip / -macos.zip. Unzip it.

  • Windows: run SimFlake.exe. SmartScreen may say "Windows protected your PC": More info > Run anyway.
  • macOS: the app isn't notarized. In Terminal, xattr -cr SimFlake.app once (otherwise macOS calls it damaged), then open it.

Connect ROS: the sim can't start rosbridge or ROS nodes itself there (the Esc > ROS buttons only work on Linux). Run rosbridge where ROS 2 Jazzy is, together with RoverFlake2's nodes:

ros2 launch rosbridge_server rosbridge_websocket_launch.xml        # port 9090, all interfaces

then start the player with --rosbridge-url ws://<that machine's IP>:9090:

  • Windows + WSL2 (Ubuntu 24.04 with ROS Jazzy + ros-jazzy-rosbridge-suite inside WSL): SimFlake.exe --rosbridge-url ws://localhost:9090.
  • Another Linux machine on the network: its IP. Both on the same network, port 9090 open.
  • macOS: a Linux machine, or Docker (docker run -it -p 9090:9090 ros:jazzy, then apt install ros-jazzy-rosbridge-suite inside it). ROS nodes then run in that container (DDS discovery doesn't cross Docker Desktop's VM).

Without rosbridge the sim still runs (drive with the arrow keys, astronaut, menus); topics just go nowhere. Camera images share that rosbridge (on Linux the sim starts a second one on 9091 for them), so several raw cameras at once can slow down /cmd_vel (claude/rosbridge-camera-starvation.md). To avoid it, run a second rosbridge for the cameras (ros2 run rosbridge_server rosbridge_websocket --ros-args -r __node:=rosbridge_streams -p port:=9091) and add --rosbridge-stream-url ws://<host>:9091.

Unity editor on Windows / macOS: works like on Linux (Unity Hub, add rover_sim, install the version it asks for); skip setup.sh (Linux only). Pressing Play doesn't start rosbridge: run it as above and set the environment variable SIMFLAKE_ROSBRIDGE_URL=ws://<host>:9090 before starting Unity Hub (or drop a RosConnection component into the scene and set its URL). If camera images come out upside down on Windows or macOS, run the player with --camera-readback bottom-up and tell us (see SensorCamera.ReadbackIsTopDown).

Adding things

  • Unity assets (Asset Store or otherwise): import them, then drag the new folder into rover_sim/Assets/ThirdParty in Unity (the Asset Store always imports at the top of Assets/) and commit. Everyone gets them on pull.
  • URDF robots: copy the ROS description package into Assets/Robots/Descriptions/, right-click the .urdf and choose Import Robot from Selected URDF file (VHACD for exact colliders). Then add MotorController / ArmController and sensors, or update the prefab in Assets/Robots/.
  • New sensors / topics: see "Writing sim code" in CLAUDE.md. It's a few lines with Ros.Advertise / Ros.Subscribe.

Troubleshooting

  • "ROS: waiting for rosbridge": check the Console for [rosbridge] lines. Run ./setup.sh if rosbridge is missing, or start it by hand: ros2 run rosbridge_server rosbridge_websocket.
  • Topics don't show up in ros2 topic list: your terminal and the sim are on different ROS_DOMAIN_IDs. The sim uses the one from ~/.bashrc (or from the terminal that launched Unity).
  • Unity says the project is locked: another Unity instance has it open.

About

For our unity Simulations

Resources

Stars

2 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages