Sheep Pen

From Flowcode Help
Jump to navigationJump to search

In this scenario we will demonstrate an automated sheep pen that can be used to move sheep from one pen to another. In the scenario sheep are represented by sphere component primitive objects which move randomly around inside the confides of the pen.

Each pen is gated with an electronic gate that can be opened or closed.

Between each pen is a corridor with a sensor to detect when a sheep is inside the corridor.

At the start of the simulation all sheep are in Pen A, the task is to move all the sheep from Pen A to Pen B

SH1.jpg


Exercise 1

Create a simple program to move all the sheep from Pen A to Pen B.


Tasks

  • Create a new flowchart, and select ‘No chip’ as the target device. We choose no chip as this is a simulation only exercise.
  • Add the ‘Sheep Pen’ component to the 3D Panel, from the ’Simulation -> Scenarios’ category.
  • Adjust the 3D Panel so that you can see the component, The Preset Views button or clicking the arrows at the top left of the 3D Panel window can be very helpful.
  • Add a loop to your program to loop forever until the simulation stop button is pressed.
  • Add a component macro to your loop to open Gate A.
  • Add a component macro to your loop to close Gate B.
  • Add a variable to store the value of the sensor.
  • Add a component macro to your loop to read the value of the sensor and store the result into the variable you created.
  • Add a decision icon to your loop to act on the value of the variable.
  • If the sensor is activated then add component macros to the Yes branch of the decision to close Gate A and open Gate B.
  • Add a loop to the yes branch of the decision to wait until the sensor is no longer activated.
  • Add a component macro inside your loop to update the value of your sensor variable.
  • Run the simulation by clicking the Play button on the top toolbar.


Working Example

Below you will see a working example to automatically herd the sheep from Pen A to Pen B.

FC6 Icon.png Sheep Pen - Worksheet 1

SH2.jpg


What to do next

Adjust the number of sheep using the SheepPen component properties.

Add a toggle switch to the 2D dashboard panel and change the Flowchart code so that you can move all sheep from Pen A to Pen B and then from Pen B to Pen A depending on the state of the toggle switch. This would allow the simulated Sheep Farmer to be able to move the sheep from pen to pen at the flick of a switch.


Component Details

A full listing of the macros and properties available in this component are available from the Components Section.