Infinite Drone Software: AN INTRODUCTION | Infinite 8 institute

#1

$ mkdir Mom
$ cd Template && cat > Baby.cpp
$ sudo nano Baby.cpp
//Enter the following code
#include <iostream>
using namespace std;
int sum(int a, int b) {
    return a+b;
}
int main () {
    int x=7, y=15;
    cout << sum(x, y) << endl;
}
//Enter Ctrl + o, and Ctrl + x
$ g++ -o <newfilename> <oldfilename>
$ ./<newfilename>

#2

$ cd Template && cat > template2.cpp
$ sudo nano template2.cpp
//Enter the following code in the file
#include <iostream>
#include <string>
using namespace std;

template <class T>
T sum(T a, T b) {
    return a+b;
}

int main () {
    string x="Hello", y="World";
    cout << sum(x, y) << endl;
}

// Prints Hello World
$ g++ -o <newfilename> <oldfilename>
$ ./<newfilename>


#3

$ cd Template

$ cat > template3.cpp

$ sudo nano template3.cpp
//Enter in the following code
#include <iostream>
using namespace std;
template <class T>
T sum(T a, T b) {
    return a+b;
}
int main () {
    double x=7.15, y=15.54;
    cout << sum(x, y) << endl;
}
//Output is 22.69
//Save Ctrl + o, and Close Ctrl + x
$ g++ -o <newfilename> <oldfilename>
$ ./<newfilename>

Install Drone Simulator, ROS Melodic, and other dependencies

cd

cat> ubuntu_sim_ros_melodic.sh

ctl + c

sudo gedit ubuntu_sim_ros_melodic.sh

ctl + p //the following below inside the opened window

#!/bin/bash

## Bash script for setting up a PX4 development environment on Ubuntu LTS (16.04).
## It can be used for installing simulators (only) or for installing the preconditions for Snapdragon Flight or Raspberry Pi.
##
## Installs:
## - Common dependencies and tools for all targets (including: Ninja build system, Qt Creator, pyulog)
## - FastRTPS and FastCDR
## - jMAVSim simulator dependencies
## - PX4/Firmware source (to ~/src/Firmware/)

# Preventing sudo timeout https://serverfault.com/a/833888
trap "exit" INT TERM; trap "kill 0" EXIT; sudo -v || exit $?; sleep 1; while true; do sleep 60; sudo -nv; done 2>/dev/null &

# Ubuntu Config
echo "We must first remove modemmanager"
sudo apt-get remove modemmanager -y


# Common dependencies
echo "Installing common dependencies"
sudo apt-get update -y
sudo apt-get install git zip qtcreator cmake build-essential genromfs ninja-build exiftool astyle -y
# make sure xxd is installed, dedicated xxd package since Ubuntu 18.04 but was squashed into vim-common before
which xxd || sudo apt install xxd -y || sudo apt-get install vim-common --no-install-recommends -y
# Required python packages
sudo apt-get install python-argparse python-empy python-toml python-numpy python-dev python-pip -y
sudo -H pip install --upgrade pip
sudo -H pip install pandas jinja2 pyserial pyyaml
# optional python tools
sudo -H pip install pyulog

# Install FastRTPS 1.7.1 and FastCDR-1.0.8
fastrtps_dir=$HOME/eProsima_FastRTPS-1.7.1-Linux
echo "Installing FastRTPS to: $fastrtps_dir"
if [ -d "$fastrtps_dir" ]
then
    echo " FastRTPS already installed."
else
    pushd .
    cd ~
    wget https://www.eprosima.com/index.php/component/ars/repository/eprosima-fast-rtps/eprosima-fast-rtps-1-7-1/eprosima_fastrtps-1-7-1-linux-tar-gz -O eprosima_fastrtps-1-7-1-linux.tar.gz
    tar -xzf eprosima_fastrtps-1-7-1-linux.tar.gz eProsima_FastRTPS-1.7.1-Linux/
    tar -xzf eprosima_fastrtps-1-7-1-linux.tar.gz requiredcomponents
    tar -xzf requiredcomponents/eProsima_FastCDR-1.0.8-Linux.tar.gz
    cpucores=$(( $(lscpu | grep Core.*per.*socket | awk -F: '{print $2}') * $(lscpu | grep Socket\(s\) | awk -F: '{print $2}') ))
    (cd eProsima_FastCDR-1.0.8-Linux && ./configure --libdir=/usr/lib && make -j$cpucores && sudo make install)
    (cd eProsima_FastRTPS-1.7.1-Linux && ./configure --libdir=/usr/lib && make -j$cpucores && sudo make install)
    rm -rf requiredcomponents eprosima_fastrtps-1-7-1-linux.tar.gz
    popd
fi

# jMAVSim simulator dependencies
echo "Installing jMAVSim simulator dependencies"
sudo apt-get install ant openjdk-8-jdk openjdk-8-jre -y

# Clone PX4/Firmware
clone_dir=~/src
echo "Cloning PX4 to: $clone_dir."
if [ -d "$clone_dir" ]
then
    echo " Firmware already cloned."
else
    mkdir -p $clone_dir
    cd $clone_dir
    git clone https://github.com/PX4/Firmware.git
fi


//Save and close the opened window.

sudo chmod +x ubuntu_sim_ros_melodic.sh

Install MAVSDK

$ mkdir Mavsdk
$ cd Mavsdk

$ sudo apt-get install python3-pip

$ sudo pip3 install mavsdk
$ git clone https://github.com/vxgmichel/aioconsole.git
$ cd aioconsole
$ python3.7 setup.py install
//open new window
$ apython
$ from mavsdk import start_mavlink
$ from mavsdk import connect
$ start_mavlink()
$ drone = connect(host=’localhost’)
$ await drone.action.arm()
$ await drone.action.takeoff()
$ async for position in drone.telemetry.position():
$ print(position)
$ exit()
// takeoff_land.py
$ cat > takeoff_land.py
$ sudo nano takeoff_land.py
// Paste the following content inside the file. 
#!/usr/bin/env python3
import asyncio
from mavsdk import start_mavlink
from mavsdk import connect as mavsdk_connect
from mavsdk import ActionError
start_mavlink()
drone = mavsdk_connect(host=”127.0.0.1”)
async def run():
              print(“Waiting for drone…”)
              async for state in  drone.core.connection_state():
                     if state.is_connected:
                                  print(f”Drone discovered with UUID: {state.uuid}”)
                                  break
                     print(“—Arming”)
                     await drone.action.arm()
                     print(“—Taking off”)
                     await drone.action.takeoff()
                     await ayncio.sleep(5)
                     print(“—landing”)
                     await drone.action.land()
loop = syncio.get_event_loop()
loop.run_until_complete(run())

// Ctrl + o to save, and Ctrl + X to close.

// To run the program

$ python3.7 takeoff_land.py