Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P-51D/ACCELEROMETER_VALUE not working for negative values #248

Closed
charliefoxtwo opened this issue Sep 24, 2023 · 6 comments · Fixed by #261
Closed

P-51D/ACCELEROMETER_VALUE not working for negative values #248

charliefoxtwo opened this issue Sep 24, 2023 · 6 comments · Fixed by #261

Comments

@charliefoxtwo
Copy link
Member

charliefoxtwo commented Sep 24, 2023

The output for ACCELEROMETER_VALUE in the P-51 is an integer representation of the g value on the accelerometer. However, bios does not support sending negative values, so this will never send anything below zero. Additionally, bios can only send whole integer values, which are not entirely useful here as the integer range of the gauge is fairly small (-5 through +12), with the operational range of the aircraft smaller still.

Code in question:

local function getAccel()
local returnValue = (GetDevice(0):get_argument_value(175)) * 17 - 5
return returnValue
end
P_51D:defineIntegerFromGetter("ACCELEROMETER_VALUE", getAccel, 65000, "Gauge Values", "Accelerometer")

My suggestion here would be to drop the -5 offset and change the multiplier to 17000. This would give much more granularity to the gauge. The end user would have to do the math on their end to calculate the actual G value ((value / 1000) - 5) but at least they would be able to get a more useful value out of it, and negative values wouldn't simply report as 0.

@WarLord211
Copy link
Member

WarLord211 commented Sep 24, 2023

why not simply make a float out of it?

but i have to look how this is handled in the model itself.
I know from other modules that all mechanical gaues work as float.
i will look deeper into it

@charliefoxtwo
Copy link
Member Author

charliefoxtwo commented Sep 24, 2023

There is ACCELEROMETER_MAIN, which has the gauge value. Perhaps we should just remove ACCELEROMETER_VALUE as it doesn't have any real utility?

P_51D:defineFloat("ACCELEROMETER_MAIN", 175, { 0, 1 }, "Accelerometer", "Accelerometer Main")

@WarLord211
Copy link
Member

This is one of the oldest modules. I never did something like this Code and also had nobody ask for it. It was there and I have left it there

@charliefoxtwo
Copy link
Member Author

This sort of thing appears in a few places. I agree it doesn't have much value. We can remove them and replace them with empty placeholders in the memory map so it doesn't mess up the addresses for everybody else if you want.

local function getRPM()
local returnValue = ((GetDevice(0):get_argument_value(139))*55+55)
return returnValue
end
defineIntegerFromGetter("ENGINE_RPM_VALUE", getRPM, 65000, "Gauge Values", "Engine RPM Value")
local function getEngineTemp()
local returnValue = ((GetDevice(0):get_argument_value(146))*700+100)
return returnValue
end
defineIntegerFromGetter("ENGINE_TEMP_VALUE", getEngineTemp, 65000, "Gauge Values", "Engine Temp Value")
local function getAirspeed()
local returnValue = ((-707.23*(GetDevice(0):get_argument_value(100))^4)+(1843.8*(GetDevice(0):get_argument_value(100))^3)-(647.84*(GetDevice(0):get_argument_value(100))^2)+(810.63*(GetDevice(0):get_argument_value(100)))+100.03)
return returnValue
end
defineIntegerFromGetter("AIRSPEED_VALUE", getAirspeed, 65000, "Gauge Values", "Airspeed Value")
local function getAlt()
local returnValue = ((GetDevice(0):get_argument_value(114))*10000)
return returnValue
end
defineIntegerFromGetter("ALTITUDE_VALUE", getAlt, 65000, "Gauge Values", "Altitude Value")
local function getFuelLev()
local returnValue = ((GetDevice(0):get_argument_value(144))*135)
return returnValue
end
defineIntegerFromGetter("FUEL_LEVEL_VALUE", getFuelLev, 65000, "Gauge Values", "Fuel Level Value")
local function getFuelNeed()
local returnValue = ((GetDevice(0):get_argument_value(145))*135)
return returnValue
end
defineIntegerFromGetter("FUEL_NEEDED_VALUE", getFuelNeed, 65000, "Gauge Values", "Fuel Needed Value")
local function getCIHDG()
local heading = 0
if (GetDevice(0):get_argument_value(128)) <= 0 then
heading = ((180 * (GetDevice(0):get_argument_value(128))) + 360)
else
heading = (180 * (GetDevice(0):get_argument_value(128)))
end
return heading
end
defineIntegerFromGetter("CI_HEADING_VALUE", getCIHDG, 65000, "Gauge Values", "CI Heading Value")
local function getCICMDHDG()
local returnValue = ((GetDevice(0):get_argument_value(129)) * 360)
return returnValue
end
defineIntegerFromGetter("CI_COMMAND_HEADING_VALUE", getCICMDHDG, 65000, "Gauge Values", "CI Commanded Heading Value")

-- Gauge Formulas
local function getManifold()
local returnValue = (GetDevice(0):get_argument_value(32))*65+10
return returnValue
end
defineIntegerFromGetter("MANIFOLD_PRESSURE_VALUE", getManifold, 65000,
"Gauge Values", "Manifold Pressure kg/cm2")
local function getMW50()
local returnValue = (GetDevice(0):get_argument_value(1))*30
return returnValue
end
defineIntegerFromGetter("METHANOL_WATER_PRES_VALUE", getMW50, 65000,
"Gauge Values", "Methanol Water Pres kg/cm2 Read as X.X")
local function getPropPitch()
local returnValue = (GetDevice(0):get_argument_value(30))*63+26
return returnValue
end
defineIntegerFromGetter("PROPELLER_PITCH_DEG_VALUE", getPropPitch, 65000,
"Gauge Values", "Propeller Pitch Degrees")
local function getFuelLevel()
local returnValue = (GetDevice(0):get_argument_value(33))*400
return returnValue
end
defineIntegerFromGetter("FUEL_LEVEL_VALUE", getFuelLevel, 65000,
"Gauge Values", "Fuel Level Liters")
local function getFuelPressure()
local returnValue = (GetDevice(0):get_argument_value(25))*20
return returnValue
end
defineIntegerFromGetter("FUEL_PRESSURE_VALUE", getFuelPressure, 65000,
"Gauge Values", "Fuel Pres kg/cm2 Read as X.X")
local function getOilPressure()
local returnValue = (GetDevice(0):get_argument_value(26))*100
return returnValue
end
defineIntegerFromGetter("OIL_PRESSURE_VALUE", getOilPressure, 65000,
"Gauge Values", "Oil Pressure kg/cm2 Read as X.X or XX.X")
local function getOilTemp()
local returnValue = (GetDevice(0):get_argument_value(28))*130
return returnValue
end
defineIntegerFromGetter("OIL_TEMPERATURE_VALUE", getOilTemp, 65000,
"Gauge Values", "Oil Temp °C")
local function getCoolantTemp()
local returnValue = (GetDevice(0):get_argument_value(27))*130
return returnValue
end
defineIntegerFromGetter("COOLANT_TEMPERATURE_VALUE", getCoolantTemp, 65000,
"Gauge Values", "Coolant Temp °C")
local function getOxygenPressure()
local returnValue = (GetDevice(0):get_argument_value(34))*250
return returnValue
end
defineIntegerFromGetter("OXYGEN_PRESSURE_VALUE", getOxygenPressure, 65000,
"Gauge Values", "Oxygen Pressure kg/cm2")
local function getAirspeed()
local returnValue = (GetDevice(0):get_argument_value(2))*750
return returnValue
end
defineIntegerFromGetter("AIRSPEED_VALUE", getAirspeed, 65000,
"Gauge Values", "Airspeed km/h")
local function getAltitude()
local returnValue = (GetDevice(0):get_argument_value(9))*9999
return returnValue
end
defineIntegerFromGetter("ALTITUDE_VALUE", getAltitude, 65000,
"Gauge Values", "Altitude Meters")
local function getTachometer()
local returnValue = (GetDevice(0):get_argument_value(29))*3200+400
return returnValue
end
defineIntegerFromGetter("TACHOMETER_VALUE", getTachometer, 65000,
"Gauge Values", "Tachometer RPM")
local function getBaro()
local returnValue = (GetDevice(0):get_argument_value(10))*120+920
return returnValue
end
defineIntegerFromGetter("BAROMETRIC_PRESSURE_VALUE", getBaro, 65000,
"Gauge Values", "Barometric Pressure mb")
local function getHDG()
local returnValue = (GetDevice(0):get_argument_value(13))*360
return returnValue
end
defineIntegerFromGetter("COMPASS_HEADING_VALUE", getHDG, 65000,
"Gauge Values", "Compass Heading")

local function getBearing()
local returnValue = (GetDevice(0):get_argument_value(600))*360
return returnValue
end
defineIntegerFromGetter("ARN6_BEARING_VALUE", getBearing, 65000,
"Gauge Values", "ARN-6 Bearing Value")
local function getScale()
local returnValue = (GetDevice(0):get_argument_value(814))*360
return returnValue
end
defineIntegerFromGetter("ARN6_SCALE_VALUE", getScale, 65000,
"Gauge Values", "ARN-6 Scale Value")
local function getMach()
local returnValue = (((-0.1871*(GetDevice(0):get_argument_value(179))^4)+(1.0314*(GetDevice(0):get_argument_value(179))^3)-(1.3069*(GetDevice(0):get_argument_value(179))^2)+(1.5846*(GetDevice(0):get_argument_value(179)))+0.4231)*100)
return returnValue
end
defineIntegerFromGetter("MACH_NUMBER_VALUE_X.XX", getMach, 65000,
"Gauge Values", "Mach Number Value Read As X.XX")
local function getAirspeed()
local returnValue = (((GetDevice(0):get_argument_value(178))*625)+40)
return returnValue
end
defineIntegerFromGetter("AIRSPEED_VALUE", getAirspeed, 65000,
"Gauge Values", "Airspeed Value")
local function getAlt()
local returnValue = (GetDevice(0):get_argument_value(707))*100000
return returnValue
end
defineIntegerFromGetter("ALTITUDE_VALUE", getAlt, 65000,
"Gauge Values", "Altitude Value")
local function getExhTemp()
local returnValue = (GetDevice(0):get_argument_value(12))*1000
return returnValue
end
defineIntegerFromGetter("EXHAUST_TEMP_VALUE", getExhTemp, 65000,
"Gauge Values", "Exhaust Temperature Value")
local function getOilPres()
local returnValue = (GetDevice(0):get_argument_value(112))*100
return returnValue
end
defineIntegerFromGetter("OIL_PRESSURE_VALUE", getOilPres, 65000,
"Gauge Values", "Oil Pressure Value")
local function getFuelFlow()
local returnValue = (GetDevice(0):get_argument_value(531))*10000
return returnValue
end
defineIntegerFromGetter("FUEL_FLOW_VALUE", getFuelFlow, 65000,
"Gauge Values", "Fuel Flow Value")
local function getVolt()
local returnValue = (GetDevice(0):get_argument_value(601))*100
return returnValue
end
defineIntegerFromGetter("DC_VOLTAGE_VALUE", getVolt, 65000,
"Gauge Values", "DC Voltage Value")
local function getLoad()
local returnValue = (GetDevice(0):get_argument_value(602))*100
return returnValue
end
defineIntegerFromGetter("LOADMETER_VALUE", getLoad, 65000,
"Gauge Values", "Loadmeter Value")
local function getTach()
local returnValue = ((5.894*(GetDevice(0):get_argument_value(16))^3)+(3.021*(GetDevice(0):get_argument_value(16))^2)+(101.29*(GetDevice(0):get_argument_value(16)))+0.0758)
return returnValue
end
defineIntegerFromGetter("TACHOMETER_VALUE", getTach, 65000,
"Gauge Values", "Tachometer Value")
local function getHydPres()
local returnValue = (GetDevice(0):get_argument_value(109))*4000
return returnValue
end
defineIntegerFromGetter("HYDRAULIC_PRES_VALUE", getHydPres, 65000,
"Gauge Values", "Hydraulic Pressure Value")
local function getFuelQuant()
local returnValue = (GetDevice(0):get_argument_value(22))*3200
return returnValue
end
defineIntegerFromGetter("FUEL_QUANTITY_VALUE", getFuelQuant, 65000,
"Gauge Values", "Fuel Quantity Value")
local function getOxyPres()
local returnValue = (GetDevice(0):get_argument_value(353))*500
return returnValue
end
defineIntegerFromGetter("OXYGEN_PRESSURE_VALUE", getOxyPres, 65000,
"Gauge Values", "Oxygen Pressure Value")
local function getCockpitAlt()
local returnValue = (GetDevice(0):get_argument_value(114))*50000
return returnValue
end
defineIntegerFromGetter("COCKPIT_ALT_VALUE", getCockpitAlt, 65000,
"Gauge Values", "Cockpit Altitude Value")
local function getHDG()
local heading = 0
if ((360-((GetDevice(0):get_argument_value(711))/0.002778)) + (360-((GetDevice(0):get_argument_value(712))/0.002778))) < 360 then
heading = (360-((GetDevice(0):get_argument_value(711))/0.002778)) + (360-((GetDevice(0):get_argument_value(712))/0.002778))
else
heading = ((360-((GetDevice(0):get_argument_value(711))/0.002778)) + (360-((GetDevice(0):get_argument_value(712))/0.00278))) - 360
end
return heading
end
defineIntegerFromGetter("HEADING_VALUE", getHDG, 65000,"Gauge Values",
"Heading Value")
local function getVVI()
local returnValue = (-1319.8*(GetDevice(0):get_argument_value(24))^5)+(0.00000005*(GetDevice(0):get_argument_value(24))^4)+(4334.8*(GetDevice(0):get_argument_value(24))^3)+(0.0000002*(GetDevice(0):get_argument_value(24))^2)+(2988.1*(GetDevice(0):get_argument_value(24)))+0.0000001
return returnValue
end
defineIntegerFromGetter("VVI_VALUE", getVVI, 65000,
"Gauge Values", "Verticl Velocity VVI")

local function getAirspeed()
local returnValue = (GetDevice(0):get_argument_value(11)) * 1000
return returnValue
end
P_51D:defineIntegerFromGetter("AIRSPEED_MPH_VALUE", getAirspeed, 65000, "Gauge Values", "Airspeed MPH")
local function getAltitude()
local returnValue = (GetDevice(0):get_argument_value(96)) * 100000
return returnValue
end
P_51D:defineIntegerFromGetter("ALTIMETER_VALUE", getAltitude, 65000, "Gauge Values", "Altimeter")
local function getEngineRPM()
local returnValue = (GetDevice(0):get_argument_value(23)) * 4500
return returnValue
end
P_51D:defineIntegerFromGetter("ENGINE_RPM_VALUE", getEngineRPM, 65000, "Gauge Values", "Engine RPM Value")
local function getGyro()
local returnValue = (GetDevice(0):get_argument_value(12)) * 360
return returnValue
end
P_51D:defineIntegerFromGetter("DIRECTIONAL_GYRO_VALUE", getGyro, 65000, "Gauge Values", "Directional Gyro")
local function getHDG()
local returnValue = (GetDevice(0):get_argument_value(1)) * 360
return returnValue
end
P_51D:defineIntegerFromGetter("HEADING_VALUE", getHDG, 65000, "Gauge Values", "Remote Compass Heading")
local function getCRS()
local returnValue = (GetDevice(0):get_argument_value(2)) * 360
return returnValue
end
P_51D:defineIntegerFromGetter("COURSE_VALUE", getCRS, 65000, "Gauge Values", "Remote Compass Course")
local function getFuelPres()
local returnValue = (GetDevice(0):get_argument_value(32)) * 25
return returnValue
end
P_51D:defineIntegerFromGetter("FUEL_PRESSURE_VALUE", getFuelPres, 65000, "Gauge Values", "Fuel Pressure")
local function getHydPres()
local returnValue = (GetDevice(0):get_argument_value(78)) * 2000
return returnValue
end
P_51D:defineIntegerFromGetter("HYDRAULIC_PRESSURE_VALUE", getHydPres, 65000, "Gauge Values", "Hydraulic Pressure")
local function getManifoldPres()
local returnValue = (GetDevice(0):get_argument_value(10)) * 65 + 10
return returnValue
end
P_51D:defineIntegerFromGetter("MANIFOLD_PRESSURE_VALUE", getManifoldPres, 65000, "Gauge Values", "Manifold Pressure")
local function getVacuum()
local returnValue = (GetDevice(0):get_argument_value(9)) * 100
return returnValue
end
P_51D:defineIntegerFromGetter("VACUUM_SUCTION_VALUE", getVacuum, 65000, "Gauge Values", "Vacuum Suction read as X.X or XX.X")
local function getOilTemp()
local returnValue = (GetDevice(0):get_argument_value(30)) * 100
return returnValue
end
P_51D:defineIntegerFromGetter("OIL_TEMPERATURE_VALUE", getOilTemp, 65000, "Gauge Values", "Oil Temperature")
local function getOilPres()
local returnValue = (GetDevice(0):get_argument_value(31)) * 200
return returnValue
end
P_51D:defineIntegerFromGetter("OIL_PRESSURE_VALUE", getOilPres, 65000, "Gauge Values", "Oil Pressure")
local function getAmps()
local returnValue = (GetDevice(0):get_argument_value(101)) * 150
return returnValue
end
P_51D:defineIntegerFromGetter("AMMETER_VALUE", getAmps, 65000, "Gauge Values", "Ammeter")
local function getOxygen()
local returnValue = (GetDevice(0):get_argument_value(34)) * 500
return returnValue
end
P_51D:defineIntegerFromGetter("OXYGEN_PRESSURE_VALUE", getOxygen, 65000, "Gauge Values", "Oxygen Pressure")
local function getLeftFuel()
local returnValue = (GetDevice(0):get_argument_value(155)) * 92
return returnValue
end
P_51D:defineIntegerFromGetter("LEFT_FUEL_TANK_VALUE", getLeftFuel, 65000, "Gauge Values", "Left Fuel Tank Gallons")
local function getRightFuel()
local returnValue = (GetDevice(0):get_argument_value(156)) * 92
return returnValue
end
P_51D:defineIntegerFromGetter("RIGHT_FUEL_TANK_VALUE", getRightFuel, 65000, "Gauge Values", "Right Fuel Tank Gallons")
local function getFuseFuel()
local returnValue = (GetDevice(0):get_argument_value(160)) * 85
return returnValue
end
P_51D:defineIntegerFromGetter("FUSELAGE_FUEL_TANK_VALUE", getFuseFuel, 65000, "Gauge Values", "Fuselage Fuel Tank Gallons")
local function getBaro()
local returnValue = (GetDevice(0):get_argument_value(97)) * 290 + 2810
return returnValue
end
P_51D:defineIntegerFromGetter("BAROMETRIC_PRESSURE_VALUE", getBaro, 65000, "Gauge Values", "Barometric Pressure")
local function getAccel()
local returnValue = (GetDevice(0):get_argument_value(175)) * 17 - 5
return returnValue
end
P_51D:defineIntegerFromGetter("ACCELEROMETER_VALUE", getAccel, 65000, "Gauge Values", "Accelerometer")

@charliefoxtwo
Copy link
Member Author

@WarLord211 what would you like to do here - remove them, or leave them? If we leave them, what would you like to do about the ones that don't work as expected, like the P-51D ACCELEROMETER_VALUE?

@WarLord211
Copy link
Member

WarLord211 commented Sep 27, 2023

stay with what work. delete what not work, without placeholders the following items are made by me without requests.
So i think the impact of the users are negligible.

charliefoxtwo added a commit to charliefoxtwo/dcs-bios that referenced this issue Sep 28, 2023
…lue controls

Adds a control for defining gauge values, which are used in some older aircraft.
charliefoxtwo added a commit to charliefoxtwo/dcs-bios that referenced this issue Sep 28, 2023
…lue controls

Adds a control for defining gauge values, which are used in some older aircraft.
jdahlblom pushed a commit that referenced this issue Sep 29, 2023
…261)

Adds a control for defining gauge values, which are used in some older aircraft.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants