Wiki » History » Revision 42

Revision 41 (Martin Jacquet, 2020-10-27 18:06) → Revision 42/49 (Martin Jacquet, 2020-10-27 18:08)

qh1. Perceptive and torque-control NMPC wiki 

 h2. I - Software Overview 

 h3. I.1. Openrobots 

 Collections of all the open-source software used at LAAS. You can find more details in "Openrobots Wiki-Homepage": 

 h3. I-2. Robotpkg 

 "Robotpkg": is a packaging system for installing robotics software developed by the robotic community. 
 We will use robotpkg to install the required modules for the simulations (state estimation, gazebo interface...) as well as third-party dependencies (qpOases). 

 h3. I-3. GenoM 

 GenoM is a generator of modules, designed to be middleware independant, i.e. the same module can be compiled for, e.g., ROS, YARP, or Pocolibs, without any modification. 
 This allows a great code re-usability and to abstract the user from any specific choice of a middleware. 
 Originally GenoM has been developed tightly with Pocolibs, then from version 3, aka GenoM3, ROS templates has been provided. 
 Another specificity of GenoM is the interaction with and between components. 
 Each component is started independantly like a linux executable (within a roscore, for ROS, or a h2 intance, for Pocolibs), then the connection between ports (or topics) is made using a supervisor, "Genomix":, either with "Matlab": or "TCL":  

 h3. I-4. Pocolibs 

 "Pocolibs": is a middleware, like ROS. 
 It aims at being lighter and faster than ROS, when running on a single machine, thanks to the exploitation of shared memory. ROS, on the other hand, uses a network layer for sending messages between nodes, this leads to greater delays and loss of performances. 

 h3. I-5. TeleKyb 

 The "TeleKyb": software platform provides the aerial-robotic oriented softwares developped at LAAS-CNRS. 
 In particular, we will use: 
 * "mrsim":, a Multi-Robot SIMulator. It is design to be a transparent interface w.r.t. the real aerial vehicles used in LAAS-CNRS. It makes the transition between simulation and experiment transparent, from the software point of view. 
 * "pom":, a UKF-based state estimator merging state feedback for different sources (e.g. mocap + IMU) 
 * "optitrack":,, to export the motion capture data to the genom software stack 
 * "rotorcraft":, the low-level interface, with either the simulated or real platform 
 * "nhfc":, near-hovering flight controller, used for unmodeled take-off and post-failure recoverues 
 * "maneuver":, a global trajectory planner, providing position and attitude (as quaternions) as well as first and second derivatives. It implement take-off and waypoint-to-waypoint motions. A joystick-based velocity control is implemented, but not used in this project. 

 h3. I-6. Gazebo 

 To simulate the platform, we use the "Gazebo": simulator. To interface it with the genom software stack, we use two dedicated components: 
 * "mrsim-gazebo": a plugin to interface the simulated multi-rotor with the genom components (in place of mrsim) 
 * "optitrack-gazebo": emulates the optitrack network interface to publish the model poses 
 The installation procedure for Gazebo can be found at 

 h2. II - Installation procedure 

 This section is a tutorial on how to install the software architecture to run the simulations. 
 Note that everything has been tested on Ubuntu 18.04 since it is the OS used by the LAAS-CNRS robotic platform. It should work seamlessly on other OS, but there is no guarantee. 


 h3. II-0. Clone the Perceptive and torque-control NMPC repository 

 Clone the repo associated to this project. Its root will act as the devel folder for the following. 
 <pre><code class="shell"> 
 git clone git:// 
 cd ./perceptive-torque-nmpc/ 
 To simplify the installation, we provide some environment variables in the file. 
 In order to run all the installed executables, we need to setup the path to the newly created folders. 
 We provide a script that exports all the required variables. 
 */!\* the source has as to be called in the repository root since it uses the @pwd@ command to export the other paths. 
 <pre><code class="shell"> 


 h3. II-1. Setup robotpkg 

 (Steps taken from 

 h4. 1. Clone the robotpkg lastest release: 

 <pre><code class="shell"> 
 git clone git:// 

 h4. 2. Check that the @openrobots/@ folder exists in the repository root, and update the environement variables accordingly if you didn't source the file: 

 <pre><code class="shell"> 
 export ROBOTPKG_BASE=`pwd`/openrobots 

 h4. 3. Install robotpkg 

 <pre><code class="shell"> 
 cd robotpkg/bootstrap 
 ./bootstrap --prefix=$ROBOTPKG_BASE 

 h4. 4. Install the required components and there dependencies 

 The installation can be done 'manually' by navigating to the desired folder in @./robotpkg/@ and install with @make update@; but we will simplify the process using a _set_. 
 To do so, we need to edit the config file: @$ROBOTPKG_BASE/etc/robotpkg.conf@. Add the following at the end of the file: 
 <pre><code class="shell"> 
 PKG_OPTIONS.%-genom3 = \ 
         codels \ 
         pocolibs-server \ 

 PKGSET.mpcset = \ 
     sysutils/arduio-genom3 \ 
     architecture/genom3 \ 
     architecture/genom3-pocolibs \ 
     robots/rotorcraft-genom3 \ 
     localization/pom-genom3 \ 
     localization/optitrack-genom3 \ 
     motion/nhfc-genom3 \ 
     path/libkdtp \ 
     optimization/qpoases \ 
     net/genomix \ 
     supervision/matlab-genomix \ 
     supervision/tcl-genomix \ 
     shell/eltclsh \ 
     simulation/mrsim-genom3 \ 
     simulation/mrsim-gazebo \ 
     simulation/libmrsim \ 

 PREFER.lapack = robotpkg 
 PREFIX.matlab = <path/to/Matlab> 
 The last line need to point to the Matlab root folder in the system (e.g. @/opt/Matlab@). 
 It is recommanded to use Matlab for the proposed simulations since the syntax is more intuitive and comprehensible for the user to modify them. However, we also provide all the launch files in tcl, as well as the environment to run them (@shell/eltclsh@ in the above list is a custom tcl script shell). 
 If Matlab is not installed on the system, remove the lines @supervision/matlab-genomix \@ and @PREFIX.matlab = <path/to/Matlab>@ from the above list. 
 Also, all the above is meant for using Pocolibs, not ROS. Futur version of this tutorial might come to use the ROS install. 
 Now return to the robotpkg folder and install all the set: 
 <pre><code class="shell"> 
 cd robotpkg 
 make update-mpcset 
 During the installation, some required dependencies need to be install with the usual package manager (e.g. @apt@ on Ubuntu). When the install stops, install the required packages and rerun the above command. 

 h4. 5. Matlab configuration 

 The last step is to update Matlab path to use the custom libraries, if relevant. 
 Add the following paths in the Matlab path window: 
 <pre><code class="shell"> 
 (change </path/to/openrobots> to the value of @$ROBOTPKG_BASE@) 

 h3. II-2. Install custom components 

 h4. List of the components 

 The @src/@ folder contains some additional components, in particular: 
 * *vision-idl*: the type declaration regarding the camera modules 
 * *camgazebo-genom3*: read the data from the gazebo inate cameras, via the gazebo API 
 * *camviz-genom3*: record and/or display the images from a camera 
 * *arucotag-genom3*: detect and filter (EKF-based) the ArUco markers/tags 
 * *maneuver-genom3*: custom version of maneuver (already mentionned) that publishes the reference trajectory for a specified receding horizon 
 * *uavmpc-genom3*: the NMPC controller presented in the paper 

 h4. Install the extra components 

 Since it they are not considered 'stable' as the one provided in robotpkg, we rather install them in a devel folder. 
 Go to the project root, check that the devel folder exists, export the path if you didn't source the Then go to the sources folder: 
 <pre><code class="shell"> 
 export DEVEL_BASE=`pwd`/devel 
 cd src/ 
 For the manual installation, @asciidoctor@ is needed. It can be installed using @apt@ or any package manager. 
 Each component here has to be installed manually, using @autoconf@. To do so, proceed as follow: 
 <pre><code class="shell"> 
 cd src/<component>/ 
 mkdir build 
 cd build 
 ../configure --prefix=$DEVEL_BASE --with-templates=pocolibs/client/c,pocolibs/server 
 make install 
 The component @vision-idl@ has to be installed first since it defines some type headers used by others. 
 The installation of the main component, @uavmpc-genom3@, is described in the next subection. 

 h4. Install the MPC controller 

 Before installing the MPC controller, we have to generate the @C@ sources corresponding to the desired model. 
 To do so, go to the @model_generation/@ folder: 
 <pre><code class="shell"> 
 cd src/uavmpc-genom3/model_generation 
 There is a file there, explaining the requirements. 
 In short, the model sources are exported to @C@ using @CasADi@ in @python3@. 
 @python3@ along with @NumPy@, @SciPy@ and @CasADi@    are required, and easily installable on most Linux distributions (e.g. with @apt@ and @pip3@). 
 Then, the sources are generated using: 
 <pre><code class="shell"> 
 python3 <quad or hexa> 
 Then install the component as explained before, but add the following flags to the @configure@ command: 
 <pre><code class="shell"> 
 ../configure --prefix=$DEVEL_BASE --with-templates=pocolibs/client/c,pocolibs/server CFLAGS='-Wall -O3 -march=native -mfpmath=sse' CXXFLAGS='-std=c++14 -Wall -O3 -march=native -mfpmath=sse' CPPFLAGS='-I$ROBOTPKG_BASE/include' LDFLAGS='-L$ROBOTPKG_BASE/lib -Wl,-R$ROBOTPKG_BASE/lib' 

 h3. II-3. Setup the environment 

 In order to run all the installed executables, we need to setup the path to the newly created folders. 
 All the required variables are exported in the file. 

 h2. III - Running the simulation 

 We @ws/@ folder contains all the material to run a basic simulation with the NMPC. 
 In a terminal, launch the script. It starts all the genom components, in background. It is used as a console since it displays warnings or error during runtime. 
 In another terminal, start gazebo with one of the world file provided. 
 Finally, run @matlab@ or @eltclsh@ and go to the relevant subsection below. 

 h3. III.1. Running the simulations with Matlab 

 Change the flag at the top of the script to use either the quadrotor or the hexarotor. 
 Change also the variable @devel_path@ to the value of @$DEVEL_BASE@ 
 The provided scripts are organised as follow 
 * The two @param_*.m@ scripts provide the parameters for either a standard colinear quadrotor (denoted *qr*) and a tilted-propeller hexarotor (denoted *hr*). 
 * The @init.m@ script that connects all the components together and call the initialization services for all provided components. 
 * The @traj_*.m@ that runs the specific trajectories for a specific scenario. 
 Launch the script then press enter between each step to proceed to the next one. The evolution can be watched in gazebo and in the console terminal in parallel. 

 h3. III.2. Running the simulations with tcl 

 _The TCL scripts are not included yet_ 
 _I will wait for the the current matlab scripts to be tested by other users, include potential feedback, then finalize the tcl versions_ 
 The tcl scripts are called from the @eltclsh@ shell environment. 
 In order to run the script and keep the variables in the environment, use the @source@ command. 
 The script architecture is the same as the matlab one. Change the flag and @devel_path@ in the init.tcl script, then: 
 <pre><code class="tcl"> 
 source init.tcl 
 source traj_<name_name>.tcl 

 h3. III.3. List of the provided trajectories 

 * @traj_mpc@ runs a flight using the nmpc without any perceptive constraint, reaching successive waypoints. 
 * @traj_track@ runs a flight using the nmpc with a couple of perceptive constraints, again reaching successive waypoints. 
 It corresponds to the experiment presented in section *V-B* in the paper. 
 * @traj_follow@ runs a flight where we follow a _target_ quadrotor equipped with a marker. The NMPC-controlled UAV needs to stay on top of it, while the _target_ quadrotor is given successive waypoints. 
 It corresponds to the experiment presented in Section *V-C* in the paper. 
 In order to perform the exact simulation performed in Section *V-E* of the paper, one need first to uncomment the tracking of the second tag in the file and recompile @uavmpc-genom3@. 
 Then, modify the parameters in @init.m@: @z_desired = 2;@ and @target_compliant = 0;@