Skip to content

Generating Autocode for Flight

Taylor Reynolds edited this page May 15, 2021 · 6 revisions

The instructions are what I use to generating autocode for SOC-i flight software. There are some specific code generation and simulation settings that are important to set properly. Make sure that you've configured the main Simulink build options from this link before starting these instructions.

Code Generation Parameters

In Simulink's navigation bar, click on Code -> C/C++ Code -> Code Generation Options... to open up the configuration parameters for the autocode. The following subsections each correspond to one of the tabs on the left-hand pane. I'll include as many screenshots as I can.

Code Generation

  • Make sure the Language is set to C.
  • Check the Package code and artifacts box. Set the Zip file name: to soci_fsw_build

opts_code_generation

Report

  • Check the following boxes: Create code generation report, Open report automatically, Generate model Web view, and Static code metrics.

Custom Code

You will need to include some custom header and source files to build the autocode with the SOAR payload. You will need to use absolute paths here that are specific to your machine.

Custom Headers

Under Additional build information -> Include directories put the following folder reference

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/include

autocode_include

Custom Source Files

Under Additional build information -> Source files put the following lines

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_1.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_2.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_aat.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_control.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_defaults.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_dump.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_global.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_info.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_order.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_post_tree.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_postorder.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_preprocess.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/amd_valid.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/cone.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/ctrlc.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/ecos.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/equil.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/kkt.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/ldl.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/matlab_main.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/preproc.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/runecos.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/spla.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/splamm.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/timer.c

<absolute_path_to_repo>/soci-gnc/Lib/FSW/soar/include/ecos/src/wright_omega.c

autocode_source

Code Placement

  • Set the Data definition to be Data defined in a single separate source file
  • Set the Data definition filename to be soci_global.c
  • Set the Data declaration to be Data declared in a single separate header file
  • Set the Data declaration filename to be soci_global.h

opts_code_placement

Code Generation Steps

Here are the steps that I take to generate autocode.

Setup the Sim

Make sure your current Matlab path is the Src folder in the repository.

  1. Run the Sim_init.m script.
  2. Click on the FSW_Lib in the main Simulink file that opens up.
  3. In the lower-left corner, click on the grey lock icon. When the yellow bar pops up, click on Disable this link.

autocode_fsw_unlock

Generating Autocode

  1. Click on Code -> C/C++ Code -> Embedded Coder Quick Start. When the popup opens, click Next
  2. Choose Subsystem, and then click on FSW_Lib and click Next.
  3. Make sure things are set to C code and Single instance. Click Next.
  4. Click Next and let Simulink figure out the number of sample times. This may take a minute, but you should see it come back with the following image:

autocode_sample_rates

  1. On the next screen, set Device Vendor to be NXP and Device Type to Cortex-M4.
  2. Choose Execution efficiency as the priority. Click Next.
  3. You should see no suggested parameter changes on the next screen. If you do see a suggested change, you may not have configured Simulink properly -- or I may have forgotten to include something here. You will need to accept any suggested parameter changes to move ahead. Click Next.
  4. This will run the code generation tool, and will take some time. When it's done, you'll see a report open up automatically.

The generated code will be placed into the Build/soci_fsw_build folder, and will also generate a soci_fsw_build.zip folder.

Debugging Issues

If you get some build failures, try these steps:

  1. Delete the Build/slprj folder and try again.
  2. Reach out to Taylor with screen shots of the error messages that you're seeing.