collision-avoidance-library  Quickstart

##元記事
https://github.com/intel/collision-avoidance-library/wiki/Quickstart#running-the-simulation

##Quickstart
Murilo Belluzzo edited this page on Mar 16 · 13 revisions

##Quickstart Guide
This is a quick guide to get the source, compile all the features and run a simulation. Our simulation environment were validated with the following revisions/releases:

|Software|Version|
|--------|--------------|
|Gazebo	 |8.0.0         |
|~~PX4~~|~~1.6.0-rc1~~   |
|ArduCopter|3.4         |
|librealsense| v.1.12.1 |

**Install Pre-Requisites**
**Install Gazebo**
**Install socat**
`sudo apt-get install socat`

The project uses Gazebo as simulation environment, so it needs to be installed if that feature is desired. Check your distro for available packages for gazebo. If none is available, the last stable version can be obtained at gazebosim.org.

Besides Gazebo itself, our test infrastructure depends on two additional plugins in order to execute the simulation and automated testing: Gazebo Sitl and Gazebo Realsense, so thoses will have to be properly installed as well. Please, follow the instructions of each project on how to do it.

###Install Autopilot
The project supports Ardupilot and PX4 as autopilots. For this quick guide we will be using Ardupilot. The project is available at the project's github page. Check Ardupilot's project wiki for instructions on how to build and install.

###Build and Install
Detailed instructions on how to build and install the project can be found in our README. To be able to run simulations and automated tests, its necessary to enable Tools and Gazebo support during compiling, so make sure that -DWITH_TOOLS=ON -DWITH_GAZEBO=ON is passed to cmake.

###Running Simulations
The project provides a script to automate the process of running the autopilot, gazebo and running coav-control plus linking it all together. The script is called coav-sim.sh and can be found in the testbed directory.

Arguments passed to coav-sim.sh will be provided to coav-control and the following table describes some environment variables that can be use to customize the execution.


|Environment Variable|	Description|
|--------------------|-------------|
|AUTOPILOT|	Defines which autopilot to use. Valid values are AP_APM and AP_PX4. Default is AP_PX4.|
|APM_DIR|	Prefix path to use to call 'arducopter' when AP_APM is used. Default is empty.|
|PX4_DIR|	Prefix path to use to run PX4 simulation. Default is $HOME/px4/Firmware.|
|WORLD|	File name of the Gazebo environment (sdf file) that will be used in the simulation. Default is 'simple_obstacle.sdf'.|
|LOGDIR               |Path to where to save log files. Default is script path/logs.|


The following command will start a simulation using Gazebo RealSense as sensor, Simple Detector as detector, Stop Avoidance as avoidance strategy and Ardupilot as autopilot:

|avoidance_algorithm|   
|-------------------|
|QC_SHIFT_AVOIDANCE| 
|QC_STOP|
|QC_VFF |


**QC_STOP_AVOIDANCEはavoidance_algorithmにないのでエラーになる** 
~~AUTOPILOT=AP_APM APM_DIR=~/git/AC3.4/ardupilot/build/sitl/bin
./coav-sim.sh -a QC_STOP_AVOIDANCE -d DI_POLAR_HIST -s ST_GAZEBO_REALSENSE~~


`AUTOPILOT=AP_APM APM_DIR=~/git/AC3.4/ardupilot/build/sitl/bin LOGDIR=~/ VERBOSE_LEVEL=1 
./coav-sim.sh -a QC_STOP  -d DI_POLAR_HIST -s ST_GAZEBO_REALSENSE`

**arducopterが下記のログを出力**
>invalid param FRAME_TYPE in defaults file
>AP_Param: Invalid param in defaults file

**~/git/collision-avoidance-library/testbed/copter.parmの
FRAME_TYPEとFRAME_CLASSが原因だった。
FRAME_TYPEをFRAMEに修正、FRAME_CLASSを削除**


**coav-controlとArduCopterがTCP PORT 5762で通信し衝突回避のsimutationを実行するらしいのだが、
Connection refusedされてしまう。**
*FRAME_TYPEをFRAMEに修正、FRAME_CLASSを削除ことでこれも解決した
ArduCopterのSITLがパラメーターエラーでうまく起動できなかったのが原因らしい*

>2017/12/27 15:49:03 socat[3177] E connect(5, AF=2 127.0.0.1:5762, 16): Connection refused

**こんどは、gzserver(gazebo server)がエラーを吐く**
*このエラーは、gzserverがrealsenseの初期化を始めた直後にgzclientを起動すれば出力されない。*
>gzserver: /build/ogre-1.9-mqY1wq/ogre-1.9-1.9.0+dfsg1/OgreMain/include/OgreAxisAlignedBox.h:252: void >Ogre::AxisAlignedBox::setExtents(const Ogre::Vector3&, const Ogre::Vector3&): Assertion `(min.x <= max.x >&& min.y <= max.y && min.z <= max.z) && "The minimum corner of the box must be less than or equal to >maximum corner"' failed.



The simulation will start only gazebo server. To see the simulation in Gazebo's graphical interface, open a separate terminal an run the command:

`gzclient`
**こんな感じでgazeboの中にrealsenseを搭載したquadが現れるが、下記にメッセージが出力される。
~~これはおそらく、librealsense v2をインストールすれば出力されなくなると思う。~~
**collision-avoidance-libraryはlibrealsense v1 じゃないとダメ。**
*このワーニングは無視してOK*
>[Wrn] [msgs.cc:1832] Conversion of sensor type[depth] not supported.
>[Wrn] [msgs.cc:1832] Conversion of sensor type[depth] not supported.

![Screenshot from 2017-12-27 15-49-56.png](https://qiita-image-store.s3.amazonaws.com/0/148248/2affdee1-c25c-4a64-b217-4777d0b47dfe.png)

###動画(youtube)
[![動画] (http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=pdIVBG1NL5c)