Skip to content

Instantly share code, notes, and snippets.

@Coderx7
Last active August 16, 2021 04:33
Show Gist options
  • Save Coderx7/f917d9af5d756c38dca5c4373a114f10 to your computer and use it in GitHub Desktop.
Save Coderx7/f917d9af5d756c38dca5c4373a114f10 to your computer and use it in GitHub Desktop.
ubuntu_sim_ros_noetic.sh
#!/bin/bash
## Bash script for setting up ROS Neotic (with Gazebo 9) development environment for PX4 on Ubuntu LTS (20.04).
## It installs the common dependencies for all targets (including Qt Creator)
##
## Installs:
## - Common dependencies libraries and tools as defined in `ubuntu_sim_common_deps.sh`
## - ROS Melodic (including Gazebo9)
## - MAVROS
if [[ $(lsb_release -sc) == *"xenial"* ]]; then
echo "OS version detected as $(lsb_release -sc) (16.04)."
echo "ROS Noetic requires at least Ubuntu 20.04."
echo "Exiting ...."
return 1;
fi
echo "Downloading dependent script 'ubuntu_sim_common_deps.sh'"
# Source the ubuntu_sim_common_deps.sh script directly from github
common_deps=$(wget https://gist.githubusercontent.com/Coderx7/33412f5b840345950a09fe3b021106db/raw/93b1b0187d801beefaf1112dafaeae836bfa4df1/ubuntu_sim_common_deps.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'ubuntu_sim_common_deps.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
. <(echo "${common_deps}")
# ROS Noetic
## Gazebo simulator dependencies
sudo apt-get install protobuf-compiler libeigen3-dev libopencv-dev -y
## ROS Gazebo: http://wiki.ros.org/noetic/Installation/Ubuntu
## Setup keys
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
## For keyserver connection problems substitute hkp://pgp.mit.edu:80 or hkp://keyserver.ubuntu.com:80 above.
sudo apt-get update
## Get ROS/Gazebo
sudo apt install ros-noetic-desktop-full -y
## Initialize rosdep
sudo rosdep init
rosdep update
## Setup environment variables
rossource="source /opt/ros/noetic/setup.bash"
if grep -Fxq "$rossource" ~/.bashrc; then echo ROS setup.bash already in .bashrc;
else echo "$rossource" >> ~/.bashrc; fi
eval $rossource
## Install rosinstall and other dependencies
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -y
# MAVROS: https://dev.px4.io/en/ros/mavros_installation.html
## Install dependencies
sudo apt-get install python3-catkin-tools python3-rosinstall-generator -y
#sudo apt-get install ros-noetic-geographic_info -y
sudo apt-get install ros-noetic-geographic-msgs -y
sudo apt-get install libgeographic-dev ros-noetic-geographic-msgs -y
# python deps for mavros
pip3 install empy
## Create catkin workspace
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin init
wstool init src
## Install MAVLink
###we use the Kinetic reference for all ROS distros as it's not distro-specific and up to date
rosinstall_generator --rosdistro kinetic mavlink | tee /tmp/mavros.rosinstall
## Build MAVROS
### Get source (upstream - released)
rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall
### Setup workspace & install deps
wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src
if ! rosdep install --from-paths src --ignore-src -y; then
# (Use echo to trim leading/trailing whitespaces from the unsupported OS name
unsupported_os=$(echo $(rosdep db 2>&1| grep Unsupported | awk -F: '{print $2}'))
rosdep install --from-paths src --ignore-src --rosdistro noetic -y --os ubuntu:focal
fi
if [[ ! -z $unsupported_os ]]; then
>&2 echo -e "\033[31mYour OS ($unsupported_os) is unsupported. Assumed an Ubuntu 20.04 installation,"
>&2 echo -e "and continued with the installation, but if things are not working as"
>&2 echo -e "expected you have been warned."
fi
#Install geographiclib
sudo apt install geographiclib-tools -y
echo "Downloading dependent script 'install_geographiclib_datasets.sh'"
# Source the install_geographiclib_datasets.sh script directly from github
install_geo=$(wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'install_geographiclib_datasets.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
sudo bash -c "$install_geo"
## Build!
catkin build
## Re-source environment to reflect new packages/build environment
catkin_ws_source="source ~/catkin_ws/devel/setup.bash"
if grep -Fxq "$catkin_ws_source" ~/.bashrc; then echo ROS catkin_ws setup.bash already in .bashrc;
else echo "$catkin_ws_source" >> ~/.bashrc; fi
eval $catkin_ws_source
@Coderx7
Copy link
Author

Coderx7 commented Aug 15, 2021

Update:
For the latest version check out this repository : https://github.com/Coderx7/ros-noetic-PX4-easy-installer

Old:
This installs ROS + Mavros + gazebo and all of the dependencies (Qt, JRE, etc) on ubuntu 20.04.
basically, this is the replacement for the same script for ubuntu 18.04 (link) updated for ubuntu 20.04 and ros noetic.
Please note that it also installs anaconda3. (if you don't like this, you can choose "no" when it comes to installing anaconda3, and carry on without it. the rest of the installation should succeed just fine).
Also, the latest version of CMake and git are installed (if they are not previously installed).

Simply do :

wget https://gist.githubusercontent.com/Coderx7/f917d9af5d756c38dca5c4373a114f10/raw/e28d5f073c554a9b3dbbfb2ab10bb658eb438b06/ubuntu_sim_ros_noetic.sh
chmod +x /ubuntu_sim_ros_noetic.sh
./ubuntu_sim_ros_noetic.sh

Follow the onscreen instructions.

<>
توجه برای ایرانیان :
لطفا قبل از اقدام به نصب نسبت به استفاده از یک وی پی ان و تنظیم دی ان اس شکن اقدام کنید تا در فرایند نصب بعلت تحریم با مشکل مواجه نشید
Before going on any further, in order to circumvent sanctions, set the shecan DNS nameserver so the script doesn't fail:
Run:

sudo nano /etc/resolv.conf 

and add

nameserver 178.22.122.100

and then save.
Just note that after restarting your machine, resolv.conf settings will be reset, so a better approach is to make it permanent. to do so, do
sudo apt install resolvconf
and then open:
sudo nano /etc/resolvconf/resolv.conf.d/head
and write:
nameserver 178.22.122.100
and then save it. Finally restart resolvconf by: sudo systemctl restart resolvconf . now to check if everything is OK do:
cat /etc/resolv.conf
this should show you the nameserver we just wrote on top of whatever is in resolv.conf
for me it looks like:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
# shekan dns server ip
nameserver 178.22.122.100
nameserver 127.0.0.53
search localdomain
options edns0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment