<commit_before># Build package from source

For this tutorial we will assume you are still using ROS and Gazebo from binary packages.
Therefore first follow the instructions from the section *Install dependencies* in the [Install binary packages](../install_binary/readme.md) documentation.

If you want to look into building any of them from source please follow their tutorials ([ROS](http://wiki.ros.org/kinetic/Installation/Source), [Gazebo](http://gazebosim.org/tutorials?tut=install_from_source)).

## Avoid conflicts with system-installed gazebo and related packages

We have seen cases in which the build procedure described here can inadvertently cross-talk with a "regular" installation of gazebo and its support packages in `/usr`. We'll work on preventing that situation, but in the meantime we recommend avoiding it by removing any such packages from your system:
~~~
sudo apt-get remove gazebo* libignition* libsdformat*
~~~
If you experience mysterious segmentation faults, especially on startup, it's likely that the cause is cross-talk with your system-installed packages.

## Get the code

Create a place to work:
~~~
export SRC_SPACE=~/uctf-ardu/src
export INSTALL_SPACE=/opt/sasc-dev
mkdir -p ${SRC_SPACE}
~~~


Create a file `/tmp/gazebo_uctf.rosinstall` with this content:
~~~
- tar:
    local-name: gazebo
    uri: https://bitbucket.org/osrf/gazebo/get/594248df0a49.tar.gz
    version: osrf-gazebo-594248df0a49
- tar:
    local-name: gazebo_models
    uri: https://bitbucket.org/osrf/gazebo_models/get/ca17c6407082.tar.gz
    version: osrf-gazebo_models-ca17c6407082
- git:
    local-name: gazebo_ros_pkgs
    uri: <EMAIL>:ros-simulation/gazebo_ros_pkgs.git
    version: kinetic-devel
- hg:
    local-name: ign-math
    uri: https://bitbucket.org/ignitionrobotics/ign-math
    version: ign-math2
- hg:
    local-name: ign-msgs
    uri: https://bitbucket.org/ignitionrobotics/ign-msgs
    version: default
- hg:
    local-name: ign-tools
    uri: https://bitbucket.org/ignitionrobotics/ign-tools
    version: default
- hg:
    local-name: ign-tools
    uri: https://bitbucket.org/ignitionrobotics/ign-tools
    version: default
- hg:
    local-name: sdformat
    uri: https://bitbucket.org/osrf/sdformat
    version: default
- git:
    local-name: uctf
    uri: <EMAIL>:osrf/uctf
    version: master

~~~

### Payload

The payload is being compiled in a catkin workspace names `ws_payload`.
Clone the following repositories and then build the workspace with `catkin_make`:

* `autonomy-payload`
* `autopilot_bridge`

### Gazebo
If you're developing use this for gazebo instead of the tarball.
~~~
hg:
   local-name: gazebo
   uri: ssh://hg@bitbucket.org/osrf/gazebo
   version: ardupilot
~~~



Check out gazebo and get on the right branch:
~~~
rosinstall ${SRC_SPACE} /tmp/gazebo_uctf.rosinstall
~~~

Fetch package.xml files:
~~~
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_gazebo.xml > ${SRC_SPACE}/gazebo/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_ign-math.xml > ${SRC_SPACE}/ign-math/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_ign-msgs.xml > ${SRC_SPACE}/ign-msgs/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_ign-tools.xml > ${SRC_SPACE}/ign-tools/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_sdformat.xml > ${SRC_SPACE}/sdformat/package.xml
~~~

## Install prerequisites

~~~
. /opt/ros/kinetic/setup.bash
rosdep update
rosdep install --from-path ${SRC_SPACE} --ignore-src
~~~

Add some other dependencies
~~~
sudo apt-get install libxslt1-dev libqwt-dev python-future libignition-transport-dev
~~~

## Build the workspace

~~~
cd ${SRC_SPACE}/..
catkin config --init --extend /opt/ros/kinetic -i ${INSTALL_SPACE} --install --isolate-devel
sudo mkdir -p ${INSTALL_SPACE}
sudo chown -R $USER:$USER ${INSTALL_SPACE}
(cd ${SRC_SPACE}/uctf && git submodule update --init --recursive)
catkin build
ln -s ${SRC_SPACE}/gazebo_models ${INSTALL_SPACE}/share/gazebo_models
~~~

## Checkout Ardupilot

Check out ardupilot from a fork and get on the right branch:
~~~
cd ${SRC_SPACE}/..
git clone https://github.com/tfoote/ardupilot.git -b uctf-dev
cd ardupilot
~~~

### Build ArduPilot SITL

~~~
export INSTALL_SPACE=/opt/sasc-dev
cd ardupilot
./Tools/scripts/install-prereqs-ubuntu.sh
git submodule update --init --recursive
./waf configure --prefix=${INSTALL_SPACE}
./waf
./waf install
~~~

### Install mavproxy

You will need mavproxy installed from pip on your system.
~~~
pip install mavproxy --system --target=${INSTALL_SPACE}/lib/python/site-packages/ --install-option="--install-scripts=${INSTALL_SPACE}/bin"
~~~

### Arbiter

Since the arbiter uses Python 3 we setup a virtual environment:

#### Python 3 venv

```console
cd ${INSTALL_SPACE}
mkdir venv3
pyvenv venv3
. venv3/bin/activate
pip install wheel
pip install image netifaces pyqt5 urllib3
```

Install the following packages into the venv too: 

* acs_lib
* acs_dashboards
* arbiter

#### Patch acs_lib

In order to avoid a dependency on `atcommander` you need to patch the file
`acs_lib/acs_network/acs_network_ground.py` and move the module level import of
`atcommander` to a local scope where it is being used.


## Terminal setup

To use this installation in each terminal instructed to open run the following commands.

~~~
export INSTALL_SPACE=/opt/sasc-dev
. ${INSTALL_SPACE}/setup.bash
. ${INSTALL_SPACE}/share/gazebo-8/setup.sh
. ${INSTALL_SPACE}/share/uctf/setup.sh
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:${INSTALL_SPACE}/share/gazebo_models
~~~

---

Next: [Run an example](../run_example/readme.md).
<commit_msg>acs_lib patch accepted upstream<commit_after># Build package from source

For this tutorial we will assume you are still using ROS and Gazebo from binary packages.
Therefore first follow the instructions from the section *Install dependencies* in the [Install binary packages](../install_binary/readme.md) documentation.

If you want to look into building any of them from source please follow their tutorials ([ROS](http://wiki.ros.org/kinetic/Installation/Source), [Gazebo](http://gazebosim.org/tutorials?tut=install_from_source)).

## Avoid conflicts with system-installed gazebo and related packages

We have seen cases in which the build procedure described here can inadvertently cross-talk with a "regular" installation of gazebo and its support packages in `/usr`. We'll work on preventing that situation, but in the meantime we recommend avoiding it by removing any such packages from your system:
~~~
sudo apt-get remove gazebo* libignition* libsdformat*
~~~
If you experience mysterious segmentation faults, especially on startup, it's likely that the cause is cross-talk with your system-installed packages.

## Get the code

Create a place to work:
~~~
export SRC_SPACE=~/uctf-ardu/src
export INSTALL_SPACE=/opt/sasc-dev
mkdir -p ${SRC_SPACE}
~~~


Create a file `/tmp/gazebo_uctf.rosinstall` with this content:
~~~
- tar:
    local-name: gazebo
    uri: https://bitbucket.org/osrf/gazebo/get/594248df0a49.tar.gz
    version: osrf-gazebo-594248df0a49
- tar:
    local-name: gazebo_models
    uri: https://bitbucket.org/osrf/gazebo_models/get/ca17c6407082.tar.gz
    version: osrf-gazebo_models-ca17c6407082
- git:
    local-name: gazebo_ros_pkgs
    uri: <EMAIL>:ros-simulation/gazebo_ros_pkgs.git
    version: kinetic-devel
- hg:
    local-name: ign-math
    uri: https://bitbucket.org/ignitionrobotics/ign-math
    version: ign-math2
- hg:
    local-name: ign-msgs
    uri: https://bitbucket.org/ignitionrobotics/ign-msgs
    version: default
- hg:
    local-name: ign-tools
    uri: https://bitbucket.org/ignitionrobotics/ign-tools
    version: default
- hg:
    local-name: ign-tools
    uri: https://bitbucket.org/ignitionrobotics/ign-tools
    version: default
- hg:
    local-name: sdformat
    uri: https://bitbucket.org/osrf/sdformat
    version: default
- git:
    local-name: uctf
    uri: <EMAIL>:osrf/uctf
    version: master

~~~

### Payload

The payload is being compiled in a catkin workspace names `ws_payload`.
Clone the following repositories and then build the workspace with `catkin_make`:

* `autonomy-payload`
* `autopilot_bridge`

### Gazebo
If you're developing use this for gazebo instead of the tarball.
~~~
hg:
   local-name: gazebo
   uri: ssh://hg@bitbucket.org/osrf/gazebo
   version: ardupilot
~~~



Check out gazebo and get on the right branch:
~~~
rosinstall ${SRC_SPACE} /tmp/gazebo_uctf.rosinstall
~~~

Fetch package.xml files:
~~~
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_gazebo.xml > ${SRC_SPACE}/gazebo/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_ign-math.xml > ${SRC_SPACE}/ign-math/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_ign-msgs.xml > ${SRC_SPACE}/ign-msgs/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_ign-tools.xml > ${SRC_SPACE}/ign-tools/package.xml
curl https://bitbucket.org/scpeters/unix-stuff/raw/master/package_xml/package_sdformat.xml > ${SRC_SPACE}/sdformat/package.xml
~~~

## Install prerequisites

~~~
. /opt/ros/kinetic/setup.bash
rosdep update
rosdep install --from-path ${SRC_SPACE} --ignore-src
~~~

Add some other dependencies
~~~
sudo apt-get install libxslt1-dev libqwt-dev python-future libignition-transport-dev
~~~

## Build the workspace

~~~
cd ${SRC_SPACE}/..
catkin config --init --extend /opt/ros/kinetic -i ${INSTALL_SPACE} --install --isolate-devel
sudo mkdir -p ${INSTALL_SPACE}
sudo chown -R $USER:$USER ${INSTALL_SPACE}
(cd ${SRC_SPACE}/uctf && git submodule update --init --recursive)
catkin build
ln -s ${SRC_SPACE}/gazebo_models ${INSTALL_SPACE}/share/gazebo_models
~~~

## Checkout Ardupilot

Check out ardupilot from a fork and get on the right branch:
~~~
cd ${SRC_SPACE}/..
git clone https://github.com/tfoote/ardupilot.git -b uctf-dev
cd ardupilot
~~~

### Build ArduPilot SITL

~~~
export INSTALL_SPACE=/opt/sasc-dev
cd ardupilot
./Tools/scripts/install-prereqs-ubuntu.sh
git submodule update --init --recursive
./waf configure --prefix=${INSTALL_SPACE}
./waf
./waf install
~~~

### Install mavproxy

You will need mavproxy installed from pip on your system.
~~~
pip install mavproxy --system --target=${INSTALL_SPACE}/lib/python/site-packages/ --install-option="--install-scripts=${INSTALL_SPACE}/bin"
~~~

### Arbiter

Since the arbiter uses Python 3 we setup a virtual environment:

#### Python 3 venv

```console
cd ${INSTALL_SPACE}
mkdir venv3
pyvenv venv3
. venv3/bin/activate
pip install wheel
pip install image netifaces pyqt5 urllib3
```

Install the following packages into the venv too: 

* acs_lib
* acs_dashboards
* arbiter

## Terminal setup

To use this installation in each terminal instructed to open run the following commands.

~~~
export INSTALL_SPACE=/opt/sasc-dev
. ${INSTALL_SPACE}/setup.bash
. ${INSTALL_SPACE}/share/gazebo-8/setup.sh
. ${INSTALL_SPACE}/share/uctf/setup.sh
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:${INSTALL_SPACE}/share/gazebo_models
~~~

---

Next: [Run an example](../run_example/readme.md).

{'fraction_non_alphanumeric': 0.12091038406827881, 'fraction_numerical': 0.008179231863442389, 'mean_word_length': 4.306132075471698, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 26, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '332660', 'n_tokens_mistral': 4012, 'n_tokens_neox': 3792, 'n_words': 1003}