KHBO Posted March 29, 2006 Report Posted March 29, 2006 Hi Pete, In mean time we've managed to get most things working. However we have a few questions. We are experiencing delays of +- 3 sec on the commands given, probabely due to unefficient programming. Do you have any FSUIPC related tips concerning a more efficient programming? (Note that there is also code included for the acquisition of voltages). Second question: We are getting the voltage values in double format, this means a lot of numbers behind the floating point, however, flightsim requires a Short as input, this means we are loosing all numbers behind the floating point. Currently we devide the voltage input by the max voltage input (so this means max = 1) and * 16348. Is there a more interesting way to cope with this problem? ------------------------ Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick 'Engine 1 Throttle Lever Dim reader1 As AnalogMultiChannelReader Dim myTask1 As New Task myTask1.AIChannels.CreateVoltageChannel("dev1/ai0", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts) myTask1.Control(TaskAction.Verify) reader1 = New AnalogMultiChannelReader(myTask1.Stream) Dim datainput1 As Double(,) datainput1 = reader1.ReadMultiSample(-1) Dim voltage1 As Double = datainput1(0, 0) lblVoltageENG1.Text = voltage1 Dim dwOffset1 As Integer Dim Wel1 As Short = ((voltage1 / 8.73) * 16384) Dim ThrottleToken1 As Integer Dim Result1 As Integer dwOffset1 = &H88C FSUIPC_Write(dwOffset1, Wel1, ThrottleToken1, Result1) myTask1.Dispose() 'Engine 2 Throttle Lever Dim reader2 As AnalogMultiChannelReader Dim myTask2 As New Task myTask2.AIChannels.CreateVoltageChannel("dev1/ai1", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts) myTask2.Control(TaskAction.Verify) reader2 = New AnalogMultiChannelReader(myTask2.Stream) Dim datainput2 As Double(,) datainput2 = reader2.ReadMultiSample(-1) Dim voltage2 As Double = datainput2(0, 0) lblVoltageENG2.Text = voltage2 Dim dwOffset2 As Integer Dim Wel2 As Short = ((voltage2 / 8.73) * 16384) Dim ThrottleToken2 As Integer Dim Result2 As Integer dwOffset2 = &H924 FSUIPC_Write(dwOffset2, Wel2, ThrottleToken2, Result2) myTask2.Dispose() 'Engine 3 Throttle Lever Dim reader3 As AnalogMultiChannelReader Dim myTask3 As New Task myTask3.AIChannels.CreateVoltageChannel("dev1/ai2", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts) myTask3.Control(TaskAction.Verify) reader3 = New AnalogMultiChannelReader(myTask3.Stream) Dim datainput3 As Double(,) datainput3 = reader3.ReadMultiSample(-1) Dim voltage3 As Double = datainput3(0, 0) lblVoltageENG3.Text = voltage3 Dim dwOffset3 As Integer Dim Wel3 As Short = ((voltage3 / 8.73) * 16384) Dim ThrottleToken3 As Integer Dim Result3 As Integer dwOffset3 = &H9BC FSUIPC_Write(dwOffset3, Wel3, ThrottleToken3, Result3 myTask3.Dispose() 'Elevator Position Control Dim reader4 As AnalogMultiChannelReader Dim myTask4 As New Task myTask4.AIChannels.CreateVoltageChannel("dev1/ai3", "", AITerminalConfiguration.Rse, -10, 10, AIVoltageUnits.Volts) myTask4.Control(TaskAction.Verify) reader4 = New AnalogMultiChannelReader(myTask4.Stream) Dim datainput4 As Double(,) datainput4 = reader4.ReadMultiSample(-1) Dim voltage4 As Double = datainput4(0, 0) lblVoltageElevator.Text = voltage4 Dim dwOffset4 As Integer Dim Wel4 As Short = (((voltage4 - (9 / 2)) / (9 / 2)) * 16384) Dim ThrottleToken4 As Integer Dim Result4 As Integer dwOffset4 = &HBB2 FSUIPC_Write(dwOffset4, Wel4, ThrottleToken4, Result4) myTask4.Dispose() FSUIPC_Process(Result1) FSUIPC_Process(Result2) FSUIPC_Process(Result3) FSUIPC_Process(Result4) End Sub FSUIPC_Close() is called in form_closed ------------------------ All comments on the programming are more than welcome to impove the loading time.
Pete Dowson Posted March 29, 2006 Report Posted March 29, 2006 Do you have any FSUIPC related tips concerning a more efficient programming? (Note that there is also code included for the acquisition of voltages). Well, I wouldn't use VB to start with. But after that, as far as FSUIPC is concerned, provinig you keep to the minimum number of process calls needed to do the job, everything else is irrelevant. By this I mean one process call for everything you want to read or write per cycle. Second question: We are getting the voltage values in double format, this means a lot of numbers behind the floating point, however, flightsim requires a Short as input, this means we are loosing all numbers behind the floating point. Currently we devide the voltage input by the max voltage input (so this means max = 1) and * 16348. Is there a more interesting way to cope with this problem? Sorry, I'm not delving into code to find out, but what "short" are you trying to deal with? Aren't you getting enough resolution? If FS only deals with 16k steps for whatever value it is you are talking about, what does it matter about the rest? [LATER] I'm not delving into yuor code in detail, but what on Earth is going on here: FSUIPC_Process(Result1) FSUIPC_Process(Result2) FSUIPC_Process(Result3) FSUIPC_Process(Result4) One "Process" call will deal with ALL queued requests, the others will do nothing at all except waste time switching processes for nothing. That will be wasting 75% of your time! Regards, Pete
Pete Dowson Posted March 29, 2006 Report Posted March 29, 2006 Another quick question. I notice: FSUIPC_Close() is called in form_closed I hope you are not Opening and Closing on every cycle too? Only do this at the beginning and end of your program, or at least only when you want to connect to FS. Oh, and why bother storing the result of each Write and Process operation in different "Result" variables if you don't check them in any case. If you are ignoring them they may as well all be ignored in one variable. If you do get an error in any you shouldn't continue in any case, or you can but it would be rather a waste of time. Pete
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now