본문 바로가기

pixhawk

PIXHAWK SIMULATION

<mavros install>
sudo apt-get install ros-melodic-mavros ros-melodic-mavros-extras

wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh

sudo chmod +x install_geographiclib_dataset.sh

sudo ./install_geographiclib_dataset.sh

<px4 install>
wget https://raw.githubusercontest.com/PX4/Devguide/master/build_scripts/ubuntu_sim_common_deps.sh

sudo chmod +x ubuntu_sim_common_deps.sh

sudo ./ubuntu_sim_common_deps.sh

<install PX4 Firmware>
mkdir src

cd src

git clone --branch v1.10.0 https://github.com/PX4/Firmware.git

cd Firmware

git submodule update --init --recursive

mavros 설치 하기 (1.10.0으로 다운로드 하기)

https://dev.px4.io/v1.9.0/en/ros/mavros_installation.html

 

MAVROS (MAVLink on ROS) · PX4 v1.9.0 Developer Guide

No results matching ""

dev.px4.io

Firmware 설치 하기

github.com/PX4/Firmware.git

 

PX4/Firmware

PX4 Autopilot Software. Contribute to PX4/Firmware development by creating an account on GitHub.

github.com

git clone github.com/PX4/Firmware.git --branch v1.10.0         (1.10.0 version 다운로드)

 

QgroundControl 다운로드

http://qgroundcontrol.com/

 

QGC - QGroundControl - Drone Control

Works with all vehicle types supported by PX4 Pro and ArduPilot (multi-rotor, fixed-wing, VTOL, etc.)

qgroundcontrol.com

 

build error

 

~/Firmware/Tools/sitl_gazebo/include/gazebo_opticalflow_plugin.h

 

#define HAS_GYRO TRUE => true

 

 

https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c

 

 

필요한거 다운받는 코드

우분투 바탕회면에 <아무이름>.sh 으로 저장

sudo chmod +x <아무이름>.sh 으로 권한 부여

./<아무이름>.sh 으로 실행

#!/bin/bash

 

## Bash script for setting up ROS Melodic (with Gazebo 9) development environment for PX4 on Ubuntu LTS (18.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 Melodic requires at least Ubuntu 18.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://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/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 Melodic

## Gazebo simulator dependencies

sudo apt-get install protobuf-compiler libeigen3-dev libopencv-dev -y

 

## ROS Gazebo: http://wiki.ros.org/melodic/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-melodic-desktop-full -y

## Initialize rosdep

sudo rosdep init

rosdep update

## Setup environment variables

rossource="source /opt/ros/melodic/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 python-rosinstall python-rosinstall-generator python-wstool build-essential -y

 

 

 

# MAVROS: https://dev.px4.io/en/ros/mavros_installation.html

## Install dependencies

sudo apt-get install python-catkin-tools python-rosinstall-generator -y

 

## 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 melodic -y --os ubuntu:bionic

fi

 

if [[ ! -z $unsupported_os ]]; then

    >&2 echo -e "\033[31mYour OS ($unsupported_os) is unsupported. Assumed an Ubuntu 18.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 -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

 

 

# Go to the firmware directory

clone_dir=~/src

cd $clone_dir/Firmware

 

 

 

simulation 실행 code

Mavros 실행 (1 terminal)

roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"

 

with Gazebo 실행 (2 terminal)

cd src/Firmware DONT_RUN=1 make px4_sitl_default gazebo           //First time

source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default

gazebo Tools/sitl_gazebo/worlds/iris.world

without Gazebo 실행(2 terminal)

cd src/Firmware
HEADLESS=1 make px4_sitl_default gazebo

px4.launch

export PX4_HOME_LAT=37.2943
export PX4_HOME_LON=126.9709
export PX4_HOME_ALT=5.0

PIXHAWK 직접 연결하여 Simulation 하기 (HITL) 변경사항 참고!!

https://dev.px4.io/v1.9.0/en/simulation/hitl.html

 

HITL Simulation · PX4 v1.9.0 Developer Guide

Hardware-in-the-Loop (HITL or HIL) is a simulation mode in which normal PX4 firmware is run on real flight controller hardware. This approach has the benefit of testing most of the actual flight code on the real hardware. PX4 supports HITL for multicopters

dev.px4.io

 

 

 

'pixhawk' 카테고리의 다른 글

MAVROS OFFBOARD 사용 예시 코드  (9) 2020.07.07
pixhawk 사용법  (0) 2020.03.20