LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom LabVIEW Code Along With SIT Wizard Code

Hello,
 
     I have a model that I have built in Simulink and are using the SIT Connection Manager to interface the model with my LabVIEW  front panel indicators and controls.  What I want to do with that auto-generated code is add my own code to it.  My question is, where can I put that code so it simultaneously runs with the SIT model, either on a real-time machine or on a host pc, in non-real-time, using a dll.  The model I have is a Simulink model of an engine and a 6DoF model with a PID controller.  What I want to do is tweak the PID Controller with LabVIEW code.  So, I will reiterate my question.  Where can I put this PID Controller code for my model when the model is setup in the wizard.  Thank you for your help.
 
Michael B
0 Kudos
Message 1 of 8
(4,456 Views)
Quick question: are you using SIT 4.0? I would highly encourage it for your case, because SIT 4.0 allows gives you many options to add your own custom code that runs alongside the scripted code for the model. You can add your code in similar places in SIT 3.0, but unfortunately you can't make changes in the SIT Connection Manager after that point or your custom code might get overwritten. SIT 4.0 gives you specific, documented places that are completely safe to add custom code to, and you can still use the Connection Manager to safely update your simulation I/O, data logging, or file playback resources.

For instance, in the Base Rate Loop subVI of the scripted Driver VI that runs the model there are labeled sequence frames set up around the base rate loop where the model ticks. There are four separate sequence frames intended for custom Initialization, Read, Write and Shutdown code. The Model Inputs and Model Outputs array go through the Read and Write frames respectively, giving you a chance to update those values as needed for your custom PID. The most important thing to remember, actually, is to not place code in the scripted IO VIs, because they get rewritten every time. The sequence frames are the recommended place for custom code. There is documentation to this effect on the block diagram of the Base Rate Loop subVI.

If you want to have code run in parallel to your simulation, rather than in the main base rate simulation loop itself, that is fine too in SIT 4.0. You can simply place your own subVI anywhere on the top-level of the scripted Driver VI and then use RT FIFOs or some such mechanism to communicate with your model as it runs.

To summarize, you can make the same changes with SIT 3.0, but you risk overwriting those changes when making changes in the SIT Connection Manager. SIT 4.0 provides a documented, safe way to manipulate the Driver VI to fit your needs.

Hope this helps!



Message Edited by Jarrod S. on 12-05-2007 10:47 PM
Jarrod S.
National Instruments
Message 2 of 8
(4,435 Views)
Jarrod S,
 
     Thank you for the detailed and fast response!  I greatly appreciate it.  The information that you provided is a great help, but I have a few more questions based on the information you gave.  For that application, the reponse you gave seems feasable, but I have another circumstance which is a bit difference.  I have a Simulink model in which I am able to map imports and outports to analog I/O on my NI PCIe-6259 board.  What I would truely like to do is also use my model to map to digital I/Oin SIT Connection Manager, btu that is not feasable with my board.  So, I am stuck with the option of custom code.  I want to add Digital I/O code to this SIT Connection Manager VI.  I am not sure what kind of problems that could arrise from such application, if there are any at all.  What is the difficulty in programming of this application because I really have no idea on the amount of code and programming this would take?  My last question is an overall question of, is this possible to add digital I/O to a Connection Manager made VI.  So if you could repond that would be great.  Thank you for your help.
Message 3 of 8
(4,417 Views)
If you have SIT 4.0, you will see that there is a Shipping Example that demonstrates exactly that. You will see there is really not a lot of code involved in implementing this. It's fairly straight-forward.

One consideration to make about digital IO, however, is that due to hardware limitations, you can't do HW-Timed Single-Point DIO like you can with analog. M-Series boards added hardware-timed digital, but it is buffered, which makes it impossible to use for point-by-point simulations. So the alternative is to simply do software-timed DIO. This is really not as bad as it sounds. There is relatively little latency in polling or updating digital lines, and you should be able to maintain very fast, deterministic loop rates with software-timed DIO. The example (Tank System) that I mentioned uses software-timed DIO.
Jarrod S.
National Instruments
Message 4 of 8
(4,412 Views)
I just realized I may not have answered one of your questions fully:

Yes, it is possible to add digital I/O to a Driver VI scripted by the Connection Manager. The Tank System example uses the designated sequence frames I mentioned in the first post in the Base Rate Loop subVI for its custom Initialize, Read, Write, and Close VIs. This ensures that this code won't be touched, even if you rescript the Driver VI to update the analog IO code.

Jarrod S.
National Instruments
Message 5 of 8
(4,409 Views)
Hello,
 
     Thank you again for the response.  I am going to try out what you suggested Jarrod, it looks like it should definately work.  I greatly appreciate your help.  If I have any other questions I will be sure to bring them up.  Thank you again for the details and the speed. 
 
Michael B
0 Kudos
Message 6 of 8
(4,400 Views)

Hello again,

     Thank you for another quick and detailed response regarding my questions.  I thought that I would have lasted longer with out having to ask a question but I guess I did not make it that long.  I have a new question based on something I ran into while I was preparing to implement what Jarrod had stated in previous posts.   This is regarding the second set of posts that Jarrod and I exchanged based on the second example that I stated with the Digital I/O.  I am going to further explain the example to clarify my question.  I have a Load Bank that is being controlled by digital signals from a LabVIEW Program and National Instruments board.  The user selects a load they want to apply and the corresponding digital I/O "turn on" and that goes to the relay.  What I want to do is add that VI to my already existing SIT Connection Manager VI to have the two programs running at the same time.  Now this is where my problem starts to arrise.  If I put my subVI, Load Bank Control VI, down, buried in the SIT Connection Manager, how do I indirectly control my SubVI from the front panel of my host VI?   By indirectly, I mean using the same methods that I was previously performing to control the VI.  Thank you for your continued help.  

I keep forgetting to state this, but I do have SIT 4.0, lab 8.5, and Real-Time 8.5.

Michael B

0 Kudos
Message 7 of 8
(4,383 Views)
Probably the easiest way to control your existing VI running on the RT Target with the Driver VI from the Host VI is to use Shared Variables. SIT uses a custom TCP communication mechanism for its data transfer, and you won't be able to hook into that to control your subVI. So I'd recommend just using some Shared Variables that your code polls every time it runs. You can then simply bind those Shared Variables to front panel controls on your Host VI to do the control.

So you'll probably need to write a thin wrapper around your load control VI that polls the Shared Variables and writes the control values to the inputs of your subVI. To add the Shared Variable support to your scripted Driver VI, you'll want to use the LabVIEW Project that gets scripted when you script a Driver VI in the Connection Manager targeted to an RT Target (not Driver VI on Localhost). The name of the LabVIEW Project is always modelname_Driver.lvproj, where modelname is the name of your model. The project is always located next to the model DLL you selected in the Connection Manager.

Simply add the Shared Variables to the target in the project, so that they'll get deployed automatically when your Driver VI gets deployed.

Hope this helps!
Jarrod S.
National Instruments
Message 8 of 8
(4,380 Views)