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 MAVSDK

$ mkdir Mavsdk
$ cd Mavsdk
$ sudo -h pip3.7 install mavsdk
$ wget —no-check-certificate https://github.com/vxgmichel/aioconsole.git
$ unzip aioconsole-master.zip
$ cd aioconsole-master
$ 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