Skip to main content

An educational ladder logic simulator in Python

Project description

PyLadderSim

PyLadderSim is an educational Python library for simulating ladder logic in a programmable logic controller (PLC) environment. This project provides an interactive, visual ladder logic simulation that allows users to build and visualize ladder circuits, toggle component states, and observe the impact of changes in real time.

Features

  • Create Ladder Logic Circuits: Add various components like contacts, coils, timers (ON-delay, OFF-delay, pulse timers), and more.
  • Interactive Toggling: Components are now clickable in the visualization, allowing users to toggle their states directly by clicking on them.
  • Real-Time Visualization: The simulation includes a live visualization of ladder logic, including color-coded status updates for each component.
  • Educational Focus: Designed to help students and enthusiasts learn ladder logic programming and PLC simulation in an intuitive and accessible way.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/pyladdersim.git
    cd pyladdersim
    
  2. Install required dependencies:

    pip install -r requirements.txt
    

Usage

  1. Setting up a Ladder Logic Simulation:

    Import pyladdersim components and set up a simple ladder circuit:

    from pyladdersim.components import Contact, InvertedContact, Output, OnDelayTimer
    from pyladdersim.ladder import Rung, Ladder
    from pyladdersim.visualizer import LadderVisualizer
    
    # Define components
    input1 = Contact(name="Start")
    input2 = InvertedContact(name="Stop")
    output = Output(name="Lamp")
    
    # Create a rung and add components
    rung1 = Rung([input1, input2, output])
    
    # Initialize the ladder and add rungs
    ladder = Ladder()
    ladder.add_rung(rung1)
    
    # Run the ladder with visualization
    ladder.run(visualize=True)
    
  2. Interacting with the Simulation:

    • Click directly on components in the visualization to toggle their states.
    • Observe color changes: Green indicates active (ON), and red indicates inactive (OFF).
    • Press Q to stop the simulation.

Components

  • Contact: Represents a standard normally open contact.
  • Inverted Contact: Represents a normally closed contact.
  • Output Coil: Represents an output device.
  • Timers: Includes ON-delay, OFF-delay, and pulse timers, each with unique timing and control logic.

Visualization

The live visualization interface is built with Tkinter for an interactive, seamless UI:

  • Transparent, Clickable Components: Each contact and coil is interactive, allowing users to click and toggle their states.
  • Dynamic Color Coding: Components show real-time ON/OFF status, with green for active and red for inactive.
  • Simulation Control: The interface updates continuously, showing the current state of each rung and overall circuit.

Example

Here’s an example of a simple ladder logic with a start/stop control and a timer-based output:

from pyladdersim.components import Contact, InvertedContact, Output, OnDelayTimer
from pyladdersim.ladder import Rung, Ladder
from pyladdersim.visualizer import LadderVisualizer

# Define components
start_button = Contact(name="Start")
stop_button = InvertedContact(name="Stop")
timer = OnDelayTimer(name="Delay Timer", PT=3)  # Timer with preset time
lamp = Output(name="Lamp")

# Create rungs
rung1 = Rung([start_button, stop_button, timer])
rung2 = Rung([timer, lamp])

# Initialize ladder
ladder = Ladder()
ladder.add_rung(rung1)
ladder.add_rung(rung2)

# Run the ladder with visualization
ladder.run(visualize=True)

Contributing

We welcome contributions to add new features, fix bugs, and improve documentation. To contribute, fork the repository, make your changes, and open a pull request.

License

This project is licensed under the MIT License.


Enjoy exploring ladder logic with PyLadderSim! For any questions, feel free to reach out or open an issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyladdersim-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyladdersim-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pyladdersim-0.1.0.tar.gz.

File metadata

  • Download URL: pyladdersim-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pyladdersim-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b23e09c3b72d5fd4d9ff757669e3d04d909d6882e34a28a90b83c43f40a25981
MD5 e749242b9ce4c326f9b4978aeea36041
BLAKE2b-256 2a08e8101dcf6c6ac45ad72bc409971bb65c8446aaf11515e029e75f36383681

See more details on using hashes here.

File details

Details for the file pyladdersim-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyladdersim-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pyladdersim-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25016104a68fc334bda4bd7af9cde853bdf9a5a1f2ccced907f3d87f410127ab
MD5 61617d668f145817539ca161341698f8
BLAKE2b-256 d77bec00d6d4ac2271f5e38d18405ce4f78d871889d457f6b30ab34210685e57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page