Robotics/ROS2

[ROS2 시작하기 - 0] 환경 셋팅

sinq 2023. 2. 19. 19:27

Setup Your Environment

Install

Environment

  • Oracle VM VirtualBox
  • OS : ubuntu 20.04

Configuration

  • Memory Size : 4 or 8GB
  • Hard disk file type : VDI
  • Hard disk Size : 20 ~ 30GB
  • Settings
    • System → Processor → 3CPU
    • Network → Attached to → Bridged Adapter
    • Storage → Controller : IDE → Empty → Choose/Create a Virtual Optical Disk (your .iso)
  • Installing ubuntu
    • Install Ubuntu
    • Minimal installation
  • For full size Screen
sudo apt update
sudo apt install build-essential gcc make perl dkms

reboot → Devices → Insert guest Addition CD image → run → restart

(If it doesn’t work, try above process)

  • Devices → Shared Clipboard → Bidirectional
  • For upgrade every packages
sudo apt update
sudo apt upgrade
  • Useful terminator
sudo apt install terminator

  • Install VScode

1. Install curl

sudo apt-get install curl

2. Download the Microsoft GPG key and copy it to the /etc/apt/trusted.gpg.d/ path

sudo sh -c 'curl <https://packages.microsoft.com/keys/microsoft.asc> | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg'

3. Add repository to download Visual Studio Code

sudo sh -c 'echo "deb [arch=amd64] <https://packages.microsoft.com/repos/vscode> stable main" > /etc/apt/sources.list.d/vscode.list'

4. fetch package list from the repository

sudo apt update

5. Install Visual Studio Code

sudo apt install code

6. Install Python

sudo apt install python3-pip

Install ROS2

Ubuntu (Debian) - ROS 2 Documentation: Foxy documentation

 

Ubuntu (Debian) — ROS 2 Documentation: Foxy documentation

Make sure you have a locale which supports UTF-8. If you are in a minimal environment (such as a docker container), the locale may be something minimal like POSIX. We test with the following settings. However, it should be fine if you’re using a differen

docs.ros.org

  • To use ros2 command
gedit ~/.bashrc

# insert on last line
source /opt/ros/foxy/setup.bash
  • Install colcon
sudo apt install python3-colcon-common-extensions
  • To use colcon command
gedit ~/.bashrc

# insert on last line
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
  • Create a workspace
mkdir ~/ros2_ws
cd ~/ros2_ws
mkdir src
colcon build
# if you have a problem, it is because of Network
# you can use network, if you set device -> Network -> attached to NAT

cd install
source local_setup.bash # whatever you can make in this workspace now!
  • To use workspace
gedit ~/.bashrc

#insert this in the last line
source ~/ros2_ws/install/setup.bash

Packages

  • Create new ‘python’ package
ros2 pkg create [name] --build-type ament_python --dependencies rclpy #python
ros2 pkg create [name] --build-type ament_cmake --dependencies rclcpp #c++

After creating pkg, you can see package.xml. If you release it later, the following part will be changed.

Default

If you make a package, you should build

  • Build only one package
colcon build --packages-select [name]