Binkles Posted December 27, 2015 Report Posted December 27, 2015 Ok, Thanks to Paul, I managed to get my radios working. I've managed to get heading, obs, and ias working for an AP. But having issues with altitude. send_padded("altitude", alt/100,4); // alt was 600 so sends 6 to the function void send_padded ( char* name, int value, int padded) { char buffer [20]; switch (padded){ case 4: sprintf (buffer, "%s:%04d\n", name, value); break; } // lcd2.setCursor(0,3); // lcd2.print("S:"); // lcd2.print(buffer); Serial.write (buffer); } So this would send altitude:0006 to lua if string.match(str, "altitude:(%d)") then state = tonumber(string.match(str, "altitude:(%d)")) current = ((state*65536)*foot/100) ipc.writeUD(0x07d4, current ) end But this isn't setting the correct value, as the plane still shows 00000 If I update the plane it comes up 100 short in my code as well... value = (value/65536)* foot/100 is the code I use to send to the arduino. Literally pulling my hair out, and freaking out about the codes for the vertical speed as well. These are the last two areas that I have left to complete my radio/ap panel.
Paul Henty Posted December 27, 2015 Report Posted December 27, 2015 Looks like you haven't reversed all of the conversion formula on the way out... //current = ((state*65536)*foot/100) //Should be... current = ((state*65536)/foot*100) ipc.writeUD(0x07d4, current ) Paul
Binkles Posted December 29, 2015 Author Report Posted December 29, 2015 Thanks for that, yes it worked :) But it's not accurate - I think because I was trying to truncate it too much (4 characters). But everynow and again it keeps missing a number. So it may display 1900 in the sim, but shows 2000 on the display - and then 2000 on the sim, and still 2000 on the display. I've tried all sorts of conversions... So I've changed the script so it sends offset value/65536 What manipulation can I perform on this to get accurate readings on the lcd and the plane. Or am I at a point where I need to put in an array and all the inaccurate numbers write a correct one) I'm using the feet value of 3.28083989501312
Binkles Posted December 29, 2015 Author Report Posted December 29, 2015 Ok, found it out, and boy do I feel stupid... Sending offset/65536... In the arduino receive the number x x/3*100 does the trick!!!!
Binkles Posted December 29, 2015 Author Report Posted December 29, 2015 Social commentary again :) Ok, so I have changed it a little, as I was still missing jumps, and now have reading the values working 100% up to FL400. Problem is in the sending back.. ipc.control(65892,1) should be the code to send to increase the ap altitude correct? I've tried offset writes, but gremlins start to appear after a bit of use. I would rather send offsets, but yeah.... I'm not having much joy.
spokes2112 Posted December 29, 2015 Report Posted December 29, 2015 A little over my head but maybe try... (psuedo) I would try AP_PANEL_ALTITUDE_SET - 66105 Disp = Pre calced/written value on the display If Disp <> FS_AP_Alt value then ipc.control(66105, Disp) End
Binkles Posted December 29, 2015 Author Report Posted December 29, 2015 Thanks for that, The displaying of it works if I use the p3d radio dials. It's using my arduino radio dials, I can't seem to send a correct value back.
Paul Henty Posted December 29, 2015 Report Posted December 29, 2015 I think this is probably a rounding error. The value is stored in the Flight Sim as Metres * 65536. Converting from feet may leave a tiny rounding error if there is not enough precision. So for example if you convert 800 feet to metres * 65536 (using your feet conversion above) you get: 15980298.24 But the .24 will be ignored as the offset is an integer. So converting back the integer part (15980298) you get 799.999988 not 800. You could mess with rounding functions but an easier trick is just to add 1 to the converted value to push the metre value up to the next 1/65536 of a metre. This should be enough to tip the rounding error to the 'other side'. For example adding one to 15980298.24 = 15980299.24, which is written as 15980299 to Flight Sim. Converting this back gives 800.000038 which is basically the value you are looking for. TL;DR - Probably a rounding issue: Try this: current = ((state*65536)/foot*100)+1 ipc.writeUD(0x07d4, current ) If that still gives some glitches when you test you can safely add 2 instead. BTW - You'll need to use the proper Feet conversion value in and out. Don't use 3! Paul
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