Decision component for simulation only

Moderator: Benj

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Decision component for simulation only

Postby medelec35 » Wed Feb 13, 2019 4:22 pm

Is it possible to have a dragable decision component that the true branch is accessed during simulation only?
The false branch is for when running of hardware.
I have set up a few flowcharts that work like this but there are a fair few steps involved.
Would be nice to drag a single decision branch instead.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Steve
Matrix Staff
Posts: 3110
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 396 times
Contact:

Re: Decision component for simulation only

Postby Steve » Thu Feb 14, 2019 9:57 am

Hi Martin,

That's a good idea. I'm sure Ben and Leigh know a few tricks, but in the meantime, here's a possible workaround...

1) Create a variable and set it to zero ("IsSimulating = 0").
2) Use a simulation event (e.g. Time::GetMillisecs) to set it to a value
3) Use an "if (IsSimulating <> 0)" decision to determine if you are simulating or not

I've not tested this, but it should work because step 2 will be ignored in the microcontroller code and so "IsSimulating" will remain zero when running on a device but will be set to a non-zero value when simulating.

Regards,
Steve.
These users thanked the author Steve for the post:
medelec35 (Thu Feb 14, 2019 10:50 am)
Rating: 5%
 

User avatar
LeighM
Matrix Staff
Posts: 1999
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 479 times
Been thanked: 684 times
Contact:

Re: Decision component for simulation only

Postby LeighM » Thu Feb 14, 2019 10:31 am

Thanks Steve, and for reminding me to comment
I've done this with a "Simulating" property (value 0 or 1)
Set the property value in a Ev event Simulation Start,
and clear the property value in a Ev event Simulation Stop.
I think this idea came from Ben, so he probably does similar.
Leigh

sim.jpg
sim.jpg (97.34 KiB) Viewed 2043 times
These users thanked the author LeighM for the post:
medelec35 (Thu Feb 14, 2019 10:52 am)
Rating: 5%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Decision component for simulation only

Postby medelec35 » Thu Feb 14, 2019 10:56 am

Thanks Guys,
I have been following this post.
Just thought a more instant solution would be beneficial for all?
These users thanked the author medelec35 for the post:
Benj (Thu Feb 14, 2019 2:33 pm)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: Decision component for simulation only

Postby Benj » Thu Feb 14, 2019 2:38 pm

Hello,

Yes a great idea Martin,

Here's a quick go at a simple component complete with source.

IsSim.fcfx
(9.86 KiB) Downloaded 43 times

IsSim.fcpx
(1.37 KiB) Downloaded 49 times


I'll add an icon and a simple GUI and add it to the v8 release.

Inside the decision icon just add this code.

Code: Select all

IsSim1::Check()


No = MCU, Yes = Sim Runtime

SimCheck.jpg
SimCheck.jpg (8.47 KiB) Viewed 2018 times
These users thanked the author Benj for the post (total 2):
medelec35 (Thu Feb 14, 2019 2:39 pm) • kersing (Fri Feb 15, 2019 6:41 pm)
Rating: 10%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Decision component for simulation only

Postby medelec35 » Thu Feb 14, 2019 7:08 pm

Hi Ben,
Just looked into this.
Do you have to add to flowchart

Code: Select all

Ev_Initialise
,

Code: Select all

Ev_Comp_Start
,

Code: Select all

Ev_Start
,

Code: Select all

Ev_Stop
&

Code: Select all

.Return = Sim
if using component?
If so, do you believe its easier than this?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: Decision component for simulation only

Postby Benj » Fri Feb 15, 2019 1:44 pm

Hi Martin,

You shouldn't have to add any of that.

It should be a case of add the component, Add the code to the decision icon. Job done :)

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Decision component for simulation only

Postby medelec35 » Fri Feb 15, 2019 2:43 pm

Thanks Ben,
Benj wrote:You shouldn't have to add any of that.

Woops Sorry, I did not see the words source, so thought Flowchart posted was an example.

Tested on hardware and working better than expected as did not need to add

Code: Select all

IsSim1::Check()
, So no need to memorise!
It works buy just using the the component:
IsSim Test1.png
IsSim Test1.png (47.37 KiB) Viewed 1984 times

I will be adding Is Sim component to every flowchart that uses RX interrupt!
These users thanked the author medelec35 for the post (total 2):
Benj (Fri Feb 15, 2019 6:01 pm) • kersing (Fri Feb 15, 2019 6:40 pm)
Rating: 10%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.