Difference between revisions of "Exercise - Using Simulation Macros"

From Flowcode Help
Jump to navigationJump to search
Line 117: Line 117:
 
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';
 
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';
 
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled "hit" and use it for the Return Value.
 
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled "hit" and use it for the Return Value.
 
 
 
(the intruder)as the Handle;
 
::::* choose 'shape1'( the brick wall) as the Axis;
 
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called "xpos", with an initial value 5.0;
 
 
::::* click on OK.
 
::::* click on OK.
  
Line 135: Line 129:
  
  
 
::::: var1 = 2, add = 3;
 
::* a Code icon [[File:Btn C Code.gif|border]]- details given below;
 
::* a delay icon configured to give a two second delay.
 
  
  
  
use it to create two byte variables, 'var1' and 'add',
 
  
  

Revision as of 13:35, 25 August 2013

Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.

When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros.

Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.

This exercise uses two of them to illustrate the use of a PIR (passive infra-red sensor) to operate an intruder sensor.



The scenario

The scene depicts the front of a house.

Exercise SimIcon pan.png

A PIR sensor is mounted on the wall of the house, above the path leading across the garden.

The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.

Its detection area is represented by the pale blue cone.

When an intruder enters the detection cone, a warning lamp lights up in the house.


The physical bits

With the System Panel visible, and viewed from above (the default position,)on it create:

  • a brick wall, represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep,
located at coordinates x = 0, y = 0, z = 60,
with rotation settings X = 0, Y = 0, Z = 0;
  • a path, represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep,
located at coordinatesx = 125mm, y = 0mm, z = 0mm,
with rotation settings of X = 0, Y = 0, Z = 0;
  • a cone, couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm,
located at coordinates x = 45mm, y = 0mm, z = 80mm,
with rotation settings of X = 0, Y = -55, Z = 0.
  • Drag the mouse cursor over these three elements and group them together. This produces 'group 1'.
Give it:
dimensions - width = 265mm, height = 250mm, depth = 135mm;
coordinates - x = 128, y = 0, z = 68;
rotation - X = 0, Y = 0, Z = 0.


Also on the System Panel, create an intruder, by:

  • adding four spheres, and configuruing the properties as follows:
sphere 1 (the head):
colour pink;
dimensions - width = 12mm, height = 13mm, depth = 15mm;
coordinates - x = -2.2, y = 0.7, z = 22;
rotation - X = 90, Y = 0, Z = 0.
sphere 2 (the body):
colour blue;
dimensions - width = 14mm, height = 26mm, depth = 24mm;
coordinates - x = -2.2, y = 0.5, z = 4;
rotation - X = 90, Y = 0, Z = -180.
sphere 3 (the legs):
colour dark green;
dimensions - width = 9mm, height = 23mm, depth = 15mm;
coordinates - x = -2.2, y = 1, z = -16;
rotation - X = 90, Y = 0, Z = -180.
sphere 4 (the feet):
colour black;
dimensions - width = 6mm, height = 15mm, depth = 25mm;
coordinates - x = -6, y = 0, z = -25;
rotation - X = 90, Y = 90, Z = 0.
  • Drag the mouse cursor over the four spheres and group them together.This produces 'group 2'.
Give it:
dimensions - width = 18mm, height = 32mm, depth = 60mm;
coordinates - x = 165, y = 0, z = 28;
rotation - X = 0, Y = 0, Z = 0.


The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)


The Flowcode program

  • Add the icons shown in the flowchart:
  • a loop icon, configured as an infinite loop, and within it:
  • two Simulation macro icons Btn Simulation Macro.gif;
  • a decision icon with:
  • a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;
  • a 'No' loop containing an output icon, followed by a delay icon and then a calculation icon;
  • Configure the icons, by double clicking on each in turn, as follows:
  • the top Simulation macro:
  • click on the 'Panel' tab, and then on the 'Position' folder;
  • click on the 'MoveAlong' macro and:
  • choose 'group2'(the intruder)as the Handle;
  • choose 'shape1'( the brick wall) as the Axis;
  • click on the down arrow on the end of the 'X' row, and create a floating point variable called "xpos", with an initial value 5.0;
  • click on OK.


  • the second Simulation macro:
  • click on the 'Panel' tab, and then on the 'Collision' folder;
  • click on the 'TestSingle' macro and:
  • choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';
  • use the down arrow at the end of the 'Return Value' box to create a boolean variable caled "hit" and use it for the Return Value.
  • click on OK.









  • Flowcode
  • Experienced
  • Students

Adding supplementary code

This feature

Definitions and function declarations:

This is

Function implementations: