1

We have a Simulink model that is compiled and run on a dSPACE box. We need to be able to

  1. change the value of a parameter with dSPACE ControlDesk and
  2. change the value of a parameter with a Matlab function inside the model (or something equivalent like a Simulink block)

(1) is possible with a Constant block, just by entering a number. You can change the value of the Constant block in dSPACE. It is also possible to enter a variable name like FOO in the Constant block and change that value FOO as a tunable parameter.

(2) has not been possible so far. Things like 'set_param' do not seem to work, because everything is compiled with Simulink Coder.

Problem

Any method that is able to change the parameter FOO from inside the model would work for us.

Application / Why?: We have values like "target x position of robot". Sometimes, this value is set manually, but sometimes, it is set automatically by different actors ('Drive straight', 'Drive curves', whatever). It would be nice to see the current target x position in one definite place and not have to worry about manually switching control from manual mode to actor 1, actor 2 etc. (of course we then need to make sure only one actor is active at each time step). If need be and our idea is impossible, we would at least like an elegant way to switch control.

Current workaround (has problems):

enter image description here enter image description here

Our current method detects changes in the set values (that may come from different actors). Actor 1 sets value u1=10, then y=u1=10. Actor 2 then sets value u2=30, then y=u2=30. But if actor 1 then sets u1=10 again, no change is detected and y is still u2=30.

terrywb
  • 3,740
  • 3
  • 25
  • 50
nspo
  • 1,488
  • 16
  • 21
  • Does the dSPACE target provide an ["External Mode"](https://de.mathworks.com/help/rtw/ug/_mw_e3815663-2703-41c7-8837-a1c09fccf2fe.html#mw_562fab5d-0c62-4f20-bfc7-251542f1deb1) for Simulink? If so you can have a simple M-Script to change the value on the target system from MATLAB / Simulink. – Sven-Eric Krüger May 24 '18 at 13:29
  • I will have to check that later. Though the idea was to change the values with a matlab function block (or equivalent) that is also compiled and run on the dSpace box itself, so that a computer is not really necessary. – nspo May 24 '18 at 13:58
  • Why don't you use the output of the M-Function as a Signal to drive the "Outport 26"? – Sven-Eric Krüger May 24 '18 at 14:10
  • See Application / Why. Sometimes we need to set the 'outport 26' manually, sometimes matlab function 1 needs to set it, sometimes matlab function 2, etc. – nspo May 24 '18 at 16:30

1 Answers1

2

You can use a "Data Store Memory", which you can change during runtime from within a MATLAB-Function-Block.

Model with M-Function and Data Store Memory

In the M-Function you declare FOO as global variable.

function fcn(u)
%#codegen

global FOO

% Do something foo...
if u < 10
    FOO = 1;
else
    FOO = 2;
end

To be able to do so you must first attach this global variable to the M-Function via the "Ports and Data Manager".

MATLAB Editor for M-Function-Block

Ports and Data Manager

Then you also have to double-click on the "Data Store Memory" in the model and in the section for "Signal Attribute" within the Block Parameters you have to set the following parameters to defined values - auto detection is not allowed here:

  • Initial value
  • Data type
  • Dimensions
  • Signal type (complexity)

Block Parameters for Data Store Memory


BUT I WOULD STILL RECOMMEND JUST TO USE AN OUTPUT OF THE M-FUNCTION TO DRIVE OUTPORT 26!

Sven-Eric Krüger
  • 1,277
  • 12
  • 19