Error in builnding model on Arduino

2 Ansichten (letzte 30 Tage)
Valerio
Valerio am 12 Feb. 2012
Kommentiert: phuc huynh am 28 Mai 2018
Hi everybody, I'm trying to build a very simply model on arduino mega 2560 board to move a servoactuator. When I press 'Build' it stops the procedure because of this error:
The corresponding 'msfun_arduino_servowrite.tlc' file for the MATLAB S-function 'msfun_arduino_servowrite' in block 'provaservu/Servo Write' must be located in the current working directory, the MATLAB S-function directory 'C:\Users\Valerio\Desktop\Tesi\Arduino0022-mavlink1.0\Arduino_simulink\demos', or the directory 'C:\Users\Valerio\Desktop\Tesi\Arduino0022-mavlink1.0\Arduino_simulink\demos\tlc_c'
I haven't any .tlc file and I don't know how to do to solve my problem.
Any ideas about that?
Thank you all!
VZ
  2 Kommentare
Arun Limgaokar
Arun Limgaokar am 13 Apr. 2018
"ok i've solved my problem alone! Thank you all!", May i know how.
phuc huynh
phuc huynh am 28 Mai 2018
can you help me????

Melden Sie sich an, um zu kommentieren.

Antworten (5)

Kaustubha Govind
Kaustubha Govind am 13 Feb. 2012
Is this where you got your blocks from? If yes, there is a comment in the Discussion section that talks about this error:
"[The] MATLAB Support Package does not support code generation. The included Simulink blocks communicate with the Arduino in Simulink "normal" (aka. simulation) mode only.

Valerio
Valerio am 14 Feb. 2012
Hi and thanks for helping me. I've understood your solution and now i'm using just the Arduino Target blocks. Now I've a problem with a S-Funtion that seems to be very similar to this:
I've followed the steps adding the function and instructions about the SetInputPortDimensions but now i've a new problem with the arguments of the added function. I copy the code for explaining it better:
function sserialsb(block)
%SSERIALSB Underlying S-Function for the ICT Serial Send block.
%SSERIALSB(BLOCK) is the underlying S-Function for the ICT Serial Send
% block.
% SS 10/15/07
% Copyright 2007-2010 The MathWorks, Inc.
% $Revision: 1.1.6.5 $
% The setup method is used to setup the basic attributes of the
% S-function such as ports, parameters, etc. Do not add any other
% calls to the main body of the function.
setup(block);
%endfunction
%% Function: setup
===================================================
% Set up the S-function block's basic characteristics such as:
% - Input ports
% - Dialog parameters
% - Options
%
function setup(block)
% Parameters:
% 1:ComPortMenu,
% 2:ComPort,
% 3:ObjConstructor,
% 4:Header,
% 5:Terminator,
% 6:EnableBlockingMode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%*ADDED*
block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Register number of ports
block.NumInputPorts = 1;
% Register parameters
block.NumDialogPrms = 6;
block.DialogPrmsTunable = {'Nontunable', 'Nontunable',
'Nontunable', ...
'Nontunable', 'Nontunable', 'Nontunable'};
% Register sample times, Inherit sample time.
block.SampleTimes = [-1 0];
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
% Override input port properties
for idx = 1:block.NumInputPorts,
block.InputPort(idx).Complexity = 0; % Real
block.InputPort(idx).DirectFeedthrough = true; % Access inputs in Outputs function
end
% Specify if Accelerator should use TLC or call back into
% file
block.SetAccelRunOnTLC(false);
block.SetSimViewingDevice(true);% no TLC required
% Allow multi dimensional signal support.
block.AllowSignalsWithMoreThan2D = true;
%%-----------------------------------------------------------------
%%Register methods called at run-time
%%-----------------------------------------------------------------
%%Start:
%%Functionality :Called in order to initialize state and work
%%area values
block.RegBlockMethod('Start', @Start);
%%Outputs:
Functionality : Called to generate block outputs in
simulation step
block.RegBlockMethod('Outputs', @Outputs);
%%Terminate:
Functionality : Called at the end of simulation for cleanup
block.RegBlockMethod('Terminate', @Terminate);
%endfunction setup
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%*ADDED*
function SetInpPortDims(block, idx, di)
block.InputPort(idx).Dimensions = di;
block.OutputPort(1).Dimensions = di/2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Start - Set up the environment by creating objects, initializing data.
function Start(block)
% Get the error strings.
errorStrings = instrumentslgate('privateinstrumentslstring',
'errorStrings');
% Get the block name.
blockName = get_param(block.BlockHandle, 'Name');
% Error if no port selected.
if strcmpi(block.DialogPrm(2).Data, errorStrings.SelectPortString)
error(errorStrings.InvalidSerialPortID, ...
errorStrings.InvalidSerialPort, blockName);
end
% Check the sample time of the block to be not continuous.
if (block.SampleTimes(1) == 0)
error(errorStrings.InvalidInheritedSampleTimeID, ...
errorStrings.InvalidInheritedSampleTime, blockName);
end
% Find the corresponding serial configuration block.
configBlk = find_system(bdroot, 'FollowLinks', 'on', ...
'MaskType','Serial Configuration', ...
'ComPort', block.DialogPrm(2).Data);
% Check if empty.
if (isempty(configBlk))
% Error out as no serial configuration block is found.
error(errorStrings.NoSCBlocksID, ...
errorStrings.NoSCBlocks, ...
block.DialogPrm(2).Data, block.DialogPrm(2).Data);
end
% Get the serial object from configuration block.
configBlkUserData = get_param(configBlk{1}, 'UserData');
if isfield(configBlkUserData, 'zzzSimulinkSerialObject')
serialObj = configBlkUserData.zzzSimulinkSerialObject;
% Get the reference count and check for errors.
configBlkUserData.zzzReferenceSendInstance =
configBlkUserData.zzzReferenceSendInstance+1;
set_param(configBlk{1}, 'UserData', configBlkUserData);
else
% Create the object.
configBlockHandle = get_param(configBlk{1}, 'Handle');
serialObj = eval(get_param(configBlockHandle, 'ObjConstructor'));
configBlkUserData.zzzSimulinkSerialObject = serialObj;
configBlkUserData.zzzReferenceReceiveInstance = 0;
configBlkUserData.zzzReferenceSendInstance = 1;
set(configBlockHandle, 'UserData', configBlkUserData);
% Set the block parameters.
set(serialObj, 'BaudRate', str2double(get_param(configBlockHandle, 'BaudRate')), ...
'DataBits', str2double(get_param(configBlockHandle, 'DataBits')), ...
'Parity', get_param(configBlockHandle, 'Parity'), ...
'StopBits', str2double(get_param(configBlockHandle, 'StopBits')), ...
'FlowControl', get_param(configBlockHandle, 'FlowControl'), ...
'Timeout', str2double(get_param(configBlockHandle, 'Timeout')), ...
'ByteOrder', get_param(configBlockHandle, 'ByteOrder'));
end
% Multiple send blocks.
if (configBlkUserData.zzzReferenceSendInstance>1)
error(errorStrings.MultipleSSBlocksID, ...
errorStrings.MultipleSSBlocks, ...
block.DialogPrm(2).Data, block.DialogPrm(2).Data);
end
% Set output buffer size on the object. Arbitrarily set to 100
times
% size of data in input port.
reqdBufferSize = 100*block.InputPort(1).DataStorageSize;
if ( reqdBufferSize > get(serialObj, 'OutputBufferSize') )
% Close the object.
fclose(serialObj);
% Set it on the object.
set(serialObj, 'OutputBufferSize', reqdBufferSize);
% Open the object again.
fopen(serialObj);
end
% Store the serial object to send blocks user data.
sendBlkUserData = get_param(block.BlockHandle, 'UserData');
sendBlkUserData.zzzSimulinkSerialObject = serialObj;
% Extract the header and terminator as well.
[header terminator] = instrumentslgate('privateslextractheaderandterminator', ...
block.DialogPrm(4).Data, ...
block.DialogPrm(5).Data);
sendBlkUserData.zzzSimulinkSerialHeader = header;
sendBlkUserData.zzzSimulinkSerialTerminator = terminator;
set_param(block.BlockHandle, 'UserData', sendBlkUserData);
% Check the data type.
dataType = block.InputPort(1).DataTypeID;
if (dataType < 0 || dataType > 7)
% Error as data type invalid.
error (errorStrings.InvalidDataTypeID, ...
errorStrings.InvalidDataType, blockName);
end
%endfunction
%% Outputs - Generate block outputs at every timestep.
function Outputs(block)
% Parameters:
% 1:ComPortMenu,
% 2:ComPort,
% 3:ObjConstructor,
% 4:Header,
% 5:Terminator,
% 6:EnableBlockingMode
% Get the underlying serial object.
userData = get_param(block.BlockHandle, 'UserData');
serialObj = userData.zzzSimulinkSerialObject;
header = userData.zzzSimulinkSerialHeader;
terminator = userData.zzzSimulinkSerialTerminator;
data = block.InputPort(1).Data(:)';
% Convert data to uint8's.
convertedData = typecast(data, 'uint8');
% Append header and terminator.
data = [header convertedData terminator];
% Output data depending on the mode selected.
if strcmpi(block.DialogPrm(6).Data, 'on') % Blocking mode on.
% Write the data.
fwrite(serialObj, data, 'uint8');
else
% Blocking mode off.
while (get(serialObj, 'BytesToOutput') ~= 0)
% Just wait until previous async fwrite is complete.
pause(0.01);
end
% Write asynchronously.
fwrite(serialObj, data, 'uint8', 'async');
end
%endfunction Outputs
%% Terminate - Clean up
function Terminate(block)
% Call the terminate method for serial object.
% Get the ID of the serial object.
userData = get_param(block.BlockHandle, 'UserData');
if isfield(userData, 'zzzSimulinkSerialObject')
serialObj = userData.zzzSimulinkSerialObject;
% Check if the object is still valid.
if isa(serialObj, 'serial') && isvalid(serialObj)
% Check if receive and transmit operations are done.
while ~(strcmpi(get(serialObj, 'TransferStatus'), 'idle'))
% Pause for some time for asynchronous operation to get over.
pause(0.01);
end
% Close and delete is done by the configuration block.
end
end
userData = [];
set(block.BlockHandle, 'UserData', userData);
%endfunction
I wrote ADDED to the two part of code I've added in and I don't know if I've done it well or positioned in the right place. The error I get is:
1)Error evaluating registered method 'SetInputPortDimensions' of MATLAB S-Function 'sserialsb' in 'provaprovahost/Serial Send'.
2)Invalid output port index specified for 'provaprovahost/Serial Send'. This block has no output ports
3)Error in port widths or dimensions. Output port 1 of 'provaprovahost/Constant' is a one dimensional vector with 1 elements.
Thank you for the help in advance.
VZ

Valerio
Valerio am 14 Feb. 2012
I've to correct a thing that I've changed respect to the last answer i wrote. I've changed this:
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%*ADDED*
function SetInpPortDims(block, idx, di)
block.InputPort(idx).Dimensions = di;
block.OutputPort(1).Dimensions = di/2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
with this:
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%*ADDED*
function SetInpPortDims(block, idx, di)
block.InputPort(idx).Dimensions = di;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
because i've just an input port and zero output port.
So then the Error now is:
1)Error evaluating registered method 'Outputs' of MATLAB S-Function 'sserialsb' in 'provaprovahost/Serial Send'.
2)An error occurred during writing.
Does it referred to the last paragraph of the code (function Outputs(block)?
Thank you again!
VZ
  1 Kommentar
Kaustubha Govind
Kaustubha Govind am 14 Feb. 2012
Valerio: I would recommend setting a breakpoint in your Outputs method and stepping through it to see what is going wrong. My guess is that error is coming from:
fwrite(serialObj, data, 'uint8');
There might be something wrong with your serial port object?

Melden Sie sich an, um zu kommentieren.


Valerio
Valerio am 16 Feb. 2012
ok i've solved my problem alone! Thank you all!

Sebastian Dietz
Sebastian Dietz am 29 Okt. 2015
Valerio, it would be great if you could tell us how you solved your problem.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by