High-Octane Posted March 5, 2004 Report Posted March 5, 2004 Hello people, As of now, my plan.... Is to try to implement codes on Gauges with needle for VB6. and have it working with FSUIPC. And Lately, For a week, I've been visiting around search page and doing a lot of search. Query: 'VB6 GAUGES; GAUGE WITH NEEDLE AT RUNTIME; ROTATING SHAPE OBJECTS AT RUNTIME' and ETC Unfortunately, The answer I always get is, Search Query not matched, or a topic similar to the words. So, I kindly ask for help to anyone who experienced on Gauge code implement and get it working sucessful with FSUIPC... .....Meaning, I would probablly need some assitance to find certain websites containing with good tutorial, Maybe your suggestion for a starter... Any help from you would be much appreciated. Thanks in Advance
rickalty Posted March 5, 2004 Report Posted March 5, 2004 The way I implemented needles on the gauges on my FSPanel app was to draw them using Trig functions. Assuming you've no problem getting the data out from FSUIPC in the first place, here's how I draw the needle for an oil pressure gauge.... If OilPress < 60 Then OilPressAngle = 0 - ((60 - OilPress) * 0.75) Else OilPressAngle = ((OilPress - 60) * 0.75) End If ' On the gauge, 60 psi is a needle angle of zero, or horizontal. The 0.75 ' is a factor to make the angle of the needle match the markings on the ' gauge face. This will be different for every gauge. OilPressAngle = OilPressAngle * (3.1412 / 180) ' Converts the angle from Radians to Degrees picOil.CurrentX = 1500 picOil.CurrentY = 750 ' Sets the center of the needle to the center of the gauge.' picOil is ' the picturebox that has the image of the gauge as its background picOil.Line Step(0 - (500 * Cos(OilPressAngle)), (0 - (500 * Sin(OilPressAngle))))-Step(0 - (250 * Cos(OilPressAngle)), (0 - (250 * Sin(OilPressAngle)))) ' Uses trig to calculate the start and end points of a line at an angle of ' OilPressAngle from 250 twips from the center of the gauge to 500 ' twips from the center of the gauge. I hope this helps. Richard
High-Octane Posted March 5, 2004 Author Report Posted March 5, 2004 Hi Richard First of all, Thank you for your help. I truly appreciate it. Assuming you've no problem getting the data out from FSUIPC in the first place, here's how I draw the needle for an oil pressure gauge.... Well, yes...I dont have any problem getting data out of FSUIPC...But, only part of problem I am having is data that need calculation... . I really need to understand how to use it and solve it if bug occur with my app. I guess it take time to understand it with so many tries or pratices. Trig function look pretty easy to understand.... So basically, I would need to set DIM statement,CALL or IF FSUIPC with values, offset, and etc first before implement trig function. And thats it? did I get my thought right? Again Thank you
rickalty Posted March 5, 2004 Report Posted March 5, 2004 Trig function look pretty easy to understand.... So basically, I would need to set DIM statement,CALL or IF FSUIPC with values, offset, and etc first before implement trig function. And thats it? did I get my thought right? That's right. First you'd dim OilPress as a variable to hold the actual value for the Oil Pressure, and OilPressAngle as a variable to hold the angle you want the needle to point to. Then CALL FSUIPC_Read to actually get the value to go into OilPress. Next you use OilPress to calculate the value for OilPressAngle. In this example, the actual gauge needle is horizontal if the Oil Presure is 60 psi, so a value greater than 60 needs to be a positive angle, a value less than 60 needs to be a negative angle. Now, to work out what angles you need, look at the gauge. In this case, there's a value of 100psi 30 degrees up from horizontal. Thus, a 40psi difference is a 30 degree angle, so I multiply the difference between the actual oil pressure and 60 (Because 60 is a zero angle) by 30/40, or 0.75. This gives me the actual angle in degrees that I need the needle to be deflected by. I convert that to Radians (In the code example the comment said to convert from Radians - that was wrong) and use that value in the trig function. The Oil Pressure gauge is one of those with a disk in the center that the needle sticks out from under, so there's actually two trig functions - one calculates the position where the needle appears from under the disk, one calculates the position of the end of the needle. If you have a gauge where the whole needle is visible, you only need to calculate the end of the needle. Richard
High-Octane Posted March 9, 2004 Author Report Posted March 9, 2004 Richard, Disregard about e-mail I sent you last friday. Actually, I didnt really want to sent e mail. But for entire weekend, for Unknown reasons, I couldn't get through on this forum. Which leaves me no choice for question asked. Anyway, about needle... What I did last weekend, copied your codes into my application, just to figure out how that work. I finally understand how these work. Actually your help and Chris, forgot his last name... but he was one that creates speedometer with sliding bar changing values. Anyway... here the delcaration I typed along with your codes copied. Dim OilPress As Long Dim OilPressAngle As Long Call FSUIPC_Read(&H8B8, 2, VarPtr(OilPress), dwResult Call FSUIPC_Read(dwResult) OilPSI = (OilPress / 65536) CaoOIL.Caption = format(OilPress) If OilPress < 60 Then OilPressAngle = 0 - ((60 - OilPress) * 0.75) Else OilPressAngle = ((OilPress - 60) * 0.75) End If ' On the gauge, 60 psi is a needle angle of zero, or horizontal. The 0.75 ' is a factor to make the angle of the needle match the markings on the ' gauge face. This will be different for every gauge. OilPressAngle = OilPressAngle * (3.1412 / 180) ' Converts the angle from Radians to Degrees picOil.CurrentX = 1500 picOil.CurrentY = 750 ' Sets the center of the needle to the center of the gauge.' picOil is ' the picturebox that has the image of the gauge as its background picOil.Line Step(0 - (500 * Cos(OilPressAngle)), (0 - (500 * Sin(OilPressAngle))))-Step(0 - (250 * Cos(OilPressAngle)), (0 - (250 * Sin(OilPressAngle)))) ' Uses trig to calculate the start and end points of a line at an angle of ' OilPressAngle from 250 twips from the center of the gauge to 500 ' twips from the center of the gauge. Running with FS2002, and my App... I show needle displaying "dead", and is not moving when flying... I show label caption at 0.... and no changing nimber either... Apparently, either way I did wrong calculating or wrote it wrong, maybe you can do a few revising on code i implement Let me know Thanks in Advance
rickalty Posted March 9, 2004 Report Posted March 9, 2004 Hi Arthur. Looks like the problem is up at the beginning here.... Call FSUIPC_Read(&H8B8, 2, VarPtr(OilPress), dwResult Call FSUIPC_Read(dwResult) OilPSI = (OilPress / 65536) CaoOIL.Caption = format(OilPress) If OilPress < 60 Then First, your brackets don't match up, you must have the same number of opening and closing brackets - I can't figure out why it didn't crash in fact :-) Secondly, you've got the call wrong - you have a second Call FSUIPC_Read that doesn't call anything, and you have no process. Here's how I think it should read. Call FSUIPC_Read(&H8B8, 2, VarPtr(OilPress), dwResult) ' Added a final bracket Call FSUIPC_Process(dwResult) 'You had no Process call OilPress = (OilPress / 65536) ' There was an OilPSI variable here undefined CaoOIL.Caption = format(OilPress, "0") ' If you want to use Format, you have to give it a format If OilPress < 60 Then Looks OK from there down. Richard
High-Octane Posted March 9, 2004 Author Report Posted March 9, 2004 Richard, About Brackets.... Actually... on VB form code... I did not forget Bracket. I probablly mistyped it on this forum. So confirm.... Call FSUIPC_Read(&H8B8, 2, VarPtr(OilPress), dwResult ) :lol: But the Label and Needle is still "dead"... Later, running FSInterrogate I discover my expression were wrong... OILPress / 65536 which really should be *55 / 16384 for Engine 1 Oil PSI so how can I write that in code expression ? First attempt: OilPress = Format(OilPress / 16384, "0") :? Needle and Label chanegd at 37... but in set... No fluxuating or anything (like giving an answer of diving from values) I vertify it by turning off Master switch when running FS2002-- Normally needle would be at "0" , but on my application, there is no movement of neddles or any change of labels still same number at 37 so seem like I did write wrong codes or expressionm did I?? :D Thanks :D
rickalty Posted March 9, 2004 Report Posted March 9, 2004 OK, I didn't actually check the address, and that's wrong. The Oil Pressure is at 8BA not 8B8 (which is the oil temp) 55 psi is equal to a reading of 16384 and 220 psi is a reading of 65535, so it is linear - each one psi is 289 on the scale, so after doing Call FSUIPC_Read(&H8BA, 2, VarPtr(OilPress), dwResult ) you can say OilPress = OilPress / 289 CaOIL.Caption=Format(OilPress, "0") You should also be able to then use OilPress to calculate OilPressAngle to put into the trig for the needle. Richard
High-Octane Posted March 9, 2004 Author Report Posted March 9, 2004 Hi Richard... First of all, How did you figure out the expression of 289? did you mean 298? because I divide 65535 into 16384 and I get 297 point something which round up to 298. Unless if I am wrong, could you explain your way of doing that, so I can learn it myself and not need to ask again for different offsets. Secondly, Thank you for the offset correction. Now I can see why I need to get a new pair of glasses :shock: :lol: Lastly, after making a few change Everything works perfect except for one little glitch. (The caption number works good, not the needle) Since I couldn't post Image on this forum out of paint program... I will go ahead and try my best explaining you in words. Let say you re looking at oil psi gauge like you re looking at clock. This would be easier for you to understand where needle is located at (IE: 7 o'clock....8 o'Clock and etc..) Okay, the glitch is....when Running FS2002-- flying the Cessna....The oil PSI starts at 21 PSI, the needle sit at 7 o'click. As I increased thrust.... viewing the caption display changing of 22psi and above until it reached to 60 psi, I assume that is standard PSI rate for most Cessnas. Anyway, after 22 PSI, The needle just skipped over at 9 o'clock and stay there with out changing position...I was expecting for it to fluxuate, without just skipping over (I wasn't epecting for perfect one, but close enough will do) And, not only that.. I am seeing double needles displaying inside the picture box at the same time, one would be at 7 o'clock and another at 9 o'clock. Either way, right after 22psi. or even if it get back at 21PSI. Only way to get it disappear is to close my app and reopen it to have one display of needle, if changing again it will just create double.I was assuming it has something to do with refreshing codes that hasn't declared yet, or do I need to do few adjustment in form properties for Picture Box? I hope you understand the way I explain you. Let me know if you did not. In case you want to observe code that may cause double needles or else. Dim OilPress As Long Dim OilPSIAngle As Long Call FSUIPC_Read(&H8BA, 2, VarPtr(OilPress), dwResult) Call FSUIPC_Read(dwResult) OilPress = OilPress / 289 OilPsiAngle = OilPress CapOil.Caption = Format(OilPress, "0") (The rest of drawing needle code stay the same)
kafka Posted March 10, 2004 Report Posted March 10, 2004 Hi, I'm a Mechatronic Student of Colombia, and i'm restoring a very old simulator named GAT 1. The main idea is to use MSFS as simulation software. It's very important for me to adquire the pitch, heading and bank from MSFS and to send some signals to offests of MSFS. I have some SDK examples, one of them named FSinterrogate by Pete Dowson and works very good, but the VB5.0 code don't runs and i don't know what's happening with VB6.0 If you have some code examples that run good, please send to me. Thanks a lot Cali - Colombia.
High-Octane Posted March 11, 2004 Author Report Posted March 11, 2004 Kafia... I've never used VB5 before, so I wouldn't know if codes for VB6 can work with VB5. Only way I can think of visiting VB fourms, show them the code example out of SDK and maybe some proficent VB user can help you adjust some codes from VB6 into VB5. I have seen them doing that before for others.(not out of SDK but general codes) Hope that help
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