Simulating simple electric circuits

Arnaud Delobelle arnodel at googlemail.com
Mon May 7 15:16:21 EDT 2007


On May 7, 7:05 pm, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n... at spamgourmet.com> wrote:
> Hello all,
>
> I'm trying to simulate simple electric logic (asynchronous)
> circuits. By "simple" I mean that I only want to know if I
> have "current" or "no current" (it's quite digital) and the only
> elements need to be (with some level of abstraction to my specific
> problem)
>
> - sources (here begin currents)
> - ground (here end currents)
> - joints
> - switches (which are able to let current pass or not, depending on
>   outside influence)
> - loads (which can signal change in current flow to the outside --
>   just like a light bulb)
>
> Is there any library for this? I couldn't find one.
>
> I tried to implement this using objects that are two-way linked;
> every object has "ports". For every port, there is
>
> - an input function (that is called by the neighbour if "current"
> comes in)
> - a reference to the neighbour's input function, to be able to let
> current flow the other way
>
> There is a master "current controller" object which tells
> the "source" object to start a "current" by calling its neighbour.
> The calls traverse the network until they reach a "ground" object.
> Specifically, the source passes a "telegram" instance with these
> calls, and everyone it passes through "registers" himself with it
> (telegrams are duplicated at joints). Then, the ground object calls
> back to the controller with all received telegrams. Like this I'm
> already able to get all possible ways through the network.

Then you can get all 'potential' paths that depend on one or more
switches being on.  Each path could know what switches it depends on
and be 'active' if and only if all those switches are on.  And each
switch would know what paths depend on it. Similarly each lightbulb
would know what paths it depends on and be 'on' if at least one path
is active; and each path would know which lightbulbs it powers

> But that's where my ideas go out. Let's assume there is a load in
> the middle of such a current, e. g. a light bulb. So if the current
> flows through it it gets notice of this because there is a telegram
> passing through it. But what if a contact before it now "cuts" the
> current, how could I notify all objects behind the cut? I tried
> several ways the past few days, but all lead to confusing (and
> non-working) code. (I'm sorry I can't provide any working code yet)
> Often it boils down to the need to check all possible ways in the
> entire network with every change. This shouldn't, in perfomance
> terms, be a big problem for me here, but it feels very dirty, and I
> smell inconsistencies.

When you turn a switch off, it would send a message to the paths that
depend on it (maybe via the controller?) so that they would be
deactivated.  In turn the lightbulbs on these paths would be informed
that they are no longer active.

When you turn a switch on, it would send a message to the paths that
depend on it so that those who do not have another off switch would be
activated.  In turn the lightbulbs on these paths would be informed
that they have a new power source.

It seems to me that it would work well with the way you started it
out, but I may have misunderstood some aspects or overlooked some
problems ;)

--
Arnaud




More information about the Python-list mailing list