Contents

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

bookmark

šŸ“Œ After some digging, I noticed that Parallels actually donā€™t support installing native amd64 os directly. It does the emlation through this:

  1. Install arm64 system
  2. Enable rosetta translation on arm64 system
  3. Add amd64 architecture to the arm system
  4. 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:

bookmark

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal main restricted
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal universe
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal universe
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-updates universe
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal multiverse
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-updates multiverse
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted universe multiverse
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ focal-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-security universe
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ focal-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security universe
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-security multiverse
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ focal-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security multiverse

And then you can:

1
2
sudo dpkg --add-architecture amd64
sudo apt update

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.

bookmark

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.

bookmark

to launch the container, you can use:

1
docker run -p 6080:80 -v /dev/shm:/dev/shm dorowu/ubuntu-desktop-lxde-vnc:focal-arm64

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:
1
apt list -a packagename
  • install specific version you wanted (arm vs amd)
1
sudo apt install packagename:amd64=vernum

Intelā€™s official guide to build librealsense on arm64 system.

bookmark

šŸš§ 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/ā€¦.

bookmark