작성자: 박준규

최초작성 2023.01.03 수정 2023.01.22(일)

이런 말을 했었지만:

We will be using Ubuntu 18.04 + ROS Melodic due to the vast amount of documentation and tutorials available compared to ROS Noetic or ROS2.

저희는 ROS2로 넘아갑니다: ROS2 스터디 노트 (2기, OLD)

Installing ROS Melodic on M1 Mac using Multipass:

M1맥에서 ROS 개발환경 세팅하기

(Steps listed below incase webpage above is removed)

These steps assume that you already have brew installed: https://brew.sh

  1. Install Multipass:

    brew install --cask multipass

  2. Setup an Ubuntu virtual environment:

    multipass launch 18.04 -n ros-melodic -c 4 -m 4G -d 40G

    The terminal command above means:

    multipass launch 18.04 //Setup virtual environment as Ubuntu 18.04

    -n ros-melodic //name: ros-melodic

    -c 4 //4 cores

    -m 4G //4GB memory

    -d 40G //40GB hard disk space

  3. We can now connect to the Ubuntu VM using Terminal:

    multipass shell ros-melodic

    exit											// exit multipass shell
    
    multipass start [VM name]						// start VM 
    multipass start ros-melodic
    
    multipass stop [VM name]						// stop VM
    miltipass stop ros-melodic
    
    multipass restart [VM name]						// restart VM
    multipass restart ros-melodic
    
    multipass delete [VM name]						// delete VM
    multipass delete ros-melodic
    
    multipass purge									// completely delete a deleted VM
    
    multipass list									// list of VMs
    
    multipass info [VM name]						// details of particular VM
    multipass info ros-melodic
    
    multipass info --all							// details of all VMs
    
    multipass mount [folder path] [VM name]:[folder path]	// share folders between PC and VM (mount)
    multipass mount /Users/[USERNAME]/Documents/ros_workspace ros-melodic:~/ros_workspace
    
    multipass unmount [VM name]						// dismount
    multipass unmount ros-melodic
    

    Untitled

  4. Once logged in, set up a password for the user ubuntu :

    sudo passwd ubuntu

  5. The Ubuntu VM currently only supports CLI. To support GUI and for us to RDP into the machine, we will install ubuntu-desktop and xrdp:

    sudo apt update //update APT list

    sudo apt install ubuntu-desktop xrdp // Install Ubuntu Desktop and XRDP

  6. Install Microsoft Remote Desktop on your Mac:

    Untitled

  7. To connect to the Ubuntu VM using Microsoft Remote Desktop, we need to know the IPv4 address of the VM:

    In a new Terminal window:multipass info ros-melodic

    With the IPv4 address known, we can now connect to the Ubuntu VM using Microsoft Remote Desktop.

  8. Installing ROS Melodic:

    In the Ubuntu VM, open a Terminal window and type the following commands:

    // Sources.list setup
    sudo sh -c 'echo "deb <http://packages.ros.org/ros/ubuntu> $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
    
    // Curl installation and setup
    sudo apt install curl
    curl -s <https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc> | sudo apt-key add -
    
    // APT list update
    sudo apt update
    
    // ROS Melodic Dekstop installation
    sudo apt install ros-melodic-desktop-full
    
    // Bash setup (auto load on startup)
    echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    
    // setup dependencies
    sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    sudo rosdep init
    rosdep update
    
  9. Multipass Mount

    We can share files between our Mac and the VM using Multipass Mount :

    multipass mount [folder path on Mac] [VM name]:[path to VM]

    Example: multipass mount /Users/[Username]/Documents/ros_workspace ros-melodic:~/ros_workspace

    Now we can use Finder to access files on our VM. We can also see that the directory has been added in our VM:

    Untitled

  10. Additional steps:

    on the Ubuntu VM:

    sudo apt install python3-pip //install pip3
    
    pip3 install catkin_pkg //install dependency
    
    cd [mounted path]
    cd ~/ros_workspace
    
    mkdir -p src								// create src folder
    cd src										// move to src folder
    catkin_init_workspace						// designate workspace
    
    cd ..										// move up a folder
    catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3		// build workspace
    
    #after catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3 has been run once, you can just use catkin_make afterwards.
    
    source [path to workspace]/devel/setup.bash		// setup script
    source ~/ros_workspace/devel/setup.bash
    

    Now the ROS workspace has been setup.

    Setting up Bash automatically on startup:

    // Bash setup (start on startup)
    echo "source ~/ros_workspace/devel/setup.bash" >> ~/.bashrc
    source ~/.bashrc