Skip to main content

Implement Generated Code

Well, you've generated some code with Tangram Pro™. So, now what? How about taking the Component Software Interface (CSI) for a test drive? After all, the whole point of the CSI is to quickly connect components with a reliable, reusable interface so that you can focus on developing your applications rather than managing the interactions between them.

You'll learn how to:

  • Describe a CSI
  • Create a local testing environment
  • Leverage your CSI generated by Tangram Pro™
  • Run an end-to-end test of your CSI
  • Visualize the program's behavior with OpenAMASE

What is a CSI?

A CSI is a lot like an application programming interface (API) for an embedded system component. To be sure, there are differences. Rather than thinking of web servers and enterprise applications, you might think of navigation, autonomy, and sensor components on a UAV. The CSI is all the code needed to support the sending and receiving of the messages that you've selected in your design (such as the OpenUxAS LMCP messages we specified in the previous tutorials).

When you run a workflow for a component, Tangram Pro™ does all the heavy lifting for you. The component interface you've defined, using simple dropdown menu selections, is output into robust C++ (or Rust) source code. This ready-to-run code not only contains objects that represent your selected messages, but also the appropriate setter and getter functions for each message, transport libraries (ZeroMQ, ActiveMQ, RabbitMQ, or Kafka), serialization/deserialization libraries, and a variety of test code.

Packaging all of this up into a set of executables means you can spend your development time on the behavior of the components themselves, rather than the connections between them.

Step 1: Gather Code

Download UAS Communications CSI

  1. Download the generated CSI code from the previous tutorial Generate Code with Workflows. You should have a folder called code-gen.

Download UAS Communications Component

To test the UAS Communications CSI, we'll also need to download a simple C++ application to handle sending serialized LMCP messages to OpenAMASE.

  1. Go to our Tangram Flex uas-communication-component repository on GitHub
  2. Click to green Code button, Download ZIP, and extract the ZIP file.
  3. Update the name of the extracted folder to uas-communication-component

Move Folders

  1. Move the code-gen-3 folder into the uas-communication-component folder.
  2. Now create a new folder that you'll share with the virtual machine. Let's name it UAS Resources.
  3. Move the uas-communication-component folder into it the UAS Resources.

The result should be a folder structure similar to this:

- UAS Resources
- uas-communication-component
- code-gen-3

Now that we have our code together, let's setup a testing environment.

Step 2: Create a Testing Environment for your CSI

Next, you are going to create an Ubuntu 20.04 LTS virtual machine using VirtualBox.

note

If you are already using a Linux machine that is running Ubuntu, you many want to skip to Step 4. Before you do, be sure to download these files:

To download VirtualBox

  1. Navigate to the VirtualBox Downloads page
  2. Click the appropriate download for your host machine, either Windows hosts or OS X hosts
  3. Click Open to open the downloaded file and launch the VirtualBox installer
  4. Double Click VirtualBox.pkg and follow the prompts to complete VirtualBox installation
  5. Launch the VirtualBox application

With VirtualBox installed you are nearly ready to create the Ubuntu 20.04 VM. But let's make sure you have an Ubuntu image with long term support (LTS).

To download Ubuntu 20.04 LTS

  1. Navigate to the Ubuntu Downloads page
  2. Click the green Download button to download the Ubuntu 20.04 LTS image

Great! Now let's head back to VirtualBox and set up that VM to use as a testing environment.

tip

As you set up your VM in VirtualBox, use the name Tangram CSI Test to mirror the remainder of the instructions below.

To create a Ubuntu 20.04 VM with VirtualBox on Mac OS

If your host machine is using Mac OS, please refer to this video for step by step instructions:

To create a Ubuntu 20.04 VM with VirtualBox on Windows

If your host machine is using Windows, please refer to this video for step by step instructions:

Whew! You are almost there. If you are unfamiliar with setting up an Ubuntu image on a VM that may have felt like a lot of steps to get your testing environment created. Hopefully, it was a smooth process. Now you should see your Tangram CSI Test VM listed in the OracleVMVirtualBox Manager.

tip

Be sure to add the VirtualBox Guest Additions Image. If you missed it in the videos, installing the VirtualBox Guest Additions will allow you to go full screen with your VM while retaining resolution and create shared folders. To add VirtualBox Guest Additions, run this command from the VM terminal:

sudo apt install build-essential dkms linux-headers-$(uname -r)

Then,

  1. In the VirtualBox menu click Devices
  2. Click Insert Guest Additions CD Image...
  3. Restart the Tangram CSI Test VM

Step 3: Create Shared Folder

With your Tangram CSI Test VM up and running, it will be helpful to configure some important settings that will be used later. Creating shared folders will allow the VM to recognize folders from your host machine to be used by the Tangram CSI Test VM. Let's add a shared folder!

Add Shared Folder

  1. In the OracleVMVirtualBox Manager select Tangram CSI Test
  2. Click the Settings icon
  3. Click the Shared Folders icon
  4. Click the Add new shared folder icon on the far right
  5. Click the Folder Path dropdown mend and select Other...
  6. Select your UAS Resources folder and click Open
  7. Select Auto-mount
  8. Click OK
  9. Click OK again

Copy Resources

  1. Launch the VM
  2. Open Files
  3. Click on the mounted folder sf_UAS_Resources. If you don't see it, try restarting your VM.
  4. Copy the uas-communication-component folder
  5. Click Home
  6. Paste the uas-communication-component folder into Home

Step 4: Add Prerequisites

There are a few tools your VM will need to set up your testing environment and successfully run the end to end test.

To add the necessary prerequisites to your VM

  1. Open Terminal in the Tangram Test CSI VM
  1. From the VM Terminal run the following command to install the first prerequisite:
sudo apt-get install ant

Following the example above, run the following commands to instal the other prerequisites.

sudo apt-get install openjdk-11-jdk
sudo apt-get install git
sudo adduser $USER vboxsf

Step 5: Clone and build the OpenAMASE repository

With the prerequisites in place, the next step is to clone the OpenAMASE repository and verify that the application will build.

What is OpenAMASE?

Developed by the Air Force Research Laboratory, Aerospace System Directorate, Power and Control Division, OpenAMASE is "a simulation toolset for the analysis and demonstration of aircraft automation and autonomy. OpenAMASE includes the necessary components to create scenarios, simulate aircraft with basic EO/IR cameras, and interact with control algorithms to command aircraft in a scenario."

This means it is an accessible tool, ideal for the purpose of running a end-to-end test of your Tangram Pro™ CSI. Using OpenAMASE will allow you to see a simulated UAV communicating the AirVehicleState and AirVehicleConfiguration LMCP messages to two other simulated UAVs.

note

For a full description of OpenAMASE, check out the OpenAMASE README.md.

To clone and build the OpenAMASE repository

  1. In the Tangram CSI Test VM terminal run the following command to clone the OpenAMASE repository
git clone https://github.com/afrl-rq/OpenAMASE.git && cd OpenAMASE
  1. Change directories with the following command in the VM terminal
cd OpenAMASE
  1. Build the the code with the following command in the VM terminal
ant jar
  1. Now, verify that the OpenAMASE application will run with the following commands in the VM terminal
cd run/linux
sh Common.sh "--config" "config/amase"

At this point OpenAMASE will build and you'll see the application running.

Step 6: Select an OpenAMASE scenario

Now let's take advantage of OpenUxAS which contains an example scenario that is much more interesting than the default scenarios in OpenAMASE.

Clone OpenUxAS

  1. Open a new Terminal tab
  2. Change directory with the following command
cd ~
  1. Clone the OpenUxAS repository
git clone https://github.com/afrl-rq/OpenUxAS.git

Select a Scenario

  1. Within OpenAMASE, click File and select Open Scenario
  2. Click the dropdown menu at the top, next to the listed file path
  3. Select /home/< virtual machine user name>
  4. Double click OpenUxAS/
  5. Double click examples/
  6. Double click 02_Example_WaterwaySearch
  7. In the Files menu on the right, select Scenario_WaterwaySearch
  8. Click OK
  9. Click the play button to run the scenario

A much better scenario don't you think? UAV 400 and UAV 500 are hovering in Nav Mode Loiter at different altitudes and conducting a search. But where is the Tangram UAV?

Step 7: Run an end-to-end test of your Tangram Pro™ CSI

Now you are going to leverage your CSI to test whether the UAS Communication Component is able to send the AirVehicleState and AirVehicleConfiguration messages.

To run the UAS Communication Component

  1. Return to Terminal
  2. Open a new Terminal tab
  3. Change directories with the following command:
cd ~/uas-communication-component
  1. Build the lmcp_sender app with the following command:
make
  1. Run the lmcp_sender app with the following command:
./lmcp_sender

At this point, you should see the starting, serializing, and sending of the AirVehicleState and AirVehicleConfiguration messages to by the UAS Communication Component in the terminal window. Let's take a look at this in OpenAMASE.

To visualize the behavior of the system with OpenAMASE

  1. With the application still running, click the OpenAMASE icon in the VM sidebar on the left
  2. If the OpenAMASE scenario timed out, click the play button to restart it

And there it is! The Tangram UAV leveraging the CSI you generated with Tangram Pro™ to send the required AirVehicleConfiguration and AirVehicleState messages.

Cheers!

By completing this tutorial, you've learned to implement the CSI generated by Tangram Pro™ in a local testing environment!

Check out what you accomplished:

  • Created a local testing environment with VirtualBox and Ubuntu 20.04 LTS
  • Leveraged the CSI generated by Tangram Pro™ to communicate the specified messages
  • Ran an end to end test of the CSI
  • Visualized the behavior of your simple system using OpenAMASE

If you want to know more about CSIs in Tangram Pro™, take a look at our blog posts.

note

Check out Discuss, our Tangram Flex community and find out more about generating CSIs with a CSIP.