MATLAB Answers

VM
0

On Off switch simulink

Asked by VM
on 10 May 2019
Latest activity Answered by Krishna Akella on 14 May 2019
Hi, in simulink Im trying to create a simple on off switch for a machine (modelled as an enitity server). with the switch being on and off at set points in the simulation ie off for 5 mins when the time is 12:30, 14:30, 15:30.
Im currently using 2 constant blocks 1 and 0 for on and off, fed into an 'if block', which is connected to the entity server.
I cannot seem to figure out how to reference time in the model. I have tried using the clock block as an input to the entity server, however as i am new to matlab my coding skills arent great and cannot figure out how to reference my own attributes.
I have also tried using matlab own defined functions, but again failed to correctly reference time and somehow connect them to the on/off constant blocks.
Could someone give me a hint to the best approach? and a way in which to correctly reference time?
many thanks for your help!

  0 Comments

Sign in to comment.

Products


Release

R2019a

2 Answers

Answer by Raj
on 13 May 2019

There are many ways you can approach this problem. One way is to convert your entity server model as an Triggered sub system. Then pass the trigger/control signal as one or zero from outside excel based on your timing criteria. See details on triggered subsystems here.
Get back in case you are having any difficulty.

  0 Comments

Sign in to comment.


Answer by Krishna Akella on 14 May 2019

Hi VM,
If I understand correctly, you are trying to model a machine going on a break for scheduled maintenance or some thing like that at particular points in time during the day. If that is correct, there are a couple of ways in which you can model this:
  1. To model a machine (Entity Server) going on a break, you can generate and send a dummy entity to the server at the specified time (through an entity input switch) and set the service time equal to 5 min (dt = 300). In you dummy entity generator you can read the current simulation time using the 'Digital Clock' block. For example, in SimEvents library see the 'Time stamp entities upon generation' under the 'Design Patterns' section.
  2. A cleaner way, although a more sophisticated way, would be to build a custom server using a 'MATLAB Discrete event system' block. You can then model your requirement in a very straight forward way. In the MATLAB DES block you can read the current simulation time using the getCurrentTime() function. To begin with, you can take the 'Custom Server' block from the design patterns and start editing it. If you are using MATLAB version >= R2017b, you can use the testEntry action method like the following to restrict any entities from being served, when the server is on break.
function isAllowed = testEntry(obj, storage, ~, ~)
% If the server is to go on break, return false to block the server
if ( obj.IsMyServerOnBreak() )
isAllowed = false;
else % If the server is online, accept entities for service
isAllowed = true;
end
end
Regards,
Krishna

  0 Comments

Sign in to comment.