PLC

Programm your own logic in Unity C# scripts

Using a C# script is just one way to define custom logic. Please check sectioin Defining Logic

If no real PLC is connected to the model, a PLC script (based on the ControlLogic base script) can be used to control the model. This can be used for replacing missing PLC functions during the development phase or for demo purposes. The realvirtual.io Demo Model is fully controlled by PLC scripts.

This is a simple PLC-script from the Demo Model. This script is controlling the conveyor with the cans. As soon as the sensor at the end of the conveyor is high the conveyor is stopped.

PLC_CanConveyor

public class PLC_CanConveyor: ControlLogic
  {
      public bool On = true;

      [Header("References")] 
      public PLCOutputBool StartConveyor;
      public PLCInputBool SensorOccupied;
      public PLCInputBool ButtonConveyorOn;
      public PLCOutputBool LampCanAtPosition;
 
      // Call this when all Updates are done
      void FixedUpdate()
      {
      
          if (SensorOccupied.Value == false && On && ButtonConveyorOn.Value == true)
          {
              StartConveyor.Value = true;
          }
          else
          {
              StartConveyor.Value = false;
          }

          LampCanAtPosition.Value = SensorOccupied.Value;
      }
  }

© 2022 in2Sight GmbH https://realvirtual.io - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

Last updated