Best way to use ROS1 with Apple Silicon
š Iāve been looking for ways to run ROS1 with my M2 Pro macbook since I got it. Along the way Iāve tried Docker, UTM, Parallels Desktop, arm64 virtual machine, x86_64 emulation and eventually converged to using parallels.
ā ļø Turns out running librealsense2 on arm64 mac is more involved than it seems. Please refer to my newest blog for more details! Hoepfully this will help other people that is also struggling to run t265 camera on Apple Silicon mac.
Quick comparison table
MacOS OpenCV build time (-j10): 3 min 50s
OS\Platform | UTM | Parallels | Docker |
---|---|---|---|
Ubuntu 20.04 x86_64 | slow | āĀ Need to set up [arm64 + desktop + rosetta] yourself. OpenCV 3.4.16 build time: 4 min 50s (75%) | slow opencv build time: 8 min 26s (45%) |
Ubuntu 20.04 arm64 | okay [rosetta avail], no librealsense | BC [Simply add amd64 architecture] | fastest, but not build for GUI, harder to use. opencv build time 4:24 (87%), 4:36 with desktop |
Ubuntu 22.04 x86_64 | BC [Use 20.04 x86] | No Gazebo Build time 5:40s | No Gazebo, slow |
Ubuntu 22.04 arm64 | BC [Use 20.04 arm64] | BC [Simply add amd64 architecture] | BC [Use 20.04 arm64] |
BC = Bad combination
š After some digging, I noticed that Parallels actually donāt support installing native amd64 os directly. It does the emlation through this:
- Install arm64 system
- Enable rosetta translation on arm64 system
- Add amd64 architecture to the arm system
- Install amd64 applicatins as usual
āUbuntu 20.04 amd64 emulation with Parallels:
Would be ideal, but does not exist as a preinstalled image [not provided by Parallels so you need to install yourself]
š Notice that Ubuntu officially only provide Ubuntu 20.04 arm64 without desktop environment [server image]. So you would need to run this command afterwards:
1 2 3
sudo apt update sudo apt upgrade sudo apt install ubuntu-desktop
Official documentation to add amd64 architecture is here:
Caveat: Snap packages are no longer availiable since they wrap all dependency inside the package. But in general it shouldnāt be too much of an issue.
Your /etc/apt/sources.list should look like this:
|
|
And then you can:
|
|
Ubuntu 22.04 amd64 emulation with Parallels:
Run this first:
- sudo apt install python3-pip
- pip3 install cmake
And then you can follow this post to compile ROS1 on ubuntu 22.04.
Note that you will not have access to gazebo anymore as itās not officially provided. But you can still use gazebo from ros2
Pros | Cons |
---|---|
Librealsense definitely will work | need to build ROS 1 yourself |
everything is x86_64, wider compatibility | slightly slower than arm64 for sure[By how much?] |
No Gazebo |
Ubuntu 20.04 arm64 VM with UTM:
slower than Parallels, experimental gpu acceleration, so I recommand Parallels
Docker solutions:
The main problem of docker is that itās a little harder to use with GUI applications. Other than that I donāt have a lot of complaints performance wise.
Rosetta and x86_64
In fact, you can do the same thing as in parallels to add x86 repos in arm64 images. And I measured that there is only 15% performance drop from building opencv natively as in macos.
GUI
I plan to explore the GUI options a little more as this has the potential to be the highest performing option.
Actually, you can use noVNC and the experience is pretty good. (except that lxde desktop is a little ugly). Use this dockerfile that has it all set up, pick the focal-arm64 one.
to launch the container, you can use:
|
|
and simply go to 127.0.0.1/6080 for your desktop
with desktop running, the opencv build time dropped a little bit to 4:36, still slightly better than parallels, but really not worth the trouble and sacrifice the look.
Useful commands when mixing X86-64 with arm64
- check package version provided by apt:
|
|
- install specific version you wanted (arm vs amd)
|
|
Intelās official guide to build librealsense on arm64 system.
š§ fyi: if you are hanging at initializing git repo step when patching kernel. You might need to update your script according to latest repo to use https.
you might also need to replace url with kernel.ubuntu.com/git/ubuntu/ā¦.