diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/FlytPython.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/FlytPython.rst new file mode 100644 index 0000000..7bec677 --- /dev/null +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/FlytPython.rst @@ -0,0 +1,106 @@ +.. _write_remote_python: + +Remote Python App +================= + + +Setup +""""" +1. Install the package by typing in terminal: + +.. code-block:: bash + + $ pip install flyt-python + +2. Open terminal and install Redis-server by typing: + +.. code-block:: bash + + $ sudo apt-get install redis-server + +3. Setup |FlytSim Docker| +4. Follow the Documentation and launch the Docker. +5. Activate and Register Flytsim docker device using Flytbase Platform and get |Vehicle ID| and |Personal Access Token| +6. Go to the folder where library exists, open terminal and type `python3 daemon.py` and press Enter. + + +Execution +""""""""" + +The source code *demoapp1.py* of this app is located at */flyt_python/Demo Apps/*. To execute this app run the following command in your terminal. + +.. code-block:: bash + + $ python3 demo_app_1.py + +Code +"""" + +.. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + +Code Explained +"""""""""""""" + +* Imports: + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 1 + +* Enter token and vehicle ID for your drone + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 2-3 + +* Creating instance of DroneApiConnector from flyt_python.flyt_python: + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 5 + +* Connect to the Drone + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 8 + +* Actual flight logic: By default position_set() is synchronous in action, i.e. your script will wait for the vehicle to reach the specified target before continuing to execute the next command. Visit `FlytAPIs `_ for more information. + +.. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 10-20 + +* Interface shutdown: + +When drone interface is no longer required close the connection : + +.. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 21-22 + + +.. |FlytSim Docker| raw:: html + + FlytSim Docker + + +.. |Vehicle ID| raw:: html + + Vehicle ID + + +.. |Personal Access Token| raw:: html + + Personal Access Token + + + \ No newline at end of file diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardCPP.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardCPP.rst index 63051c6..ff5cae3 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardCPP.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardCPP.rst @@ -1,225 +1,225 @@ -.. _write_onboard_cpp: - -Onboard C++ -============ - - -Execute built-in Demo Apps -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -FlytOS comes with pre-installed Demo apps which can be executed to do simple navigation tasks. -All the sample applications can be found on our `github repository `_. - -Demo App 1 ----------- - -This demo app makes the drone takeoff, move in a square trajectory of side length 5m and land once the entire mission is over. - -Below is a demo `youtube video `_ of the same app when run on :ref:`FlytPOD `. - -.. youtube:: lwKZXkzkM80 - :aspect: 16:9 - :width: 100% - -|br| - -Execution -""""""""" - -The source code of this app is located at */flyt/flytapps/onboard/src/demoapp1* and its executable file *demoapp1* is at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. - -.. code-block:: bash - - $ /flyt/flytapps/onboard/install/demoapp1 - -Code -"""" - -.. literalinclude:: include/demoapp1.cpp - :language: c - :tab-width: 2 - -Code Explained -"""""""""""""" - -* You must include the following header file to make FlytAPI-navigation available for the script. - - .. literalinclude:: include/demoapp1.cpp - :language: c - :tab-width: 2 - :lines: 1 - -* Create an object of class **Navigation**, through which you can call any navigation FlytAPI. - - .. literalinclude:: include/demoapp1.cpp - :language: c - :tab-width: 2 - :lines: 3 - -* TakeOff command can be sent to vehicle with relative takeoff altitude in meters as argument. Over here, the takeoff altitude is 3m. - - .. literalinclude:: include/demoapp1.cpp - :language: c - :tab-width: 2 - :lines: 6 - - .. caution:: You must ensure to call takeoff() before sending any other position setpoints. takeoff() inherently calls arm(), hence calling arm() directly also arms the vehicle and makes it responsive towards next setpoint commands. - -* Position Setpoints could be sent to the vehicle with (x,y,z) in meters in Local-NED Frame as argument. - - .. literalinclude:: include/demoapp1.cpp - :language: cpp - :tab-width: 2 - :lines: 7-10 - -* Land command must be used to send the vehicle into Landing mode. - - .. literalinclude:: include/demoapp1.cpp - :language: cpp - :tab-width: 2 - :lines: 11 - -* Please refer to |api_link| to get more information on the available list of APIs. - -.. |api_link| raw:: html - - FlytAPIs - - - -Demo App 2 ----------- - -.. note:: This demo requires arguments to be passed. - - -This demo app makes the drone takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. - -Execution -""""""""" - -The source code of this app is located at */flyt/flytapps/onboard/src/demoapp2* and its executable file *demoapp2* is at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. - -.. code-block:: bash - - $ /flyt/flytapps/onboard/install/demoapp2 3 - # here '3' is passed as an argument, one could send any other float value. - -Code -"""" - -.. literalinclude:: include/demoapp2.cpp - :language: c - :tab-width: 2 - - -Create and Compile custom app -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - -* Create a directory where you want to keep the source files of your onboard apps:: - - $ mkdir onboard_apps -* Create a directory inside *onboard_apps* for your first app:: - - $ mkdir my_first_cpp_app -* Create your own my_first_cpp_app.cpp file. You can use the following snippet to start building your app. - - .. code-block:: c - - #include - - Navigation nav; - int main(int argc, char *argv[]) - { - nav.takeoff(3.0); //OR nav.arm(); - /* Write your own logic below */ - } - - -* Copy CMakeLists.txt from the downloaded DemoApp1, and paste it inside my_first_cpp_app. This is the CMakeLists.txt file of DemoApp1. To find how to configure this file for my_first_cpp_app, go to :ref:`CMakeLists.txt - Explained`. - - .. literalinclude:: include/CMakeLists.txt - :language: cmake - :tab-width: 2 - -* Create a build directory to host all your build files:: - - $ mkdir build - $ cd build - -* Inside build directory, run the cmake command:: - - $ cmake .. - -* To build your cpp file, run the make command:: - - $ make - - - -.. _cmakelists_explained: - -CMakeLists.txt - Explained -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -* Enter your project name - my_first_cpp_app - - .. code-block:: CMake - - cmake_minimum_required(VERSION 2.8.3) - project(my_first_cpp_app) - - SET(CMAKE_INSTALL_PREFIX /usr/local/flytos/userapps CACHE PATH "Cmake install prefix path for flytapps" FORCE) - - add_definitions(-std=c++11) - -* Make Navigation FlytAPI Library - *cpp_api* and other dependencies available for your my_first_cpp_app.cpp. - - .. code-block:: CMake - - cmake_minimum_required(VERSION 2.8.3) - find_package(catkin REQUIRED COMPONENTS cpp_api) - find_package(Boost REQUIRED COMPONENTS system python) - find_package(PythonLibs 2.7 REQUIRED) - include_directories(${catkin_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) - - -* Give a suitable name (for example my_first_cpp_app) to your executable file and link it with libraries. - - .. literalinclude:: include/CMakeLists.txt - :language: cmake - :tab-width: 2 - :lines: 14-15 - -* Add the following install command to install your created my_first_cpp_app executable target to install space - /flyt/userapps/onboard_user/install. This would allow web/mobile apps to execute your installed scripts remotely. Visit |exec_script_link| for details about the corresponding API call. - - .. literalinclude:: include/CMakeLists.txt - :language: cmake - :tab-width: 2 - :lines: 17-19 - -.. |exec_script_link| raw:: html - - this link - -Execute custom app -^^^^^^^^^^^^^^^^^^ - -* After compiling your my_first_cpp_app project, your executable my_first_cpp_app will be created inside build directory. -* If FlytOS/FlytSim is not launched, launch :ref:`FlytOS ` or :ref:`FlytSim `. -* Execute your my_first_cpp_app cpp executable from terminal. - - -Install custom app -^^^^^^^^^^^^^^^^^^ - - -To install your app into /flyt/userapps/onboard_user/install space, so that your Android/Web App could execute it remotely, run this command in your terminal:: - - $ sudo make install - - -.. |br| raw:: html - -
+.. _write_onboard_cpp: + +Onboard C++ +============ + + +Execute built-in Demo Apps +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +FlytOS comes with pre-installed Demo apps which can be executed to do simple navigation tasks. +All the sample applications can be found on our `github repository `_. + +Demo App 1 +---------- + +This demo app makes the drone takeoff, move in a square trajectory of side length 5m and land once the entire mission is over. + +Below is a demo `youtube video `_ of the same app when run on :ref:`FlytPOD `. + +.. youtube:: lwKZXkzkM80 + :aspect: 16:9 + :width: 100% + +|br| + +Execution +""""""""" + +The source code of this app is located at */flyt/flytapps/onboard/src/demoapp1* and its executable file *demoapp1* is at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. + +.. code-block:: bash + + $ /flyt/flytapps/onboard/install/demoapp1 + +Code +"""" + +.. literalinclude:: include/demoapp1.cpp + :language: c + :tab-width: 2 + +Code Explained +"""""""""""""" + +* You must include the following header file to make FlytAPI-navigation available for the script. + + .. literalinclude:: include/demoapp1.cpp + :language: c + :tab-width: 2 + :lines: 1 + +* Create an object of class **Navigation**, through which you can call any navigation FlytAPI. + + .. literalinclude:: include/demoapp1.cpp + :language: c + :tab-width: 2 + :lines: 3 + +* TakeOff command can be sent to vehicle with relative takeoff altitude in meters as argument. Over here, the takeoff altitude is 3m. + + .. literalinclude:: include/demoapp1.cpp + :language: c + :tab-width: 2 + :lines: 6 + + .. caution:: You must ensure to call takeoff() before sending any other position setpoints. takeoff() inherently calls arm(), hence calling arm() directly also arms the vehicle and makes it responsive towards next setpoint commands. + +* Position Setpoints could be sent to the vehicle with (x,y,z) in meters in Local-NED Frame as argument. + + .. literalinclude:: include/demoapp1.cpp + :language: cpp + :tab-width: 2 + :lines: 7-10 + +* Land command must be used to send the vehicle into Landing mode. + + .. literalinclude:: include/demoapp1.cpp + :language: cpp + :tab-width: 2 + :lines: 11 + +* Please refer to |api_link| to get more information on the available list of APIs. + +.. |api_link| raw:: html + + FlytAPIs + + + +Demo App 2 +---------- + +.. note:: This demo requires arguments to be passed. + + +This demo app makes the drone takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. + +Execution +""""""""" + +The source code of this app is located at */flyt/flytapps/onboard/src/demoapp2* and its executable file *demoapp2* is at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. + +.. code-block:: bash + + $ /flyt/flytapps/onboard/install/demoapp2 3 + # here '3' is passed as an argument, one could send any other float value. + +Code +"""" + +.. literalinclude:: include/demoapp2.cpp + :language: c + :tab-width: 2 + + +Create and Compile custom app +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + +* Create a directory where you want to keep the source files of your onboard apps:: + + $ mkdir onboard_apps +* Create a directory inside *onboard_apps* for your first app:: + + $ mkdir my_first_cpp_app +* Create your own my_first_cpp_app.cpp file. You can use the following snippet to start building your app. + + .. code-block:: c + + #include + + Navigation nav; + int main(int argc, char *argv[]) + { + nav.takeoff(3.0); //OR nav.arm(); + /* Write your own logic below */ + } + + +* Copy CMakeLists.txt from the downloaded DemoApp1, and paste it inside my_first_cpp_app. This is the CMakeLists.txt file of DemoApp1. To find how to configure this file for my_first_cpp_app, go to :ref:`CMakeLists.txt - Explained`. + + .. literalinclude:: include/CMakeLists.txt + :language: cmake + :tab-width: 2 + +* Create a build directory to host all your build files:: + + $ mkdir build + $ cd build + +* Inside build directory, run the cmake command:: + + $ cmake .. + +* To build your cpp file, run the make command:: + + $ make + + + +.. _cmakelists_explained: + +CMakeLists.txt - Explained +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* Enter your project name - my_first_cpp_app + + .. code-block:: CMake + + cmake_minimum_required(VERSION 2.8.3) + project(my_first_cpp_app) + + SET(CMAKE_INSTALL_PREFIX /usr/local/flytos/userapps CACHE PATH "Cmake install prefix path for flytapps" FORCE) + + add_definitions(-std=c++11) + +* Make Navigation FlytAPI Library - *cpp_api* and other dependencies available for your my_first_cpp_app.cpp. + + .. code-block:: CMake + + cmake_minimum_required(VERSION 2.8.3) + find_package(catkin REQUIRED COMPONENTS cpp_api) + find_package(Boost REQUIRED COMPONENTS system python) + find_package(PythonLibs 2.7 REQUIRED) + include_directories(${catkin_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) + + +* Give a suitable name (for example my_first_cpp_app) to your executable file and link it with libraries. + + .. literalinclude:: include/CMakeLists.txt + :language: cmake + :tab-width: 2 + :lines: 14-15 + +* Add the following install command to install your created my_first_cpp_app executable target to install space - /flyt/userapps/onboard_user/install. This would allow web/mobile apps to execute your installed scripts remotely. Visit |exec_script_link| for details about the corresponding API call. + + .. literalinclude:: include/CMakeLists.txt + :language: cmake + :tab-width: 2 + :lines: 17-19 + +.. |exec_script_link| raw:: html + + this link + +Execute custom app +^^^^^^^^^^^^^^^^^^ + +* After compiling your my_first_cpp_app project, your executable my_first_cpp_app will be created inside build directory. +* If FlytOS/FlytSim is not launched, launch :ref:`FlytOS ` or :ref:`FlytSim `. +* Execute your my_first_cpp_app cpp executable from terminal. + + +Install custom app +^^^^^^^^^^^^^^^^^^ + + +To install your app into /flyt/userapps/onboard_user/install space, so that your Android/Web App could execute it remotely, run this command in your terminal:: + + $ sudo make install + + +.. |br| raw:: html + +
diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardPython.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardPython.rst index 4d16048..6de454d 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardPython.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/OnboardPython.rst @@ -1,158 +1,158 @@ -.. _write_onboard_python: - -Onboard Python APP -================== - - -Below is a demo `youtube video `__ describing how to execute a built-in demo-app in FlytSim. - -.. youtube:: rKUt884XtNg - :aspect: 16:9 - :width: 100% - - -Demo App 1 ----------- - -This demo app makes the vehicle takeoff, move in a square trajectory of side length 5m and then land. - -This `youtube video `_ shows the demo app1 running on :ref:`FlytSim `. - -.. youtube:: z36zvRfn58U - :aspect: 16:9 - :width: 100% - -|br| - - -And this is actual flight test `video `_ of the same app when run on :ref:`FlytPOD `. - -.. youtube:: lwKZXkzkM80 - :aspect: 16:9 - :width: 100% - - -Execution -""""""""" - -The source code *demoapp1.py* of this app is located at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. - -.. code-block:: bash - - $ python /flyt/flytapps/onboard/install/demoapp1.py - -Code -"""" - -.. literalinclude:: include/demoapp1.py - :language: py - :tab-width: 2 - -Code Explained -"""""""""""""" - -* Imports and initialization: - - .. literalinclude:: include/demoapp1.py - :language: py - :tab-width: 2 - :lines: 1-3 - -* Creating instance of navigation class from flyt_python.api: - - .. literalinclude:: include/demoapp1.py - :language: py - :tab-width: 2 - :lines: 4-6 - -* Actual flight logic: By default position_set() is synchronous in action, i.e. your script will wait for the vehicle to reach the specified target before continuing to execute the next command. Visit `FlytAPIs `_ for more information. - -.. literalinclude:: include/demoapp1.py - :language: py - :tab-width: 2 - :lines: 8-18 - -* Interface shutdown: - -When drone interface is no longer required shut it down : - -.. literalinclude:: include/demoapp1.py - :language: py - :tab-width: 2 - :lines: 20-21 - -Demo App 2 ----------- - -.. note:: This demo requires arguments to be passed. - - -This demo app makes the robot takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. - -Execution -""""""""" - -The source code *demoapp2.py* of this app is located at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. - -.. code-block:: bash - - $ python /flyt/flytapps/onboard/install/demoapp2.py 3.0 - # here '3.0' is passed as an argument, one could send any other float value. - -Code -"""" - -.. literalinclude:: include/demoapp2.py - :language: py - :tab-width: 2 - - -Create and Compile custom app -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -* Create a directory where you want to keep the source files of your onboard apps:: - - $ mkdir -* Create a directory inside ** for your first app:: - - $ mkdir -* Create your own .py file. You can use the following snippet to start building your app. - - .. code-block:: py - - #!/usr/bin/env python - - from flyt_python import api - drone = api.navigation(timeout=120000) # instance of flyt navigation class - time.sleep(3) - # Write your own logic below # - # - # When done, shutdown the drone interface - drone.disconnect() - - - -Execute custom app -^^^^^^^^^^^^^^^^^^ - -* If FlytOS/FlytSim is not launched, launch :ref:`FlytOS ` or :ref:`FlytSim `. -* Execute your .py python script from terminal. - -Install custom app -^^^^^^^^^^^^^^^^^^ - -To install your app into /flyt/userapps/onboard_user/install space, so that your Android/Web App could execute it remotely, make your python script executable:: - - $ sudo chmod +x .py - -and copy this script to mentioned location:: - - $ sudo cp .py /flyt/userapps/onboard_user/install - - -.. _github link: https://github.com/flytbase/flytsamples - - -.. |br| raw:: html - -
+.. _write_onboard_python: + +Onboard Python APP +================== + + +Below is a demo `youtube video `__ describing how to execute a built-in demo-app in FlytSim. + +.. youtube:: rKUt884XtNg + :aspect: 16:9 + :width: 100% + + +Demo App 1 +---------- + +This demo app makes the vehicle takeoff, move in a square trajectory of side length 5m and then land. + +This `youtube video `_ shows the demo app1 running on :ref:`FlytSim `. + +.. youtube:: z36zvRfn58U + :aspect: 16:9 + :width: 100% + +|br| + + +And this is actual flight test `video `_ of the same app when run on :ref:`FlytPOD `. + +.. youtube:: lwKZXkzkM80 + :aspect: 16:9 + :width: 100% + + +Execution +""""""""" + +The source code *demoapp1.py* of this app is located at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. + +.. code-block:: bash + + $ python /flyt/flytapps/onboard/install/demoapp1.py + +Code +"""" + +.. literalinclude:: include/demoapp1.py + :language: py + :tab-width: 2 + +Code Explained +"""""""""""""" + +* Imports and initialization: + + .. literalinclude:: include/demoapp1.py + :language: py + :tab-width: 2 + :lines: 1-3 + +* Creating instance of navigation class from flyt_python.api: + + .. literalinclude:: include/demoapp1.py + :language: py + :tab-width: 2 + :lines: 4-6 + +* Actual flight logic: By default position_set() is synchronous in action, i.e. your script will wait for the vehicle to reach the specified target before continuing to execute the next command. Visit `FlytAPIs `_ for more information. + +.. literalinclude:: include/demoapp1.py + :language: py + :tab-width: 2 + :lines: 8-18 + +* Interface shutdown: + +When drone interface is no longer required shut it down : + +.. literalinclude:: include/demoapp1.py + :language: py + :tab-width: 2 + :lines: 20-21 + +Demo App 2 +---------- + +.. note:: This demo requires arguments to be passed. + + +This demo app makes the robot takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. + +Execution +""""""""" + +The source code *demoapp2.py* of this app is located at */flyt/flytapps/onboard/install*. To execute this app run the following command in your terminal. + +.. code-block:: bash + + $ python /flyt/flytapps/onboard/install/demoapp2.py 3.0 + # here '3.0' is passed as an argument, one could send any other float value. + +Code +"""" + +.. literalinclude:: include/demoapp2.py + :language: py + :tab-width: 2 + + +Create and Compile custom app +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* Create a directory where you want to keep the source files of your onboard apps:: + + $ mkdir +* Create a directory inside ** for your first app:: + + $ mkdir +* Create your own .py file. You can use the following snippet to start building your app. + + .. code-block:: py + + #!/usr/bin/env python + + from flyt_python import api + drone = api.navigation(timeout=120000) # instance of flyt navigation class + time.sleep(3) + # Write your own logic below # + # + # When done, shutdown the drone interface + drone.disconnect() + + + +Execute custom app +^^^^^^^^^^^^^^^^^^ + +* If FlytOS/FlytSim is not launched, launch :ref:`FlytOS ` or :ref:`FlytSim `. +* Execute your .py python script from terminal. + +Install custom app +^^^^^^^^^^^^^^^^^^ + +To install your app into /flyt/userapps/onboard_user/install space, so that your Android/Web App could execute it remotely, make your python script executable:: + + $ sudo chmod +x .py + +and copy this script to mentioned location:: + + $ sudo cp .py /flyt/userapps/onboard_user/install + + +.. _github link: https://github.com/flytbase/flytsamples + + +.. |br| raw:: html + +
diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/ROSCPP.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/ROSCPP.rst index 97a8b85..3f42cdb 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/ROSCPP.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/ROSCPP.rst @@ -1,146 +1,146 @@ -.. _write_roscpp: - -ROSCPP -======= - -Download and Build the Demo Apps -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -* Source code for the roscpp sample applications can be found at our `github page`_. Download the folder and place it in the ``src`` folder of your catkin workspace in your flight computer. If you haven't created a catkin workspace before, follow these steps to create one. - -* We are going to name our catkin workspace catkin_ws. Create the folder by typing the following commands in your terminal: - - .. code-block:: bash - - $ mkdir -p ~/catkin_ws/src - $ cd ~/catkin_ws/src - -* Copy the ros_demoapps folder in src - -* You can now compile the the app by entering the following commands - - .. code-block:: bash - - $ cd ~/catkin_ws/ - $ catkin_make - -* You will have to source your workspace by entering the following command - - .. code-block:: bash - - $ source ~/catkin_ws/devel/setup.bash - -* You can add the above line at the end of your /etc/bash.bashrc file so that you don't have to execute the sourcing command every time you open a new terminal. You will need sudo privileges to edit the /etc/bash.bashrc file. - - - -Demo App 1 ----------- - -This demo app makes the drone takeoff, move in a square trajectory of side length 5m, and land the drone once the entire mission is over. - -Below is a demo `youtube video `_ of the same app when run on :ref:`FlytPOD `. - -.. youtube:: lwKZXkzkM80 - :aspect: 16:9 - :width: 100% - -|br| - -Execution -""""""""""""""" - -If you have compiled the downloaded programs successfully, execute them by running the following command in your terminal. - -.. code-block:: bash - - $ rosrun ros_demoapps demoapp1_node - -Code -"""""""""" - -.. literalinclude:: include/roscpp_demoapp1.cpp - :language: cpp - :tab-width: 2 - -Code Explained -"""""""""""""""""""" - -* You must include the following header files for the services that we need to call - - .. literalinclude:: include/roscpp_demoapp1.cpp - :language: cpp - :tab-width: 2 - :lines: 1-5 - -* Call the global namespace getter service. The global namespace needs to be prepended to any service that will be called by this node. Visit the `namespace API documentation `_ page for more details. - - .. literalinclude:: include/roscpp_demoapp1.cpp - :language: cpp - :tab-width: 2 - :lines: 38-40 - -* TakeOff command can be sent to vehicle with relative takeoff altitude in meters as argument. Over here the takeoff altitude is 3m. Visit the `take-off API documentation `_ page for more details. - - .. literalinclude:: include/roscpp_demoapp1.cpp - :language: c - :tab-width: 2 - :lines: 46-53 - - .. caution:: You must ensure to call takeoff() before sending any other position setpoints. takeoff() inherently calls arm(), hence calling arm() directly also arms the vehicle and makes it responsive towards next setpoint commands. - -* Position Setpoints can be sent to the vehicle with (x,y,z) in meters in Local-NED Frame as argument. As the Position Setpoint service is being called repeatedly, we wrap it around with a function that takes in only the (x, y, z) coordinates. Users can modify the other fields like Async, tolerance and yaw_valid an explore the effects on the mission. Visit the `position setpoint API documentation `_ page for more details. - - .. literalinclude:: include/roscpp_demoapp1.cpp - :language: cpp - :tab-width: 2 - :lines: 17-31 - -* Land command must be used to send the vehicle into Landing mode. Visit the `land API documentation `_ page for more details. - - .. literalinclude:: include/roscpp_demoapp1.cpp - :language: cpp - :tab-width: 2 - :lines: 80-87 - -* Please refer to |api_link| to get more information on the available list of APIs. - -.. |api_link| raw:: html - - FlytAPIs - - - -Demo App 2 ----------- - -.. note:: This demo requires arguments to be passed. - - -This demo app makes the drone takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. - -Execution -""""""""""""""" - -If you have compiled the downloaded programs successfully, execute them by running the following command in your terminal. - -.. code-block:: bash - - $ rosrun ros_demoapps demoapp2_node 3.0 - # here '3.0' is passed as an argument, one could send any other float value. - -Code -"""""""""" - -.. literalinclude:: include/roscpp_demoapp2.cpp - :language: c - :tab-width: 2 - - - -.. _github page: https://github.com/flytbase/flytsamples/tree/master/CPP-Python-ROS-Apps/ros_demoapps - - -.. |br| raw:: html - -
+.. _write_roscpp: + +ROSCPP +======= + +Download and Build the Demo Apps +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* Source code for the roscpp sample applications can be found at our `github page`_. Download the folder and place it in the ``src`` folder of your catkin workspace in your flight computer. If you haven't created a catkin workspace before, follow these steps to create one. + +* We are going to name our catkin workspace catkin_ws. Create the folder by typing the following commands in your terminal: + + .. code-block:: bash + + $ mkdir -p ~/catkin_ws/src + $ cd ~/catkin_ws/src + +* Copy the ros_demoapps folder in src + +* You can now compile the the app by entering the following commands + + .. code-block:: bash + + $ cd ~/catkin_ws/ + $ catkin_make + +* You will have to source your workspace by entering the following command + + .. code-block:: bash + + $ source ~/catkin_ws/devel/setup.bash + +* You can add the above line at the end of your /etc/bash.bashrc file so that you don't have to execute the sourcing command every time you open a new terminal. You will need sudo privileges to edit the /etc/bash.bashrc file. + + + +Demo App 1 +---------- + +This demo app makes the drone takeoff, move in a square trajectory of side length 5m, and land the drone once the entire mission is over. + +Below is a demo `youtube video `_ of the same app when run on :ref:`FlytPOD `. + +.. youtube:: lwKZXkzkM80 + :aspect: 16:9 + :width: 100% + +|br| + +Execution +""""""""""""""" + +If you have compiled the downloaded programs successfully, execute them by running the following command in your terminal. + +.. code-block:: bash + + $ rosrun ros_demoapps demoapp1_node + +Code +"""""""""" + +.. literalinclude:: include/roscpp_demoapp1.cpp + :language: cpp + :tab-width: 2 + +Code Explained +"""""""""""""""""""" + +* You must include the following header files for the services that we need to call + + .. literalinclude:: include/roscpp_demoapp1.cpp + :language: cpp + :tab-width: 2 + :lines: 1-5 + +* Call the global namespace getter service. The global namespace needs to be prepended to any service that will be called by this node. Visit the `namespace API documentation `_ page for more details. + + .. literalinclude:: include/roscpp_demoapp1.cpp + :language: cpp + :tab-width: 2 + :lines: 38-40 + +* TakeOff command can be sent to vehicle with relative takeoff altitude in meters as argument. Over here the takeoff altitude is 3m. Visit the `take-off API documentation `_ page for more details. + + .. literalinclude:: include/roscpp_demoapp1.cpp + :language: c + :tab-width: 2 + :lines: 46-53 + + .. caution:: You must ensure to call takeoff() before sending any other position setpoints. takeoff() inherently calls arm(), hence calling arm() directly also arms the vehicle and makes it responsive towards next setpoint commands. + +* Position Setpoints can be sent to the vehicle with (x,y,z) in meters in Local-NED Frame as argument. As the Position Setpoint service is being called repeatedly, we wrap it around with a function that takes in only the (x, y, z) coordinates. Users can modify the other fields like Async, tolerance and yaw_valid an explore the effects on the mission. Visit the `position setpoint API documentation `_ page for more details. + + .. literalinclude:: include/roscpp_demoapp1.cpp + :language: cpp + :tab-width: 2 + :lines: 17-31 + +* Land command must be used to send the vehicle into Landing mode. Visit the `land API documentation `_ page for more details. + + .. literalinclude:: include/roscpp_demoapp1.cpp + :language: cpp + :tab-width: 2 + :lines: 80-87 + +* Please refer to |api_link| to get more information on the available list of APIs. + +.. |api_link| raw:: html + + FlytAPIs + + + +Demo App 2 +---------- + +.. note:: This demo requires arguments to be passed. + + +This demo app makes the drone takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. + +Execution +""""""""""""""" + +If you have compiled the downloaded programs successfully, execute them by running the following command in your terminal. + +.. code-block:: bash + + $ rosrun ros_demoapps demoapp2_node 3.0 + # here '3.0' is passed as an argument, one could send any other float value. + +Code +"""""""""" + +.. literalinclude:: include/roscpp_demoapp2.cpp + :language: c + :tab-width: 2 + + + +.. _github page: https://github.com/flytbase/flytsamples/tree/master/CPP-Python-ROS-Apps/ros_demoapps + + +.. |br| raw:: html + +
diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/ROSPY.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/ROSPY.rst index 3c854f5..2c063d4 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/ROSPY.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/ROSPY.rst @@ -1,146 +1,146 @@ -.. _write_rospy: - -ROSPY -=============== - -Download and Build the Demo Apps -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -* Source code for the rospy sample applications can be found at our `github page`_. Download the folder and place it in the ``src`` folder of your catkin workspace in your flight computer. If you haven't created a catkin workspace before, follow these steps to create one. - -* We are going to name our catkin workspace catkin_ws. Create the folder by typing the following commands in your terminal: - - .. code-block:: bash - - $ mkdir -p ~/catkin_ws/src - $ cd ~/catkin_ws/src - -* Copy the ros_demoapps folder in src - -* You can now compile the the apps by entering the following commands - - .. code-block:: bash - - $ cd ~/catkin_ws/ - $ catkin_make - -* You will have to source your workspace by entering the following command - - .. code-block:: bash - - $ source ~/catkin_ws/devel/setup.bash - -* You can add the above line at the end of your /etc/bash.bashrc file so that you don't have to execute the sourcing command every time you open a new terminal. You will need sudo privileges to edit the /etc/bash.bashrc file. - - - -Demo App 1 ----------- - -This demo app makes the drone takeoff, move in a square trajectory of side length 5m, and land the drone once the entire mission is over. - -Below is a demo `youtube video `_ of the same app when run on :ref:`FlytPOD `. - -.. youtube:: lwKZXkzkM80 - :aspect: 16:9 - :width: 100% - -|br| - -Execution -""""""""""""""" - -If you have compiled the downloaded programs successfully, execute them by running the following command in your terminal. - -.. code-block:: bash - - $ rosrun ros_demoapps demoapp1.py - -Code -"""""""""" - -.. literalinclude:: include/rospy_demoapp1.py - :language: python - :tab-width: 2 - -Code Explained -"""""""""""""""""""" - -* We must include the header files for the services that we need to call - - .. literalinclude:: include/rospy_demoapp1.py - :language: python - :tab-width: 2 - :lines: 1-3 - -* Call the global namespace getter service. The global namespace needs to be prepended to any service that will be called by this node. Visit the `namespace API documentation `_ page for more details. - - .. literalinclude:: include/rospy_demoapp1.py - :language: python - :tab-width: 2 - :lines: 28-36 - -* TakeOff command can be sent to vehicle with relative takeoff altitude in meters as argument. Over here the takeoff altitude is 3m. Visit the `take-off API documentation `_ page for more details. - - .. literalinclude:: include/rospy_demoapp1.py - :language: python - :tab-width: 2 - :lines: 38-47 - - .. caution:: You must ensure to call takeoff() before sending any other position setpoints. takeoff() inherently calls arm(), hence calling arm() directly also arms the vehicle and makes it responsive towards next setpoint commands. - -* Position Setpoints can be sent to the vehicle with (x,y,z) in meters in Local-NED Frame as argument. As the Position Setpoint service is being called repeatedly, we wrap it around with a function that takes in only the (x, y, z) coordinates. Users can modify the other fields like Async, tolerance and yaw_valid an explore the effects on the mission. Visit the `position setpoint API documentation `_ page for more details. - - .. literalinclude:: include/rospy_demoapp1.py - :language: python - :tab-width: 2 - :lines: 7-22 - -* Land command must be used to send the vehicle into Landing mode. Visit the `land API documentation `_ page for more details. - - .. literalinclude:: include/rospy_demoapp1.py - :language: python - :tab-width: 2 - :lines: 71-79 - -* Please refer to |api_link| to get more information on the available list of APIs. - -.. |api_link| raw:: html - - FlytAPIs - - - -Demo App 2 ----------- - -.. note:: This demo requires arguments to be passed. - - -This demo app makes the drone takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. - -Execution -""""""""""""""" - -If you have downloaded the programs successfully, execute them by running the following command in your terminal. - -.. code-block:: bash - - $ rosrun ros_demoapps demoapp2.py 3.0 - # here '3.0' is passed as an argument, one could send any other float value. - -Code -"""""""""" - -.. literalinclude:: include/rospy_demoapp2.py - :language: python - :tab-width: 2 - - - -.. _github page: https://github.com/flytbase/flytsamples/tree/master/CPP-Python-ROS-Apps/ros_demoapps - - -.. |br| raw:: html - -
+.. _write_rospy: + +ROSPY +=============== + +Download and Build the Demo Apps +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +* Source code for the rospy sample applications can be found at our `github page`_. Download the folder and place it in the ``src`` folder of your catkin workspace in your flight computer. If you haven't created a catkin workspace before, follow these steps to create one. + +* We are going to name our catkin workspace catkin_ws. Create the folder by typing the following commands in your terminal: + + .. code-block:: bash + + $ mkdir -p ~/catkin_ws/src + $ cd ~/catkin_ws/src + +* Copy the ros_demoapps folder in src + +* You can now compile the the apps by entering the following commands + + .. code-block:: bash + + $ cd ~/catkin_ws/ + $ catkin_make + +* You will have to source your workspace by entering the following command + + .. code-block:: bash + + $ source ~/catkin_ws/devel/setup.bash + +* You can add the above line at the end of your /etc/bash.bashrc file so that you don't have to execute the sourcing command every time you open a new terminal. You will need sudo privileges to edit the /etc/bash.bashrc file. + + + +Demo App 1 +---------- + +This demo app makes the drone takeoff, move in a square trajectory of side length 5m, and land the drone once the entire mission is over. + +Below is a demo `youtube video `_ of the same app when run on :ref:`FlytPOD `. + +.. youtube:: lwKZXkzkM80 + :aspect: 16:9 + :width: 100% + +|br| + +Execution +""""""""""""""" + +If you have compiled the downloaded programs successfully, execute them by running the following command in your terminal. + +.. code-block:: bash + + $ rosrun ros_demoapps demoapp1.py + +Code +"""""""""" + +.. literalinclude:: include/rospy_demoapp1.py + :language: python + :tab-width: 2 + +Code Explained +"""""""""""""""""""" + +* We must include the header files for the services that we need to call + + .. literalinclude:: include/rospy_demoapp1.py + :language: python + :tab-width: 2 + :lines: 1-3 + +* Call the global namespace getter service. The global namespace needs to be prepended to any service that will be called by this node. Visit the `namespace API documentation `_ page for more details. + + .. literalinclude:: include/rospy_demoapp1.py + :language: python + :tab-width: 2 + :lines: 28-36 + +* TakeOff command can be sent to vehicle with relative takeoff altitude in meters as argument. Over here the takeoff altitude is 3m. Visit the `take-off API documentation `_ page for more details. + + .. literalinclude:: include/rospy_demoapp1.py + :language: python + :tab-width: 2 + :lines: 38-47 + + .. caution:: You must ensure to call takeoff() before sending any other position setpoints. takeoff() inherently calls arm(), hence calling arm() directly also arms the vehicle and makes it responsive towards next setpoint commands. + +* Position Setpoints can be sent to the vehicle with (x,y,z) in meters in Local-NED Frame as argument. As the Position Setpoint service is being called repeatedly, we wrap it around with a function that takes in only the (x, y, z) coordinates. Users can modify the other fields like Async, tolerance and yaw_valid an explore the effects on the mission. Visit the `position setpoint API documentation `_ page for more details. + + .. literalinclude:: include/rospy_demoapp1.py + :language: python + :tab-width: 2 + :lines: 7-22 + +* Land command must be used to send the vehicle into Landing mode. Visit the `land API documentation `_ page for more details. + + .. literalinclude:: include/rospy_demoapp1.py + :language: python + :tab-width: 2 + :lines: 71-79 + +* Please refer to |api_link| to get more information on the available list of APIs. + +.. |api_link| raw:: html + + FlytAPIs + + + +Demo App 2 +---------- + +.. note:: This demo requires arguments to be passed. + + +This demo app makes the drone takeoff, move in a square trajectory of side length *provided as an argument to the script* and land once the entire mission is over. + +Execution +""""""""""""""" + +If you have downloaded the programs successfully, execute them by running the following command in your terminal. + +.. code-block:: bash + + $ rosrun ros_demoapps demoapp2.py 3.0 + # here '3.0' is passed as an argument, one could send any other float value. + +Code +"""""""""" + +.. literalinclude:: include/rospy_demoapp2.py + :language: python + :tab-width: 2 + + + +.. _github page: https://github.com/flytbase/flytsamples/tree/master/CPP-Python-ROS-Apps/ros_demoapps + + +.. |br| raw:: html + +
diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile.rst index 7602366..5d4cfd5 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile.rst @@ -1,24 +1,24 @@ -.. _write_remote_mobile: - -Remote Mobile -=============== - - -These apps run on a mobile device and communicate with the drone using RESTful and WebSocket FlytAPIs. These apps can be built in native languages like Java-for-Android or using cross-platform frameworks like Cordova. Samples for remote mobile apps are available in `Flytsamples github `_. - -**Android-Apps**: These are native Android apps built using java and Android Studio. This approach provides full flexibility in terms of native support for the platform. We have put together an `Android SDK `_ for Flytbase to help you get started with your custom Android app. -:ref:`Read more`. - - -**HTML-JS-Apps**: These apps are built using web technologies - HTML/JS/CSS and Cordova framework. Using cordova the app can be converted to desired target platform like Android, iOS or Blackberry etc. This is a good option for quick prototyping and building cross platform apps. -:ref:`Read more`. - - - -.. toctree:: - :maxdepth: 2 - :hidden: - :caption: Developers - - ./RemoteMobile/RemoteAndroidApps.rst - ./RemoteMobile/RemoteWebApps.rst +.. _write_remote_mobile: + +Remote Mobile +=============== + + +These apps run on a mobile device and communicate with the drone using RESTful and WebSocket FlytAPIs. These apps can be built in native languages like Java-for-Android or using cross-platform frameworks like Cordova. Samples for remote mobile apps are available in `Flytsamples github `_. + +**Android-Apps**: These are native Android apps built using java and Android Studio. This approach provides full flexibility in terms of native support for the platform. We have put together an Android SDK for Flytbase to help you get started with your custom Android app. +:ref:`Read more` + + +**HTML-JS-Apps**: These apps are built using web technologies - HTML/JS/CSS and Cordova framework. Using cordova the app can be converted to desired target platform like Android, iOS or Blackberry etc. This is a good option for quick prototyping and building cross platform apps. +:ref:`Read more` + + + +.. toctree:: + :maxdepth: 2 + :hidden: + :caption: Developers + + ./RemoteMobile/RemoteAndroidApps.rst + ./RemoteMobile/RemoteWebApps.rst \ No newline at end of file diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/FlytPython.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/FlytPython.rst new file mode 100644 index 0000000..7bec677 --- /dev/null +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/FlytPython.rst @@ -0,0 +1,106 @@ +.. _write_remote_python: + +Remote Python App +================= + + +Setup +""""" +1. Install the package by typing in terminal: + +.. code-block:: bash + + $ pip install flyt-python + +2. Open terminal and install Redis-server by typing: + +.. code-block:: bash + + $ sudo apt-get install redis-server + +3. Setup |FlytSim Docker| +4. Follow the Documentation and launch the Docker. +5. Activate and Register Flytsim docker device using Flytbase Platform and get |Vehicle ID| and |Personal Access Token| +6. Go to the folder where library exists, open terminal and type `python3 daemon.py` and press Enter. + + +Execution +""""""""" + +The source code *demoapp1.py* of this app is located at */flyt_python/Demo Apps/*. To execute this app run the following command in your terminal. + +.. code-block:: bash + + $ python3 demo_app_1.py + +Code +"""" + +.. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + +Code Explained +"""""""""""""" + +* Imports: + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 1 + +* Enter token and vehicle ID for your drone + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 2-3 + +* Creating instance of DroneApiConnector from flyt_python.flyt_python: + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 5 + +* Connect to the Drone + + .. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 8 + +* Actual flight logic: By default position_set() is synchronous in action, i.e. your script will wait for the vehicle to reach the specified target before continuing to execute the next command. Visit `FlytAPIs `_ for more information. + +.. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 10-20 + +* Interface shutdown: + +When drone interface is no longer required close the connection : + +.. literalinclude:: include/demo_app_1.py + :language: py + :tab-width: 2 + :lines: 21-22 + + +.. |FlytSim Docker| raw:: html + + FlytSim Docker + + +.. |Vehicle ID| raw:: html + + Vehicle ID + + +.. |Personal Access Token| raw:: html + + Personal Access Token + + + \ No newline at end of file diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteAndroidApps.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteAndroidApps.rst index 687bec4..be03e9f 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteAndroidApps.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteAndroidApps.rst @@ -1,73 +1,143 @@ -.. _write_remote_mobile_android: - - -Android App - Java (Android-Studio) -==================================== - -Sample App -^^^^^^^^^^ -Download the `FlytSample repository `_ from Github. - -**Building** - -* Open Android Studio, and from the Welcome screen, select Open an existing Android Studio project. -* From the Open File or Project window that appears, navigate to and select the directory where you have cloned the FlytSample App, Click OK. -* If it asks you to do a Gradle Sync, click OK. -* You may also need to install various platforms and tools, if you get errors like **"Failed to find target with hash string 'android-23' "** and similar. -* Click the Run button (the green arrow) or use Run -> Run 'android' from the top menu. -* If it asks you to use Instant Run, click Proceed Without Instant Run. -* Also, you need to have an Android device plugged in with developer options enabled at this point. See here for more details on setting up developer devices. - -How to use FlytSDK -^^^^^^^^^^^^^^^^^^ - -**Following is a sample implementation of the REST call to fetch namespace from FlytOS** - - .. code-block:: java - - HttpParam httpParam = new HttpParam(); - httpParam.setUrl("http://" + {IP ADDRESS} + "/ros/get_global_namespace"); - JSONObject params=new JSONObject(); - httpParam.setParams(params); - - HttpRequest request= new HttpRequest(new HttpRequest.IResponseHandler() { - @Override - public void onResponse(String response) { - try { - JSONObject resp = new JSONObject(response); - namespace = resp.getJSONObject("param_info").getString("param_value"); - } catch (Exception| IOError e) { - } - } - }); - request.execute(httpParam); - - -**Following is a sample implementation of the websocket call to get state from FlytOS** - - - .. code-block:: java - - Ros ros=new Ros("ws://"+{IP Address}+"/websocket"); - ros.connect(); - - - - - - - .. code-block:: java - - Topic stateData = new Topic(ros, "/" + namespace + "/flyt/state","mavros_msgs/State", 200); - stateData.subscribe(new CallbackRos() { - @Override - public void handleMessage(JSONObject message) { - try { - connectionStatus = message.getBoolean("connected"); - armStatus= message.getBoolean("armed"); - } catch (JSONException e) { - } - } - }); - - +.. _write_remote_mobile_android: + + +Android App - Java (Android-Studio) +==================================== + +* You can download FlytSDK android from `here `__ and build your app using it. + + +.. figure:: /_static/Images/android-sdk.png + :align: center + :width: 30% + +* The SDK has all the required libraries for making REST calls and a websocket connection to FlytOS already integrated in it. +* The mainActivity in it shows a sample of how a REST call and a WebSocket call is to be made. +* Sample REST call to fetch namespace from FlytOS + + .. code-block:: java + + private class NamespaceRequest extends AsyncTask { + @Override + protected String doInBackground(Void... params) { + try { + //Rest url + final String url = "http://"+IP+"/ros/get_global_namespace"; + //params in json + String requestJson = "{}"; + //headers + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity entity = new HttpEntity(requestJson,headers); + //restTemplate object initialise for rest call + RestTemplate restTemplate = new RestTemplate(); + restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); + // make the rest call and recieve the response in "response" + String response = restTemplate.postForObject(url,entity, String.class); + + return response; + } catch (Exception e) { + Log.e("MainActivity", e.getMessage(), e); + } + + return null; + } + //function called after a successful rest call + @Override + protected void onPostExecute(String response) { + if (response!="") { + + try { + //initialise a JSON object with the response string + JSONObject resp = new JSONObject(response); + //extract the required field from the JSON object + namespace=resp.getJSONObject("param_info").getString("param_value"); + } catch (JSONException | NullPointerException e) { + } + } + } + +* Sample websocket call to view roll pitch yaw from FlytOS. + + .. code-block:: java + + IP=editTextIP.getText().toString(); + //Initialise a ros object with websocket url + ros=new Ros("ws://"+IP+"/websocket"); + ros.connect(); + + + .. note:: The Ros object initialisation is done once every time the app is run unless you are planning to connect to multiple FlytOS devices. + + + + + .. code-block:: java + + //the namespace(unique for every FlytPOD) fetched from the rest call is used to subscribe to a web socket topic + //the syntax Topic(, , , optional) + topic=new Topic(ros,"/"+namespace+"/mavros/imu/data_euler" , "geometry_msgs/TwistStamped",200); + topic.subscribe(new CallbackRos(){ + //callback method- what to do when messages recieved. + @Override + public void handleMessage(JSONObject message){ + try { + updateRoll(message.getJSONObject("twist").getJSONObject("linear").getDouble("x")); + updatePitch(message.getJSONObject("twist").getJSONObject("linear").getDouble("y")); + updateYaw(message.getJSONObject("twist").getJSONObject("linear").getDouble("z")); + + + }catch(JSONException e){} + } + }); + +Sample Apps +---------------- + + +1. Joystick App +^^^^^^^^^^^^^^^^^ + +* This is a sample joystick app to control your drone like you would in a regular joystick. +* To try this app you can download the apk from `here `__ or download the source code from `here `__. + +* Once you have connected to your FlytOS device using the right URL, you will be redirected to the app screen. + +* You need to press takeoff before you can use the joystick to control your drone(default 7 mts). + +* The right joystick gives the drone commands to move up, down, turn-left and turn-right. + +* The left joystick gives the drone commands to move front, back, left and right. + +* All the commands are given with respect to the drone(front = direction of the nose/front of the drone). + +* The app uses velocity_set API to control the drone. + + .. image:: /_static/Images/flytAndroidSample2.png + :height: 300px + :width: 500px + :align: center + + +2. Follow me App +^^^^^^^^^^^^^^^^^^^^^^ + +* This App allows the user to send the drone the its(mobile device running the app) GPS location on click of a button and make the drone follow you. +* To try this app you can download the apk from `here `_ or download the source code from `here `__. +* Once you have connected to your FlytOS device using the right URL, you will be redirected to the app screen. +* The blue marker shows the location of the drone on the map. +* The blue dot shows the mobile location of the mobile device. +* Click on the follow on button on the bottom of the screen for the drone to start following you. +* Please wait for the mobile device to get an accurate GPS location for the drone to start accepting the GPS location. +* Click on follow off to stop the drone from following. +* Click the nudge button on the left side of the screen (first button on the left) to give or remove any offset between you and your drone when placed at the same location. +* Keep in mind to stop follow before giving it Land command. + + + .. image:: /_static/Images/follow-me-android-app.png + :height: 500px + :width: 300px + :align: center + + diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteWebApps.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteWebApps.rst index 9c5dbeb..1e60cb4 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteWebApps.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/RemoteWebApps.rst @@ -1,163 +1,163 @@ -.. _write_remote_mobile_web: - -Android App- HTML,CSS,JS (Cordova) -================================== - - -Introduction --------------- - -This document deals with the instructions and step by step guide for creating Mobile apps for your Drone. There are two ways of doing so. The conventional way is to build a mobile app in JAVA using IDEs such as Eclipse or Android Studio. The other way of going about creating mobile apps is to reuse the Web app code i.e a simple HTML, CSS and JS project and convert that into a mobile app using frameworks such as Cordova and Phonegap. This allows for sharing the same codebase for creating cross-platform mobile apps. - - -Here in the second approach we develop an android app with HTML, CSS, JS/Jquery using Cordova engine. These apps will allow you to remotely monitor and command your drone. You will also see how to get custom data from the Drone on your app. The IDE that we have selected for this approach is IntelliJ Idea. The GUI and the client side coding is done in HTML, CSS and JS/Jquery, reused code from Web Apps to create Mobile Apps. - - -.. figure:: /_static/Images/Web_mobile_blockdiagram.png - :align: center - - - Flow diagram of Web/Mobile application development - - - - - -Development Environment Setup ------------------------------- - -For a quick start, you can follow the steps given below to install Ionic, Cordova and IntelliJ IDEA: - - -#. Please install Node.js v4 (Node.js v5 does not work at the moment with Ionic). To install node.js go to this `link`_. This will also install the node package manager npm. - - -#. Using npm install the latest Ionic and Cordova:: - - $ sudo npm install -g cordova ionic - - -#. Follow the `Android`_ and `iOS`_ platform guides to install required platform dependencies (SDKs). - - .. note:: **Follow this step for Mobile app development only.** iOS development requires Mac OS X. iOS simulator through the Ionic CLI requires the ios-sim npm package, which can be installed with the command ``sudo npm -g install ios-sim``. - - - - -#. IntelliJ IDEA also requires JDK 1.6 or higher. To install JDK 7 go to `this link`_. - - - .. important:: Please install JDK before installing Android Studio or Android SDK Tools. - - -#. Go to the `link here`_ to install IntelliJ IDEA. - -Create a new Project --------------------- - - -Follow the steps below to get create a mobile app : - -#. Launch IntelliJ IDEA and click on create new project. -#. Select **Static Web** in the new window on the left side. -#. Make sure **PhoneGap/Cordova App** is selected on the right and click on next. -#. Fill up details of your project viz. Project Name and Project Location. Click on Finish. -#. New project opens up. You can create/edit your HTML, CSS and JS/Jquery files here. - - -The front end of the app is developed in HTML, CSS, JS/Jquery . - - -To start building an Android App using Cordova all you need to do is, add the files of `FlytSDK Web `_ to this project and build your App like you would a Web App (editing the app.html and app.js files). - - -Build and Run the Project ---------------------------------- - - - -You can build and run the app using IntelliJ IDEA in either a browser based emulator or load the app on your mobile device. - -**Running in Browser:** - -- Go to **view**. -- Click on the **Open in browser** option. -- Select the browser of your choice. - - -**Running in Device:** - -- Connect mobile device to computer using a USB cable. -- Select **Specify target** in IntelliJ Idea corresponding to your device (Refresh if necessary). -- Click on **Run** button to start building your app and to install it on the device. - - -Sample Mobile Application --------------------------- - - -In the earlier section we had built a Web app for the drone, we can also build an Android/iOS application by converting this Web app using Cordova. This application allows you to trigger an on-board service to takeoff and land the drone from your mobile device. - - -You just need to connect to the FlytOS running system by entering the **URL** in the first App screen. - - - - -.. image:: /_static/Images/mobile-sample-app-url.png - :align: center - -.. image:: /_static/Images/mobile-app-sample.png - :align: center - - -You can Also try out `Flyt Joystick `_ app or view the code from the `repository `_: - -- Install or build the app and launch it. -- Enter the IP of the device running FlytOS to be able to communicate with it. - -.. image:: /_static/Images/app-login-screen.png - :align: center - -- Once the IP is confirmed you are redirected to the app screen. -- This App allows the user to send the drone velocity setpoints and control the drone as with a regular joystick. - -Things to Remember - -- You need to takeoff before you can use the joystick to control your drone. -- The left joystick gives the drone commands to move up, down, turn-left and turn-right. -- The right joystick gives the drone commands to move front, back, left and right. -- All the commands are given with respect to the drone(front = direction of the nose/front of the drone). - - -.. image:: /_static/Images/app-screen.png - :align: center - - - - - - -.. _Ionic components: http://ionicframework.com/docs/components/ - -.. _getting started: http://ionicframework.com/getting-started - -.. _here: https://cordova.apache.org/docs/en/latest/guide/overview/ - -.. _click here: https://www.jetbrains.com/idea/ - -.. _link: https://nodejs.org/en/download/ - -.. _this link: https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get - -.. _link here: https://www.jetbrains.com/idea/download - -.. _Ionic components: http://ionicframework.com/docs/components/ - -.. _GitHub repository: https://github.com/navstik/flytsamples - -.. _Android: http://cordova.apache.org/docs/en/5.1.1/guide/platforms/android/index.html - -.. _ios: http://cordova.apache.org/docs/en/5.1.1/guide/platforms/ios/index.html - - +.. _write_remote_mobile_web: + +Android App- HTML,CSS,JS (Cordova) +================================== + + +Introduction +-------------- + +This document deals with the instructions and step by step guide for creating Mobile apps for your Drone. There are two ways of doing so. The conventional way is to build a mobile app in JAVA using IDEs such as Eclipse or Android Studio. The other way of going about creating mobile apps is to reuse the Web app code i.e a simple HTML, CSS and JS project and convert that into a mobile app using frameworks such as Cordova and Phonegap. This allows for sharing the same codebase for creating cross-platform mobile apps. + + +Here in the second approach we develop an android app with HTML, CSS, JS/Jquery using Cordova engine. These apps will allow you to remotely monitor and command your drone. You will also see how to get custom data from the Drone on your app. The IDE that we have selected for this approach is IntelliJ Idea. The GUI and the client side coding is done in HTML, CSS and JS/Jquery, reused code from Web Apps to create Mobile Apps. + + +.. figure:: /_static/Images/Web_mobile_blockdiagram.png + :align: center + + + Flow diagram of Web/Mobile application development + + + + + +Development Environment Setup +------------------------------ + +For a quick start, you can follow the steps given below to install Ionic, Cordova and IntelliJ IDEA: + + +#. Please install Node.js v4 (Node.js v5 does not work at the moment with Ionic). To install node.js go to this `link`_. This will also install the node package manager npm. + + +#. Using npm install the latest Ionic and Cordova:: + + $ sudo npm install -g cordova ionic + + +#. Follow the `Android`_ and `iOS`_ platform guides to install required platform dependencies (SDKs). + + .. note:: **Follow this step for Mobile app development only.** iOS development requires Mac OS X. iOS simulator through the Ionic CLI requires the ios-sim npm package, which can be installed with the command ``sudo npm -g install ios-sim``. + + + + +#. IntelliJ IDEA also requires JDK 1.6 or higher. To install JDK 7 go to `this link`_. + + + .. important:: Please install JDK before installing Android Studio or Android SDK Tools. + + +#. Go to the `link here`_ to install IntelliJ IDEA. + +Create a new Project +-------------------- + + +Follow the steps below to get create a mobile app : + +#. Launch IntelliJ IDEA and click on create new project. +#. Select **Static Web** in the new window on the left side. +#. Make sure **PhoneGap/Cordova App** is selected on the right and click on next. +#. Fill up details of your project viz. Project Name and Project Location. Click on Finish. +#. New project opens up. You can create/edit your HTML, CSS and JS/Jquery files here. + + +The front end of the app is developed in HTML, CSS, JS/Jquery . + + +To start building an Android App using Cordova all you need to do is, add the files of `FlytSDK Web `_ to this project and build your App like you would a Web App (editing the app.html and app.js files). + + +Build and Run the Project +--------------------------------- + + + +You can build and run the app using IntelliJ IDEA in either a browser based emulator or load the app on your mobile device. + +**Running in Browser:** + +- Go to **view**. +- Click on the **Open in browser** option. +- Select the browser of your choice. + + +**Running in Device:** + +- Connect mobile device to computer using a USB cable. +- Select **Specify target** in IntelliJ Idea corresponding to your device (Refresh if necessary). +- Click on **Run** button to start building your app and to install it on the device. + + +Sample Mobile Application +-------------------------- + + +In the earlier section we had built a Web app for the drone, we can also build an Android/iOS application by converting this Web app using Cordova. This application allows you to trigger an on-board service to takeoff and land the drone from your mobile device. + + +You just need to connect to the FlytOS running system by entering the **URL** in the first App screen. + + + + +.. image:: /_static/Images/mobile-sample-app-url.png + :align: center + +.. image:: /_static/Images/mobile-app-sample.png + :align: center + + +You can Also try out `Flyt Joystick `_ app or view the code from the `repository `_: + +- Install or build the app and launch it. +- Enter the IP of the device running FlytOS to be able to communicate with it. + +.. image:: /_static/Images/app-login-screen.png + :align: center + +- Once the IP is confirmed you are redirected to the app screen. +- This App allows the user to send the drone velocity setpoints and control the drone as with a regular joystick. + +Things to Remember + +- You need to takeoff before you can use the joystick to control your drone. +- The left joystick gives the drone commands to move up, down, turn-left and turn-right. +- The right joystick gives the drone commands to move front, back, left and right. +- All the commands are given with respect to the drone(front = direction of the nose/front of the drone). + + +.. image:: /_static/Images/app-screen.png + :align: center + + + + + + +.. _Ionic components: http://ionicframework.com/docs/components/ + +.. _getting started: http://ionicframework.com/getting-started + +.. _here: https://cordova.apache.org/docs/en/latest/guide/overview/ + +.. _click here: https://www.jetbrains.com/idea/ + +.. _link: https://nodejs.org/en/download/ + +.. _this link: https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get + +.. _link here: https://www.jetbrains.com/idea/download + +.. _Ionic components: http://ionicframework.com/docs/components/ + +.. _GitHub repository: https://github.com/navstik/flytsamples + +.. _Android: http://cordova.apache.org/docs/en/5.1.1/guide/platforms/android/index.html + +.. _ios: http://cordova.apache.org/docs/en/5.1.1/guide/platforms/ios/index.html + + diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/include/demo_app_1.py b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/include/demo_app_1.py new file mode 100644 index 0000000..4181664 --- /dev/null +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteMobile/include/demo_app_1.py @@ -0,0 +1,22 @@ +from flyt_python.flyt_python import DroneApiConnector +token = '' # Personal Access Token +vehicle_id = '' # Vehicle ID + +drone = DroneApiConnector(token,vehicle_id,ip_address = 'localhost', wait_for_drone_response = True) + +# Initialize the drone's connection +drone.connect() + +print("Taking Off") +drone.takeoff(5) + +print("Drawing square with side = 5") + +drone.set_local_position(x=5, y=0, z=0, body_frame=True) +drone.set_local_position(x=0, y=5, z=0, body_frame=True) +drone.set_local_position(x=-5, y=0, z=0,body_frame=True) +drone.set_local_position(x=0, y=-5, z=0,body_frame=True) + +drone.land() +#disconnect the drone +drone.disconnect() diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteWeb.rst b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteWeb.rst index f524cfd..b006a79 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteWeb.rst +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/RemoteWeb.rst @@ -1,163 +1,163 @@ -.. _write_remote_web: - -Remote Web -=============== - -Introduction -------------- -Web apps provide an easy way to interact with the drone. These apps use the RESTful and Websocket FlytAPIs. -There are several sample web apps available on `Flytsamples github `_. Here we will go through the steps to create your own custom web app. - - - -Create a New Project ---------------------- - -* We have put together a `Web SDK `_ for Flytbase to help speed up the process of building your custom app - -* You can download the SDK `here `__ and follow the `instructions `_ to get a “Hello World” app up and running. -* The SDK has a **URL** screen and websocket initialisation code pre-integrated. This helps to establish connection and access telemetry data which is required for all the apps -* All your app specific UI components and JS code goes in app.html and app.js respectively. -* Next step is to add specific UI components and respective socket or REST calls from the `API documentation `_ to the above mentioned files and you are good to go. - - - -Deploying the App ------------------ - -There are two ways to deploy web apps built using FlytAPIs. One option is to deploy an app on the onboard web server within FlytOS or alternately the app can be deployed remotely on your own custom server. - -**Deploying on Onboard Server** - - -* Go into the folder /flyt/flytapps/web/. -* Create a folder for your Web app, eg sampleApp. -* Inside th samplApp folder create a folder named static and paste the contents of your Web app folder inside this folder. -* Create an empty document named __init__.py and views.py alongside static folder. -* Open the views.py file and write the following code: - -.. code-block:: python - - from flask import Blueprint, render_template - - sampleApp = Blueprint('sampleApp', __name__,static_folder='static') - - @sampleApp.route('/') - def timeline(): - return sampleApp.send_static_file('index.html') - #index.html is the page that is rendered when your custom webapp is fired. - - - -* Now come back to /flyt/flytapps/web/ and add an entry for your sampleApp in apps.py file. - -.. code-block:: python - - from flask import Blueprint, render_template, Flask - - from .user_app1.views import user_app1 - from .sampleApp.views import sampleApp - - def register_user( main_app ): - main_app.register_blueprint(user_app1,url_prefix='/user_app1') - main_app.register_blueprint(sampleApp,url_prefix='/sampleApp') - - - - -* Now restart the FlytOS and your web app will be served at /sampleApp . -* You can also try out other Sample Apps in the `repository `_. - - -**Deploying on Remote Server** - -You can deploy the app on a remote server of your choice. The HTML/JS/CSS code of the app will typically go in the static directory while the server side code will depend on the server stack used. The SDK has an initial connection page which is useful in remote deployment to provide the URL(IP) of the system running FlytOS. The internal REST/WebSocket calls are then routed accordingly. -Here are the steps for a sample remote deployment using a simple flask dev server: - -* Create a folder for your Web app, eg sampleApp. -* Inside the samplApp folder create a folder named static and paste the contents (HTML/JS/CSS) of your Web app folder inside this folder. -* Create an empty document named __init__.py and sampleapp.py alongside static folder. -* Open the sampleapp.py file and write the following code: - -.. code-block:: python - - #!/usr/bin/python - - - from flask import Flask - - # Setup Flask app. - app = Flask(__name__) - app.debug = True - - - # Routes - @app.errorhandler(Exception) - def unhandled_exception(e): - return str(e),500 - - @app.route('/') - def root(): - return app.send_static_file('index.html') - - - if __name__ == '__main__': - - app.run(host='0.0.0.0', - port=80, - debug=True, - use_reloader=True) - - -* To start the server, run the following command on command line from within your app directory : - -.. code-block:: bash - - $ sudo python sampleapp.py - -* To view your app, open a browser and go to http:// - -Note: This is only a dev server and for production deployment with flask you can check the options `here `_ - - - - -Sample Web Application ------------------------ - -.. note:: The source code for the sample web/mobile apps is available in `github repository `_ for your reference. - - - -Following is a simple demonstration of how to run a Web application for your drone. This application allows you to trigger an on-board service that sends commands to your drone to takeoff and land. - - - -.. image:: /_static/Images/sample-app-screen.png - :align: center - - - - -You can Also try out `Joystick `_ Web app : - -- Launch the index.html file in your browser. -- Enter the IP of the device running FlytOS to be able to communicate with it. - -.. image:: /_static/Images/web-app-login-screen.png - :align: center - -- Once the IP is confirmed you are redirected to the app screen. -- This App allows the user to send the drone velocity setpoints and control the drone as with a regular joystick. - -Things to Remember - -- You need to takeoff before you can use the joystick to control your drone. -- The left joystick gives the drone commands to move up, down, turn-left and turn-right. -- The right joystick gives the drone commands to move front, back, left and right. -- All the commands are given with respect to the drone(front = direction of the nose/front of the drone). - - -.. image:: /_static/Images/web-app-screen.png - :align: center - +.. _write_remote_web: + +Remote Web +=============== + +Introduction +------------- +Web apps provide an easy way to interact with the drone. These apps use the RESTful and Websocket FlytAPIs. +There are several sample web apps available on `Flytsamples github `_. Here we will go through the steps to create your own custom web app. + + + +Create a New Project +--------------------- + +* We have put together a `Web SDK `_ for Flytbase to help speed up the process of building your custom app + +* You can download the SDK `here `__ and follow the `instructions `_ to get a “Hello World” app up and running. +* The SDK has a **URL** screen and websocket initialisation code pre-integrated. This helps to establish connection and access telemetry data which is required for all the apps +* All your app specific UI components and JS code goes in app.html and app.js respectively. +* Next step is to add specific UI components and respective socket or REST calls from the `API documentation `_ to the above mentioned files and you are good to go. + + + +Deploying the App +----------------- + +There are two ways to deploy web apps built using FlytAPIs. One option is to deploy an app on the onboard web server within FlytOS or alternately the app can be deployed remotely on your own custom server. + +**Deploying on Onboard Server** + + +* Go into the folder /flyt/flytapps/web/. +* Create a folder for your Web app, eg sampleApp. +* Inside th samplApp folder create a folder named static and paste the contents of your Web app folder inside this folder. +* Create an empty document named __init__.py and views.py alongside static folder. +* Open the views.py file and write the following code: + +.. code-block:: python + + from flask import Blueprint, render_template + + sampleApp = Blueprint('sampleApp', __name__,static_folder='static') + + @sampleApp.route('/') + def timeline(): + return sampleApp.send_static_file('index.html') + #index.html is the page that is rendered when your custom webapp is fired. + + + +* Now come back to /flyt/flytapps/web/ and add an entry for your sampleApp in apps.py file. + +.. code-block:: python + + from flask import Blueprint, render_template, Flask + + from .user_app1.views import user_app1 + from .sampleApp.views import sampleApp + + def register_user( main_app ): + main_app.register_blueprint(user_app1,url_prefix='/user_app1') + main_app.register_blueprint(sampleApp,url_prefix='/sampleApp') + + + + +* Now restart the FlytOS and your web app will be served at /sampleApp . +* You can also try out other Sample Apps in the `repository `_. + + +**Deploying on Remote Server** + +You can deploy the app on a remote server of your choice. The HTML/JS/CSS code of the app will typically go in the static directory while the server side code will depend on the server stack used. The SDK has an initial connection page which is useful in remote deployment to provide the URL(IP) of the system running FlytOS. The internal REST/WebSocket calls are then routed accordingly. +Here are the steps for a sample remote deployment using a simple flask dev server: + +* Create a folder for your Web app, eg sampleApp. +* Inside the samplApp folder create a folder named static and paste the contents (HTML/JS/CSS) of your Web app folder inside this folder. +* Create an empty document named __init__.py and sampleapp.py alongside static folder. +* Open the sampleapp.py file and write the following code: + +.. code-block:: python + + #!/usr/bin/python + + + from flask import Flask + + # Setup Flask app. + app = Flask(__name__) + app.debug = True + + + # Routes + @app.errorhandler(Exception) + def unhandled_exception(e): + return str(e),500 + + @app.route('/') + def root(): + return app.send_static_file('index.html') + + + if __name__ == '__main__': + + app.run(host='0.0.0.0', + port=80, + debug=True, + use_reloader=True) + + +* To start the server, run the following command on command line from within your app directory : + +.. code-block:: bash + + $ sudo python sampleapp.py + +* To view your app, open a browser and go to http:// + +Note: This is only a dev server and for production deployment with flask you can check the options `here `_ + + + + +Sample Web Application +----------------------- + +.. note:: The source code for the sample web/mobile apps is available in `github repository `_ for your reference. + + + +Following is a simple demonstration of how to run a Web application for your drone. This application allows you to trigger an on-board service that sends commands to your drone to takeoff and land. + + + +.. image:: /_static/Images/sample-app-screen.png + :align: center + + + + +You can Also try out `Joystick `_ Web app : + +- Launch the index.html file in your browser. +- Enter the IP of the device running FlytOS to be able to communicate with it. + +.. image:: /_static/Images/web-app-login-screen.png + :align: center + +- Once the IP is confirmed you are redirected to the app screen. +- This App allows the user to send the drone velocity setpoints and control the drone as with a regular joystick. + +Things to Remember + +- You need to takeoff before you can use the joystick to control your drone. +- The left joystick gives the drone commands to move up, down, turn-left and turn-right. +- The right joystick gives the drone commands to move front, back, left and right. +- All the commands are given with respect to the drone(front = direction of the nose/front of the drone). + + +.. image:: /_static/Images/web-app-screen.png + :align: center + diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/CMakeLists.txt b/source/docs/FlytOS/Developers/BuildingCustomApps/include/CMakeLists.txt index 21c5131..a9e515a 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/CMakeLists.txt +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/CMakeLists.txt @@ -1,19 +1,19 @@ - -cmake_minimum_required(VERSION 2.8.3) -project(demoapp1) - -SET(CMAKE_INSTALL_PREFIX /usr/local/flytos/flytapps CACHE PATH "Cmake install prefix path for flytapps" FORCE) - -add_definitions(-std=c++11) - -find_package(catkin REQUIRED COMPONENTS cpp_api) -find_package(Boost REQUIRED COMPONENTS system python) -find_package(PythonLibs 2.7 REQUIRED) -include_directories(${catkin_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) - -add_executable(demoapp1 demoapp1.cpp) -target_link_libraries(demoapp1 ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) - -install(TARGETS demoapp1 - DESTINATION /flyt/userapps/onboard_user/install COMPONENT Runtime -) + +cmake_minimum_required(VERSION 2.8.3) +project(demoapp1) + +SET(CMAKE_INSTALL_PREFIX /usr/local/flytos/flytapps CACHE PATH "Cmake install prefix path for flytapps" FORCE) + +add_definitions(-std=c++11) + +find_package(catkin REQUIRED COMPONENTS cpp_api) +find_package(Boost REQUIRED COMPONENTS system python) +find_package(PythonLibs 2.7 REQUIRED) +include_directories(${catkin_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) + +add_executable(demoapp1 demoapp1.cpp) +target_link_libraries(demoapp1 ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) + +install(TARGETS demoapp1 + DESTINATION /flyt/userapps/onboard_user/install COMPONENT Runtime +) diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demo_app_1.py b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demo_app_1.py new file mode 100644 index 0000000..4181664 --- /dev/null +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demo_app_1.py @@ -0,0 +1,22 @@ +from flyt_python.flyt_python import DroneApiConnector +token = '' # Personal Access Token +vehicle_id = '' # Vehicle ID + +drone = DroneApiConnector(token,vehicle_id,ip_address = 'localhost', wait_for_drone_response = True) + +# Initialize the drone's connection +drone.connect() + +print("Taking Off") +drone.takeoff(5) + +print("Drawing square with side = 5") + +drone.set_local_position(x=5, y=0, z=0, body_frame=True) +drone.set_local_position(x=0, y=5, z=0, body_frame=True) +drone.set_local_position(x=-5, y=0, z=0,body_frame=True) +drone.set_local_position(x=0, y=-5, z=0,body_frame=True) + +drone.land() +#disconnect the drone +drone.disconnect() diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.cpp b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.cpp index 98f5736..e469408 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.cpp +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.cpp @@ -1,12 +1,12 @@ -#include - -Navigation nav; -int main(int argc, char *argv[]) -{ - nav.take_off(3.0); //Taking Off - nav.position_set(5,0,-3); //Sending Position Setpoints - nav.position_set(5,5,-3); - nav.position_set(0,5,-3); - nav.position_set(0,0,-3); - nav.land(false); //Landing -} +#include + +Navigation nav; +int main(int argc, char *argv[]) +{ + nav.take_off(3.0); //Taking Off + nav.position_set(5,0,-3); //Sending Position Setpoints + nav.position_set(5,5,-3); + nav.position_set(0,5,-3); + nav.position_set(0,0,-3); + nav.land(false); //Landing +} diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.py b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.py old mode 100755 new mode 100644 index a53fd07..3ac6446 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.py +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp1.py @@ -1,23 +1,23 @@ -#!/usr/bin/env python -import time -from flyt_python import api - -drone = api.navigation(timeout=120000) # instance of flyt droneigation class - -# at least 3sec sleep time for the drone interface to initialize properly -time.sleep(3) - -print 'taking off' -drone.take_off(5.0) - -print ' going along the setpoints' -drone.position_set(5, 0, 0, relative=True) -drone.position_set(0, 5, 0, relative=True) -drone.position_set(-5, 0, 0, relative=True) -drone.position_set(0, -5, 0, relative=True) - -print 'Landing' -drone.land(async=False) - -# shutdown the instance -drone.disconnect() +#!/usr/bin/env python +import time +from flyt_python import api + +drone = api.navigation(timeout=120000) # instance of flyt droneigation class + +# at least 3sec sleep time for the drone interface to initialize properly +time.sleep(3) + +print 'taking off' +drone.take_off(5.0) + +print ' going along the setpoints' +drone.position_set(5, 0, 0, relative=True) +drone.position_set(0, 5, 0, relative=True) +drone.position_set(-5, 0, 0, relative=True) +drone.position_set(0, -5, 0, relative=True) + +print 'Landing' +drone.land(async=False) + +# shutdown the instance +drone.disconnect() diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.cpp b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.cpp index 9c27dda..3b9898a 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.cpp +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.cpp @@ -1,21 +1,21 @@ -#include -#include -#include - -Navigation nav; -int main(int argc, char *argv[]) -{ - if(argc < 2){ - std::cout<<"\nThis app expects arguments\n"; - exit(0); - } - - float side_length = std::stof(argv[1]); //Convert Argument from string to float - nav.take_off(3.0); //Taking Off - nav.position_set(side_length,0,-3); //Sending Position Setpoints with side length accepted from script - nav.position_set(side_length,side_length,-3); - nav.position_set(0,side_length,-3); - nav.position_set(0,0,-3); - nav.land(false); //Landing -} - +#include +#include +#include + +Navigation nav; +int main(int argc, char *argv[]) +{ + if(argc < 2){ + std::cout<<"\nThis app expects arguments\n"; + exit(0); + } + + float side_length = std::stof(argv[1]); //Convert Argument from string to float + nav.take_off(3.0); //Taking Off + nav.position_set(side_length,0,-3); //Sending Position Setpoints with side length accepted from script + nav.position_set(side_length,side_length,-3); + nav.position_set(0,side_length,-3); + nav.position_set(0,0,-3); + nav.land(false); //Landing +} + diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.py b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.py old mode 100755 new mode 100644 index b5f9300..ccbfa75 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.py +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/demoapp2.py @@ -1,33 +1,33 @@ -#!/usr/bin/env python -import time -import argparse -from flyt_python import api - -drone = api.navigation(timeout=120000) # instance of flyt droneigation class - -# at least 3sec sleep time for the drone interface to initialize properly -time.sleep(3) - -## parsing command line arguments -parser = argparse.ArgumentParser(description='Process a float value.') -parser.add_argument('side', metavar='side_length', type=float, help='side length of the square') -args = parser.parse_args() - -## lets fly -side_length = args.side - -print "taking off!" -drone.take_off(5.0) - -print 'flying in square', side_length -drone.position_set(side_length, 0, 0, relative=True) -drone.position_set(0, side_length, 0, relative=True) -drone.position_set(-side_length, 0, 0, relative=True) -drone.position_set(0, -side_length, 0, relative=True) - -print "landing" -drone.land(False) -print 'Cheers!!' - -# shutdown the instance -drone.disconnect() +#!/usr/bin/env python +import time +import argparse +from flyt_python import api + +drone = api.navigation(timeout=120000) # instance of flyt droneigation class + +# at least 3sec sleep time for the drone interface to initialize properly +time.sleep(3) + +## parsing command line arguments +parser = argparse.ArgumentParser(description='Process a float value.') +parser.add_argument('side', metavar='side_length', type=float, help='side length of the square') +args = parser.parse_args() + +## lets fly +side_length = args.side + +print "taking off!" +drone.take_off(5.0) + +print 'flying in square', side_length +drone.position_set(side_length, 0, 0, relative=True) +drone.position_set(0, side_length, 0, relative=True) +drone.position_set(-side_length, 0, 0, relative=True) +drone.position_set(0, -side_length, 0, relative=True) + +print "landing" +drone.land(False) +print 'Cheers!!' + +# shutdown the instance +drone.disconnect() diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_CMakeLists.txt b/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_CMakeLists.txt index 0e3b3ec..46977ca 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_CMakeLists.txt +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_CMakeLists.txt @@ -1,47 +1,47 @@ -cmake_minimum_required(VERSION 2.8.3) -project(roscpp_demoapps) - -## Add support for C++11, supported in ROS Kinetic and newer -add_definitions(-std=c++11) - -## Find catkin macros and libraries -## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) -## is used, also find other catkin packages -find_package(catkin REQUIRED COMPONENTS - core_api - roscpp - rospy -) - -################################### -## catkin specific configuration ## -################################### -## The catkin_package macro generates cmake config files for your package -## Declare things to be passed to dependent projects -## INCLUDE_DIRS: uncomment this if you package contains header files -## LIBRARIES: libraries you create in this project that dependent projects also need -## CATKIN_DEPENDS: catkin_packages dependent projects also need -## DEPENDS: system dependencies of this project that dependent projects also need -catkin_package( -# INCLUDE_DIRS include -# LIBRARIES roscpp_demoapp -# CATKIN_DEPENDS core_api roscpp rospy -# DEPENDS system_lib -) - -## Build - -## Specify additional locations of header files -## Your package locations should be listed before other locations -include_directories( - ${catkin_INCLUDE_DIRS} -) - -## Declare C++ executables - -add_executable(demoapp1_node src/demoapp1.cpp) -target_link_libraries(demoapp1_node ${catkin_LIBRARIES}) - - -add_executable(demoapp2_node src/demoapp2.cpp) -target_link_libraries(demoapp2_node ${catkin_LIBRARIES}) +cmake_minimum_required(VERSION 2.8.3) +project(roscpp_demoapps) + +## Add support for C++11, supported in ROS Kinetic and newer +add_definitions(-std=c++11) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + core_api + roscpp + rospy +) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES roscpp_demoapp +# CATKIN_DEPENDS core_api roscpp rospy +# DEPENDS system_lib +) + +## Build + +## Specify additional locations of header files +## Your package locations should be listed before other locations +include_directories( + ${catkin_INCLUDE_DIRS} +) + +## Declare C++ executables + +add_executable(demoapp1_node src/demoapp1.cpp) +target_link_libraries(demoapp1_node ${catkin_LIBRARIES}) + + +add_executable(demoapp2_node src/demoapp2.cpp) +target_link_libraries(demoapp2_node ${catkin_LIBRARIES}) diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp1.cpp b/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp1.cpp index f77c92b..c22d2c6 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp1.cpp +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp1.cpp @@ -1,89 +1,89 @@ -#include -#include -#include -#include -#include - -std::string global_namespace; - -core_api::ParamGetGlobalNamespace namespace_srv; -core_api::TakeOff takeoff_srv; -core_api::Land land_srv; -core_api::PositionSet pos_srv; - -ros::ServiceClient pos_client,land_client,takeoff_client; - - -bool position_set(float x, float y, float z) -{ - pos_srv.request.twist.twist.linear.x = x; - pos_srv.request.twist.twist.linear.y = y; - pos_srv.request.twist.twist.linear.z = z; - pos_srv.request.twist.twist.angular.z = 0.0; - pos_srv.request.tolerance = 1.0; - pos_srv.request.async = false; - pos_srv.request.yaw_valid = false; - pos_srv.request.relative = false; - pos_srv.request.body_frame = false; - ROS_INFO("Going to the next setpoint"); - pos_client.call(pos_srv); - return pos_srv.response.success; -} - -int main(int argc, char **argv) -{ - ros::init(argc, argv, "roscpp_demoapp1"); - ros::NodeHandle nh; - - ros::ServiceClient namespace_client = nh.serviceClient("/get_global_namespace"); - namespace_client.call(namespace_srv); - global_namespace = namespace_srv.response.param_info.param_value; - - takeoff_client = nh.serviceClient("/"+global_namespace+"/navigation/take_off"); - land_client = nh.serviceClient("/"+global_namespace+"/navigation/land"); - pos_client = nh.serviceClient("/"+global_namespace+"/navigation/position_set"); - - ROS_INFO("Taking Off"); - takeoff_srv.request.takeoff_alt = 3.0; - takeoff_client.call(takeoff_srv); - if(!takeoff_srv.response.success) - { - ROS_ERROR("Failed to takeoff"); - return 1; - } - - //Sending Position Setpoints - if(!position_set(5,0,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - if(!position_set(5,5,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - if(!position_set(0,5,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - if(!position_set(0,0,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - ROS_INFO("Landing"); - land_srv.request.async =false; - land_client.call(land_srv); - if(!land_srv.response.success) - { - ROS_ERROR("Failed to Land!"); - return 1; - } - return 0; +#include +#include +#include +#include +#include + +std::string global_namespace; + +core_api::ParamGetGlobalNamespace namespace_srv; +core_api::TakeOff takeoff_srv; +core_api::Land land_srv; +core_api::PositionSet pos_srv; + +ros::ServiceClient pos_client,land_client,takeoff_client; + + +bool position_set(float x, float y, float z) +{ + pos_srv.request.twist.twist.linear.x = x; + pos_srv.request.twist.twist.linear.y = y; + pos_srv.request.twist.twist.linear.z = z; + pos_srv.request.twist.twist.angular.z = 0.0; + pos_srv.request.tolerance = 1.0; + pos_srv.request.async = false; + pos_srv.request.yaw_valid = false; + pos_srv.request.relative = false; + pos_srv.request.body_frame = false; + ROS_INFO("Going to the next setpoint"); + pos_client.call(pos_srv); + return pos_srv.response.success; +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "roscpp_demoapp1"); + ros::NodeHandle nh; + + ros::ServiceClient namespace_client = nh.serviceClient("/get_global_namespace"); + namespace_client.call(namespace_srv); + global_namespace = namespace_srv.response.param_info.param_value; + + takeoff_client = nh.serviceClient("/"+global_namespace+"/navigation/take_off"); + land_client = nh.serviceClient("/"+global_namespace+"/navigation/land"); + pos_client = nh.serviceClient("/"+global_namespace+"/navigation/position_set"); + + ROS_INFO("Taking Off"); + takeoff_srv.request.takeoff_alt = 3.0; + takeoff_client.call(takeoff_srv); + if(!takeoff_srv.response.success) + { + ROS_ERROR("Failed to takeoff"); + return 1; + } + + //Sending Position Setpoints + if(!position_set(5,0,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + if(!position_set(5,5,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + if(!position_set(0,5,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + if(!position_set(0,0,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + ROS_INFO("Landing"); + land_srv.request.async =false; + land_client.call(land_srv); + if(!land_srv.response.success) + { + ROS_ERROR("Failed to Land!"); + return 1; + } + return 0; } \ No newline at end of file diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp2.cpp b/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp2.cpp index 45e99a0..73e06c5 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp2.cpp +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/roscpp_demoapp2.cpp @@ -1,97 +1,97 @@ -#include -#include -#include -#include -#include -#include - -std::string global_namespace; - -core_api::ParamGetGlobalNamespace namespace_srv; -core_api::TakeOff takeoff_srv; -core_api::Land land_srv; -core_api::PositionSet pos_srv; - -ros::ServiceClient pos_client,land_client,takeoff_client; - - -bool position_set(float x, float y, float z) -{ - pos_srv.request.twist.twist.linear.x = x; - pos_srv.request.twist.twist.linear.y = y; - pos_srv.request.twist.twist.linear.z = z; - pos_srv.request.twist.twist.angular.z = 0.0; - pos_srv.request.tolerance = 1.0; - pos_srv.request.async = false; - pos_srv.request.yaw_valid = false; - pos_srv.request.relative = false; - pos_srv.request.body_frame = false; - ROS_INFO("Going to the next setpoint"); - pos_client.call(pos_srv); - return pos_srv.response.success; -} - -int main(int argc, char **argv) -{ - if(argc < 2) - { - std::cout<<"\nThis app expects arguments\n"; - exit(0); - } - - float side_length = std::stof(argv[1]); //Convert Argument from string to float - ros::init(argc, argv, "roscpp_demoapp1"); - ros::NodeHandle nh; - - ros::ServiceClient namespace_client = nh.serviceClient("/get_global_namespace"); - namespace_client.call(namespace_srv); - global_namespace = namespace_srv.response.param_info.param_value; - - takeoff_client = nh.serviceClient("/"+global_namespace+"/navigation/take_off"); - land_client = nh.serviceClient("/"+global_namespace+"/navigation/land"); - pos_client = nh.serviceClient("/"+global_namespace+"/navigation/position_set"); - - ROS_INFO("Taking Off"); - takeoff_srv.request.takeoff_alt = 3.0; - takeoff_client.call(takeoff_srv); - if(!takeoff_srv.response.success) - { - ROS_ERROR("Failed to takeoff"); - return 1; - } - //Sending Position Setpoints - - if(!position_set(side_length,0,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - if(!position_set(side_length,side_length,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - if(!position_set(0,side_length,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - if(!position_set(0,0,-3)) - { - ROS_ERROR("Failed to set position"); - return 1; - } - - ROS_INFO("Landing"); - land_srv.request.async =false; - land_client.call(land_srv); - if(!land_srv.response.success) - { - ROS_ERROR("Failed to Land!"); - return 1; - } - return 0; +#include +#include +#include +#include +#include +#include + +std::string global_namespace; + +core_api::ParamGetGlobalNamespace namespace_srv; +core_api::TakeOff takeoff_srv; +core_api::Land land_srv; +core_api::PositionSet pos_srv; + +ros::ServiceClient pos_client,land_client,takeoff_client; + + +bool position_set(float x, float y, float z) +{ + pos_srv.request.twist.twist.linear.x = x; + pos_srv.request.twist.twist.linear.y = y; + pos_srv.request.twist.twist.linear.z = z; + pos_srv.request.twist.twist.angular.z = 0.0; + pos_srv.request.tolerance = 1.0; + pos_srv.request.async = false; + pos_srv.request.yaw_valid = false; + pos_srv.request.relative = false; + pos_srv.request.body_frame = false; + ROS_INFO("Going to the next setpoint"); + pos_client.call(pos_srv); + return pos_srv.response.success; +} + +int main(int argc, char **argv) +{ + if(argc < 2) + { + std::cout<<"\nThis app expects arguments\n"; + exit(0); + } + + float side_length = std::stof(argv[1]); //Convert Argument from string to float + ros::init(argc, argv, "roscpp_demoapp1"); + ros::NodeHandle nh; + + ros::ServiceClient namespace_client = nh.serviceClient("/get_global_namespace"); + namespace_client.call(namespace_srv); + global_namespace = namespace_srv.response.param_info.param_value; + + takeoff_client = nh.serviceClient("/"+global_namespace+"/navigation/take_off"); + land_client = nh.serviceClient("/"+global_namespace+"/navigation/land"); + pos_client = nh.serviceClient("/"+global_namespace+"/navigation/position_set"); + + ROS_INFO("Taking Off"); + takeoff_srv.request.takeoff_alt = 3.0; + takeoff_client.call(takeoff_srv); + if(!takeoff_srv.response.success) + { + ROS_ERROR("Failed to takeoff"); + return 1; + } + //Sending Position Setpoints + + if(!position_set(side_length,0,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + if(!position_set(side_length,side_length,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + if(!position_set(0,side_length,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + if(!position_set(0,0,-3)) + { + ROS_ERROR("Failed to set position"); + return 1; + } + + ROS_INFO("Landing"); + land_srv.request.async =false; + land_client.call(land_srv); + if(!land_srv.response.success) + { + ROS_ERROR("Failed to Land!"); + return 1; + } + return 0; } \ No newline at end of file diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp1.py b/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp1.py index 32add7c..46a6f60 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp1.py +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp1.py @@ -1,82 +1,82 @@ -#!/usr/bin/env python -import rospy -from core_api.srv import * - -global_namespace = '' - -def setpoint_local_position(lx, ly, lz, yaw=0.0, tolerance= 1.0, async = False, relative= False, yaw_valid= False, body_frame= False): - global global_namespace - rospy.wait_for_service('/'+ global_namespace +'/navigation/position_set') - try: - handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/position_set', PositionSet) - - # building message structure - header_msg = std_msgs.msg.Header(1,rospy.Time(0.0,0.0),'a') - twist = geometry_msgs.msg.Twist(geometry_msgs.msg.Vector3(lx,ly,lz),geometry_msgs.msg.Vector3(0.0,0.0,yaw)) - twiststamped_msg= geometry_msgs.msg.TwistStamped(header_msg, twist) - req_msg = PositionSetRequest(twiststamped_msg, tolerance, async, relative, yaw_valid, body_frame) - resp = handle(req_msg) - return resp.success - except rospy.ServiceException, e: - rospy.logerr("pos set service call failed %s", e) - return None - -def make_square(): - global global_namespace - #first get the global namespace to call the subsequent services - #wait for service to come up - rospy.wait_for_service('/get_global_namespace') - try: - res = rospy.ServiceProxy('/get_global_namespace', ParamGetGlobalNamespace) - op = res() - global_namespace = str(op.param_info.param_value) - except rospy.ServiceException, e: - rospy.logerr("global namespace service not available", e) - #cannot continue without global namespace - return None - - # Next take off to an altitue of 3.0 meters - rospy.wait_for_service('/'+ global_namespace +'/navigation/take_off') - try: - handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/take_off', TakeOff) - resp = handle(takeoff_alt=3.0) - except rospy.ServiceException, e: - rospy.logerr("takeoff service call failed %s", e) - # cannot continue without taking off - return None - print "Took off successfully" - - # Then call the position set service for each edge of a square shaped trajectory - if setpoint_local_position(5,0,-3.0): - print "Successfully reached 1st waypoint" - else: - rospy.logerr("Failed to set position") - return None - if setpoint_local_position(5,5,-3.0): - print "Successfully reached 2nd waypoint" - else: - rospy.logerr("Failed to set position") - return None - if setpoint_local_position(0,5,-3.0): - print "Successfully reached 3rd waypoint" - else: - rospy.logerr("Failed to set position") - return None - if setpoint_local_position(0,0,-3.0): - print "Successfully reached 4th waypoint" - else: - rospy.logerr("Failed to set position") - return None - - # Finally land the drone - rospy.wait_for_service('/'+ global_namespace +'/navigation/land') - try: - handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/land', Land) - resp = handle(False) - except rospy.ServiceException, e: - rospy.logerr("land service call failed %s", e) - return None - print "Landed Successfully. Exiting script." - -if __name__ == "__main__": +#!/usr/bin/env python +import rospy +from core_api.srv import * + +global_namespace = '' + +def setpoint_local_position(lx, ly, lz, yaw=0.0, tolerance= 1.0, async = False, relative= False, yaw_valid= False, body_frame= False): + global global_namespace + rospy.wait_for_service('/'+ global_namespace +'/navigation/position_set') + try: + handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/position_set', PositionSet) + + # building message structure + header_msg = std_msgs.msg.Header(1,rospy.Time(0.0,0.0),'a') + twist = geometry_msgs.msg.Twist(geometry_msgs.msg.Vector3(lx,ly,lz),geometry_msgs.msg.Vector3(0.0,0.0,yaw)) + twiststamped_msg= geometry_msgs.msg.TwistStamped(header_msg, twist) + req_msg = PositionSetRequest(twiststamped_msg, tolerance, async, relative, yaw_valid, body_frame) + resp = handle(req_msg) + return resp.success + except rospy.ServiceException, e: + rospy.logerr("pos set service call failed %s", e) + return None + +def make_square(): + global global_namespace + #first get the global namespace to call the subsequent services + #wait for service to come up + rospy.wait_for_service('/get_global_namespace') + try: + res = rospy.ServiceProxy('/get_global_namespace', ParamGetGlobalNamespace) + op = res() + global_namespace = str(op.param_info.param_value) + except rospy.ServiceException, e: + rospy.logerr("global namespace service not available", e) + #cannot continue without global namespace + return None + + # Next take off to an altitue of 3.0 meters + rospy.wait_for_service('/'+ global_namespace +'/navigation/take_off') + try: + handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/take_off', TakeOff) + resp = handle(takeoff_alt=3.0) + except rospy.ServiceException, e: + rospy.logerr("takeoff service call failed %s", e) + # cannot continue without taking off + return None + print "Took off successfully" + + # Then call the position set service for each edge of a square shaped trajectory + if setpoint_local_position(5,0,-3.0): + print "Successfully reached 1st waypoint" + else: + rospy.logerr("Failed to set position") + return None + if setpoint_local_position(5,5,-3.0): + print "Successfully reached 2nd waypoint" + else: + rospy.logerr("Failed to set position") + return None + if setpoint_local_position(0,5,-3.0): + print "Successfully reached 3rd waypoint" + else: + rospy.logerr("Failed to set position") + return None + if setpoint_local_position(0,0,-3.0): + print "Successfully reached 4th waypoint" + else: + rospy.logerr("Failed to set position") + return None + + # Finally land the drone + rospy.wait_for_service('/'+ global_namespace +'/navigation/land') + try: + handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/land', Land) + resp = handle(False) + except rospy.ServiceException, e: + rospy.logerr("land service call failed %s", e) + return None + print "Landed Successfully. Exiting script." + +if __name__ == "__main__": make_square() \ No newline at end of file diff --git a/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp2.py b/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp2.py index f4e4f32..70be140 100644 --- a/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp2.py +++ b/source/docs/FlytOS/Developers/BuildingCustomApps/include/rospy_demoapp2.py @@ -1,87 +1,87 @@ -#!/usr/bin/env python -import sys -import rospy -from core_api.srv import * - -global_namespace = '' - -def setpoint_local_position(lx, ly, lz, yaw=0.0, tolerance= 1.0, async = False, relative= False, yaw_valid= False, body_frame= False): - global global_namespace - rospy.wait_for_service('/'+ global_namespace +'/navigation/position_set') - try: - handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/position_set', PositionSet) - - # building message structure - header_msg = std_msgs.msg.Header(1,rospy.Time(0.0,0.0),'a') - twist = geometry_msgs.msg.Twist(geometry_msgs.msg.Vector3(lx,ly,lz),geometry_msgs.msg.Vector3(0.0,0.0,yaw)) - twiststamped_msg= geometry_msgs.msg.TwistStamped(header_msg, twist) - req_msg = PositionSetRequest(twiststamped_msg, tolerance, async, relative, yaw_valid, body_frame) - resp = handle(req_msg) - return resp.success - except rospy.ServiceException, e: - rospy.logerr("pos set service call failed %s", e) - return None - -def make_square(side_length): - global global_namespace - #first get the global namespace to call the subsequent services - #wait for service to come up - rospy.wait_for_service('/get_global_namespace') - try: - res = rospy.ServiceProxy('/get_global_namespace', ParamGetGlobalNamespace) - op = res() - global_namespace = str(op.param_info.param_value) - except rospy.ServiceException, e: - rospy.logerr("global namespace service not available", e) - #cannot continue without global namespace - return None - - # Next take off to an altitue of 3.0 meters - rospy.wait_for_service('/'+ global_namespace +'/navigation/take_off') - try: - handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/take_off', TakeOff) - resp = handle(takeoff_alt=3.0) - except rospy.ServiceException, e: - rospy.logerr("takeoff service call failed %s", e) - # cannot continue without taking off - return None - print "Took off successfully" - - # Then call the position set service for each edge of a square shaped trajectory - if setpoint_local_position(side_length,0,-3.0): - print "Successfully reached 1st waypoint" - else: - rospy.logerr("Failed to set position") - return None - if setpoint_local_position(side_length,side_length,-3.0): - print "Successfully reached 2nd waypoint" - else: - rospy.logerr("Failed to set position") - return None - if setpoint_local_position(0,side_length,-3.0): - print "Successfully reached 3rd waypoint" - else: - rospy.logerr("Failed to set position") - return None - if setpoint_local_position(0,0,-3.0): - print "Successfully reached 4th waypoint" - else: - rospy.logerr("Failed to set position") - return None - - # Finally land the drone - rospy.wait_for_service('/'+ global_namespace +'/navigation/land') - try: - handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/land', Land) - resp = handle(False) - except rospy.ServiceException, e: - rospy.logerr("land service call failed %s", e) - return None - print "Landed Successfully. Exiting script." - -if __name__ == "__main__": - if len(sys.argv) == 2: - make_square(sys.argv[1]) - else: - print "This node need side_length of square(float) as an argument" +#!/usr/bin/env python +import sys +import rospy +from core_api.srv import * + +global_namespace = '' + +def setpoint_local_position(lx, ly, lz, yaw=0.0, tolerance= 1.0, async = False, relative= False, yaw_valid= False, body_frame= False): + global global_namespace + rospy.wait_for_service('/'+ global_namespace +'/navigation/position_set') + try: + handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/position_set', PositionSet) + + # building message structure + header_msg = std_msgs.msg.Header(1,rospy.Time(0.0,0.0),'a') + twist = geometry_msgs.msg.Twist(geometry_msgs.msg.Vector3(lx,ly,lz),geometry_msgs.msg.Vector3(0.0,0.0,yaw)) + twiststamped_msg= geometry_msgs.msg.TwistStamped(header_msg, twist) + req_msg = PositionSetRequest(twiststamped_msg, tolerance, async, relative, yaw_valid, body_frame) + resp = handle(req_msg) + return resp.success + except rospy.ServiceException, e: + rospy.logerr("pos set service call failed %s", e) + return None + +def make_square(side_length): + global global_namespace + #first get the global namespace to call the subsequent services + #wait for service to come up + rospy.wait_for_service('/get_global_namespace') + try: + res = rospy.ServiceProxy('/get_global_namespace', ParamGetGlobalNamespace) + op = res() + global_namespace = str(op.param_info.param_value) + except rospy.ServiceException, e: + rospy.logerr("global namespace service not available", e) + #cannot continue without global namespace + return None + + # Next take off to an altitue of 3.0 meters + rospy.wait_for_service('/'+ global_namespace +'/navigation/take_off') + try: + handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/take_off', TakeOff) + resp = handle(takeoff_alt=3.0) + except rospy.ServiceException, e: + rospy.logerr("takeoff service call failed %s", e) + # cannot continue without taking off + return None + print "Took off successfully" + + # Then call the position set service for each edge of a square shaped trajectory + if setpoint_local_position(side_length,0,-3.0): + print "Successfully reached 1st waypoint" + else: + rospy.logerr("Failed to set position") + return None + if setpoint_local_position(side_length,side_length,-3.0): + print "Successfully reached 2nd waypoint" + else: + rospy.logerr("Failed to set position") + return None + if setpoint_local_position(0,side_length,-3.0): + print "Successfully reached 3rd waypoint" + else: + rospy.logerr("Failed to set position") + return None + if setpoint_local_position(0,0,-3.0): + print "Successfully reached 4th waypoint" + else: + rospy.logerr("Failed to set position") + return None + + # Finally land the drone + rospy.wait_for_service('/'+ global_namespace +'/navigation/land') + try: + handle = rospy.ServiceProxy('/'+ global_namespace +'/navigation/land', Land) + resp = handle(False) + except rospy.ServiceException, e: + rospy.logerr("land service call failed %s", e) + return None + print "Landed Successfully. Exiting script." + +if __name__ == "__main__": + if len(sys.argv) == 2: + make_square(sys.argv[1]) + else: + print "This node need side_length of square(float) as an argument" sys.exit(1) \ No newline at end of file