Show/Hide Toolbars

HOMER Pro 3.16

HOMER Logo


HOMER calls MatlabUpdateState once to get the power output from the custom component for all time steps.

[new_time_series_output,user_defined_errors] = MatlabUpdateState(custom_component)

MatlabUpdateState has one input variable:

custom_component: This MATLAB struct contains information about the Custom Component, such as the custom resources it uses, whether it is an AC or DC component, the rated capacity, etc.

The following table contains examples of commands you might use in your MatlabUpdateState function.

Using the Custom_Component

Action

Command

Description

Check if the Component is on the AC or DC bus

simulation_parameters.custom_components(i).is_AC

Check if the Component is on the AC or DC bus. All actions of this component affect the buses accordingly.

Check if a Custom Resource exists before using it

if strcmp(custom_component.resource_list(idx).resource_name,'WaveHeight')

This example checks for a Resource with name "WaveHeight"

Set the power the Component produces

new_time_series_output = custom_component.resource_list(wave_height_index).resource_series

This sets the power of the Custom Component equal to the resource value at that time step i.

Set the user_defined_errors

user_defined_errors.error_description = 'none';

user_defined_errors.severity_code = 'none';

Set this if you have no errors or warnings to send back.

user_defined_errors.error_description = 'Power exceeding limit';

user_defined_errors.severity_code = 'COMPONENT_SIMULATION_ERROR';

Set this if you want to send back a warning.

user_defined_errors.error_description = 'Resource file missing';

user_defined_errors.severity_code = 'COMPONENT_CRITICAL_ERROR';

Set this if you want to abort the simulation with the Custom Component. For example, when the Custom Resource is missing, present this error.

 

Troubleshooting

If errors occur while trying to run the MATLAB Custom Component, you may see the "No feasible solutions found" message.

shots_components_controller_matlab_no_feasible

First, ensure that your system does actually produce at least one feasible result by running your system with one of the original HOMER dispatch algorithms, Cycle Charging or Load Following.

DLL Load Library Failed

Look in the Suggestions area in the lower-left corner of the HOMER page for specific error messages. You can hover your mouse over a message or click it to see the full message. The first problem that might occur is that HOMER might be unable to find your MATLAB installation. If this is the case, you see an error message that says "DLL Load Library Failed."

shots_components_controller_matlab_dll_load_fail

If you see this message, be sure that the path specified for the input "Path to '\bin\win32' subfolder in MATLAB installation directory" is correct and points to the \bin\win32 subfolder inside your MATLAB installation. Also ensure that you are pointing to a 32-bit installation of MATLAB, which is always installed in "Program Files (x86)" and not in "Program Files" (if you have a 64-bit computer). If you need a 32-bit version of MATLAB, you can download it from the MathWorks website. You can install 32-bit and 64-bit versions of MATLAB on your computer at the same time.

No Matlab Path

If the path to MATLAB '\bin\win32\ folder is empty, ensure that it is pointing to the correct MATLAB 32-bit version's 'bin\win32' folder.

Error using cd

If HOMER is able to find your MATLAB installation, but not the working directory you specified, you see the error message: "MATLAB error: Error using cd..."

shots_components_controller_matlab_cd_fail

Hover your mouse over the message to see the full text. If you see this error, check the path you specified for the "Working directory" input. It is very likely that this path is spelled wrong or does not exist. HOMER gave MATLAB the command cd('C:\your\path') where "C:\your\path" is the path you specified for the "Working directory," and MATLAB gave an error. If it is not clear by checking the path name, open MATLAB and use the "cd" command to debug this step.

MATLAB error while executing...

If the steps above work, HOMER sends the custom_component variable to the MATLAB workspace, then calls your MatlabUpdateState command using the syntax listed above. If input variables are missing, or if the names are spelled wrong, HOMER provides the corresponding error message in the Suggestions area in the lower-left of the page after the calculation is finished. It may look like this:

shots_components_controller_matlab_error

You can hover your mouse over the message or click it to see the full text of the error message. In this case, the full text of the message is:

MATLAB error while executing '[new_time_series_output,user_defined_errors] = MatlabUpdateState(custom_component);': Undefined function 'MatlabUpdateState for ...

You might see this message if one of the following occurs:

The output return variable is not of the right type of struct.

The new_time_series_output is not the same length as the custom resource used.

There is invalid code in the M-file.