Skip to main content

Author a Message Set with Flex

The previous tutorials leveraged message sets from existing message sets in Tangram Pro™. But, if a component software interface needs a message set that is currently not included in existing message sets, a Tangram Pro™ user can define their own message set with Flex.

This provides a high level overview for users to add support for their own message sets in Tangram Pro™.

Note: Flex Documentation is coming soon and will be available at Flex Docs. For this tutorial, example Flex code is provided.

You'll learn how to:

  • Add support for your own message set to Tangram Pro™ using the Flex authorship feature.

Step 1: Create Your Own Message Set

  1. First, create a team for this tutorial per Getting Started.

  2. Next, open the Flex view on the side panel.

  3. Create a Package by clicking the New icon button in the upper left. Choose a name and ensure you select your team from the drop down.

  4. Click + Create Package.

  5. Create a new file in the package called "Messages.flex" and paste the following contents:

    flex
    struct LocationLLA {
    latitude : float64;
    longitude : float64;
    altitude : float64;
    }
    message struct WhereAmINow {
    location: LocationLLA;
    }
    message struct WhereShouldIGo {
    waypoint: LocationLLA;
    }
  6. Save the file by clicking the gear button in the upper-right and selecting Save File or alternatively pressing the hot-key Ctrl + S / Cmd + S.

  7. Publish your new package by selecting the ... button next to your package name in the left panel and then choosing Publish Package.

Step 2: Build A Component Based Design Using the New Message Set

For a refresher on building a Component Based Design go to Visualize a Component Based System Design

  1. Go to the component library
  2. Create a new component for your team. Call it "LocationReporter".
  3. Add ports for your new component from your new message set by editing the type, clicking Add Port, and selecting your new Flex package ([YourPackageName]::v1) from the drop down. For this component, add the following messages:
    • WhereAmINow - Out
  4. Add another component called "Autonomy" and give it the following port interface:
    • WhereShouldIGo - Out
  5. Add a third component called "Controller" and give it the following port interface:
    • WhereAmINow - In
    • WhereShouldIGo - In
  6. Finally, add a fourth, "top level" component. No ports are necessary.
  7. Add an implementation for each of the components. Note: To add an implementation, type a name in the Implementation Name text box and click Create Implementation. You can use any name. For generic purposes people often use the name "impl". But, the name can be any you choose.
  8. Open the workspace for the top level component, and add the other 3 components as subcomponents.
  9. Connect the components together (In to Out).

Step 3: Generate a CSI

For a refresher in generating a Component Software Interface go to Generate Code with Workflows

  1. Open the workspace to the LocationReporter component's implementation. There will not be any subcomponents on this view.
  2. Create a new workflow. Call it Code Gen.
  3. Add the Code Gen 3.0 plugin as the only step to run in the workflow. Ensure that its output language is cpp and its transport library is ZeroMQ.
  4. Run the workflow to generate a CSI from your Flex module.
  5. Download the generated code. Extract and open the package.
  6. Navigate to the code-gen-3/include folder. You should see a file called WhereAmINow.hpp. This file was generated as a result of your defining it as a message in your .flex file and including that message in the interface for LocationReporter. Note that WhereShouldIGo is NOT included because even though you defined it in your .flex file, it was not in the interface specification of the LocationReporter component.
  7. Open WhereAmINow.hpp. Take a look at the file and see that there are C++ functions in there to getLocation() and setLocation() that use the type LocationLLA. Note that these were defined from your the WhereAmINow message struct in your Flex file.
  8. Open LocationLLA.hpp. Take a look at the file and see that there are private class variables for latitude, longitude, and altitude. Note that these were defined in your LocationLLA struct in your Flex file.

Further Exploration

  • Enter a syntactic error in the Flex editor, and see that it identifies the error.
  • Make a change to your Flex file, such as adding a field to a message. Publish the changed Flex specification, update a component interface to use the new version, and generate a CSI. See how the changes you made to Flex affect the resulting interface code.

Cheers!

By completing this tutorial you learned how to:

  • Use Tangram Pro™ to define and use custom message definitions to build component-based systems.
  • Generate code with these user-defined Flex packages.
    note

    Check out Discuss, our Tangram Flex community and find out more about Flex Authorship in Tangram Pro™.