Skip to main content

AR4-Control software on Apple Silicon (Mac M1-M4)

Hi community,

I’m very excited to experiment with the new AR4-HMI build and currently have version 6.3.1 running from source on Ubuntu 22.04.
Since I’ve gotten older versions (4.xx and 5.xx) running on my Mac M1 (Apple Silicon, ARM CPU) — which is actually my main machine for coding — I recently discovered that the GitHub source files are not compatible with my laptop’s architecture.

When running python AR4.py after completing all setup steps, I get the following error:

Traceback (most recent call last):
  File "../x/AR4.py", line 167, in <module>
    import ARrobots.robot_kinematics as robot
ModuleNotFoundError: No module named 'ARrobots.robot_kinematics'

I understand that the build relies on .pyd and .so library imports. As Chris Annin explained, these files are similar to Windows .dll files and bundle specific functionality. The downside is that they need to be precompiled for each architecture. From the files in the ARrobots folder, I can see that the libraries were compiled for Linux x86_64 (Python 3.11 and one for 3.12) and for Windows x64.

Since I’m running ARM, I’m wondering if anyone could help me build the .so/.pyd files for Mac M1.
Am I correct in assuming that everything needed for the build is in the ARrobots/src folder?
I’m really looking forward to your help!

Best regards,
Justin

P.S.: I also have Windows for ARM installed on the same system, and I can confirm that the program runs when using the downloadable .exe from the download section. Does this mean the .pyd file is both x86_64 and ARM compatible or is this the windows conversion layer at work; going from ARM instructions to X64?

Jason Kirk

I've built the kinematics before on my Mac M3. I'll get this too you ASAP.

I can't say if the windows .dll is compiled cross platform or just has a conversion layer.

When Linux support gets out of Beta Darwin is next.

There are places in the code that definitely won't work. At the very least you'll have to replace all of the if platform == "Linux" with "Darwin"

I also expect that vision won't work for you even then.

Jason Kirk

Darwin ARM64 kinematics for python 3.9-3.13 merged to main.

Please see notes about other compatibility issues.

Joachim Dahl

I was able to run the basic control software on a Macbook Pro M4.

cd git/ar4-hmi/ARrobots/src

cmake -S. -Bbuild -Dpybind11_DIR="/opt/homebrew/lib/python3.14/site-packages/pybind11"

cmake --build build

cp build/robot_kinematics.cpython-313-darwin.so ../

I also got the camera working with moderately small changes to the Python code, but something is strange in cropping of the images, and I haven't figured out that part yet.

Jason Kirk

Joachim Dahl This is a known issue. There is a cropping improvement for *nix in the next upcoming version. Just a minor change to how the window is managed.

DM me if you need the fix now.

Joachim Dahl

Jason Kirk It would be great if you can share a fix for the cropping issue. I wanted to play with the vision parts... I don't see anywhere to send DMs on the forum, though.

Jason Kirk

Joachim Dahl I don't either, sorry about that.
There are some other changes to the code in this area, but I believe these are the ones that fix the crop behavior on Linux.

AR4.py
--------------------------------
10046: -cv2.imshow("Cropped", roi)
+cv2.imshow("image", roi)

10064: -cv2.namedWindow("image")
+cv2.namedWindow("image", cv2.WINDOW_NORMAL)

10067: +cv2.waitKey(0)

Let me know if that doesn't cover it.

Joachim Dahl

Jason Kirk The issue is that the image on left is not scaled to cover the gray area. In contrast to the behavior on my Windows Laptop.

Justin Iszatt

Joachim Dahl 
I just checked the zooming on my linux machine and can't reproduce this... For me the zoomed image is correctly scaled.
I am struggling to teach objects right now, but this is definitely lack of experience with the AR4-HMI...

regarding the buil for Mac I was able to get it running after some tk/ttk problems. as we have a platform guard for linux and windows, I am looking a little deeper into the camera stream topic now.
as v4l2-ctl is not available on Mac, I am thinking of rewriting the whole listing..

Justin Iszatt

hi Joachim Dahl and Jason Kirk 

Thank you for the fix and the detailed instructions. Before checking on this thread just now I was actually able to build the kinematics on my M1!!

Will try the new version now, thanks again. Definitely learned (or rather "had to learn") something new!
As I added some system-guards myself for the last versions I have been using, I know what to look for and see if I can fix something myself.
As you already pushed to master and are a contributor, could you also add "v4l2-ctl" in the readme.md's "linux" part? Maybe just adding to "sudo apt-get install wmctrl"

In any case thanks again!
LG

J