Skip to content

Run the Project

Ian McElhenny edited this page Feb 6, 2021 · 17 revisions

Run the System Requirements

This setup relies on a few things, due to the docker networking constraints on windows we need to setup a mavlink-router to help route the mavlink messages to and from the drone to the ground station and the agent code. Additionally we are going to setup for SITL mode, so this means launching a PX4 SITL. Lastly we will need to have the base station running standalone (or the agent) depending on which one is to be debugged in Clion. These steps are shown below. Order does matter.

Spin up mavlink-router

Back in the powershell we need to open a dedicated window for the mavlink-router executable. This will not create a new container, but rather will give you a new bash-prompt into the already created container.

  1. In powershell, run .\run_dev.sh <path to repo-root>.
  2. In the new git-bash window execute the rest of the commands.
  3. Find the docker host IP address: getent hosts host.docker.internal | awk '{ print $1 }'
  4. Execute mavlink-routerd -e <docker host ip address>:14550 127.0.0.1:14550

At this point the mavlink router is running. QGround control and the agent (once the sitl is turned on below) will be able to connect to the autopilot. Note that the router can some times crash when disconnects occur, just simply run the 4th command above again.

Spin up PX4 Sitl

Like the container, the first time this command is ran it can take a while. However subsequent executions should be quick.

  1. Open a new bash window. See the mavlink-router setup for instructions on opening a new bash prompt.
  2. Navigate to the PX4 repo, which is downloaded by default in the docker build process, via: cd ~/px4
  3. Next execute the sitl, this can be ran in headless mode as well: make px4_sitl gazebo_iris_opt_flow or HEADLESS=1 make px4_sitl gazebo_iris_opt_flow

Now we have the mavlink-router and the sitl running. Next we can begin to setup our code base and get it connected to this system as well!

Build and Run Our Project Components

Our system is made up of 3 component types: Agent(s), a Base Station, and Controller(s). We must first turn on the base station before any other components can be started. Below shows one option: run the base station, debug the agent. Of course these can be flipped around or you can choose to just run both (external to clion after building each component).

The Base Staion

This section will describe building a base station node.

  1. Open a new bash window. See the mavlink-router setup for instructions on opening a new bash prompt.
  2. Open clion clion&.

Now we can modify the project source to prepare for a Base station build.

At the top of the main.cpp we have a #define called BASE_MODE this, when set to 1, will configure the project to build a base station executable. See below:

As you can see this is configured with 0 so it will actually build an Agent node. Change to 1 and build, you may also need to reset/reload the cmake first. These a re shown below:

Reload Cmake

Build the Project

Once the build completes, we can copy out the executable for manual execution.

  1. In the bash prompt execute the following: cd ~/ && cp ~/hovergames2/code/bin/HoverGames2 ./.
  2. Now we can execute the base station with the following command: cd ~/ && ./HoverGames2.

The Agent

Now we can setup clion to build the agent.

  1. Simply change the #define from #define BASE_MODE 1 to #define BASE_MODE 0.
  2. Build the project, like we did above.

Now that we have a built project, either copy out the executable (with a name change so it doesnt override the base station executable) or simply press the debug/run icon in the upper right hand corner.

The Controller

Lastly we want to run a version of the controller. We have several versions, as listed below:

  • manual_controller.py - a CLI interface that allows the user to send position commands to the drone manually typed in.
  • User-emulated controller - a arrow interface that runs the full scene simulation and allows a user to directly control the position of the Agent with arrow key commands
  • Rule based controller - The full scene simulation with a rule based controller (fully autonomous)
  • Reinforcement Learning Controller - The full scene simulation running a trained RL model to decide where the Agent should move to (fully autonomous).

The below sections will describe how to setup and use each controller listed above.

Manual Controller - CLI

Like mentioned above, this controller directly exercises the python controller interface by allowing the user to set a position command, and then turn on the repetitive sending of said command to the Agent via the base station.

Clone this wiki locally