xgulism1 / UE_Spice_Demo

A demo project for the Spice plugin for Unreal Engine.
3 stars 0 forks source link

Can't get @values #2

Open Angelo50 opened 1 year ago

Angelo50 commented 1 year ago

Hi, I have tried to get componant value as we can do in ngspice but it does not return anything Example a verat basic simple netlist

V0 1 0 5 R1 1 0 100 .tran 0.001 50 uic

Your plug-in give me access to all the standard Keys (V0#branch, node 1) But, in ngspice, I have the option to get componant values as Amps for exemple by typing: print @r1(i) I tried with the function "GetAnalysisValues" with the key @r1, @R1, r1, R1 but it does not return anything Can you help ?

xgulism1 commented 1 year ago

Hi,

I am sorry, but I am not familiar with the syntax @r1(i) in print command in ngspice. I tried it using the ngspice application downloaded here: https://sourceforge.net/projects/ngspice/files/ng-spice-rework/38/ngspice-38_64.zip/download Commands like print v(1) or print v0#branch work (without the @), but only for the existing vectors.

However, if you need to get the current values through the component, the ngspice documentation (https://sourceforge.net/projects/ngspice/files/ng-spice-rework/38/ngspice-38-manual.pdf/download) states on the page 93: "zero valued voltage sources may be inserted into the circuit for the purpose of measuring current. They of course have no effect on circuit operation since they represent short-circuits." On the same page is an example of the voltage source (the name suggests it is used for measurement): VMEAS 12 9

I can see it being annoying inserting voltage sources after every component, but I do not think there is another way. I have always done it that way.

Martin

Angelo50 commented 1 year ago

Thanks for your anwser In Ngspice, we can access a lot of value for each component just by reference the component name with a @before Of course, there are some work around for the intensity by just computing (node1Volt - node2Volt) / Ohm for a resistor. I use it already But for diodes, transistors, the heart of ngspice is the usage of the components reference value with the @ I don't have a clue how you built the plug-in to run an ngspice instance and communicate with it I tried 2 or 3 years ago to integrate the ngspice DLL in visual studio and work with it but without success.. This is why I bought your plug-in. I have already developped the simulator in unreal with your plug-in and it works, but now I want to go deeper, I need to go deeper with the circuit values

Ps: I already use the voltage node with 0 to simulate each naked wire the player creates

xgulism1 commented 1 year ago

You are right. I found it in the documentation as "internal device parameters". The syntax is @r1[r] for the resistance of the r1 resistor. It works in alter commands e.g. alter @r1[r] = 50, although this is obviously not the main purpose.

I do not want to expose raw commands to ngspice from blueprints to keep things simple, but I will try to figure out how to provide access to the internal device parameters.

Thank you!

Angelo50 commented 1 year ago

In fact, I want to implement diodes and especially LED. I'm able to see it's voltage according his two nodes but not his Intensity ( with the @D1[id] if we consider it is called D1 in the circuit) image

I have already implement a logic that retreive all voltages for nodes, Amps for wire with the standard vectors

Thanks for your time Angelo.

Angelo50 commented 1 year ago

Hey, I'have found the issue It has nothing to see with you but with me ..so sorry By default,NGSpice does not keep feed back component currents You have to add the following option: .options savecurrents Thatis simple as that and it works now, I can access the component currect value simply by setting the key @d1[id] I hope you did not waste your time because of me Thanks

Angelo.

xgulism1 commented 1 year ago

No worries :), I also learned new things. Thank you.

Martin

Angelo50 commented 1 year ago

Hi Martin.

You may have a look on this video: https://youtu.be/b1MjcLRQZ5M This is the starting point of using you plug-in in realtime and implement an interactive simulator As written in the video, do not take care of the cosmetic part which needs to be imporved

Angelo.