brianacooper11 Posted April 18, 2016 Posted April 18, 2016 I'm at wits end with a .lua mod I created to visibly sweep the wings of a 'make flyable' mod, for the Tu-22M3 in particular, but would work for anything. The main file, an avLuaDevice Sweep.lua, basically works well, looks cool, and looks like this: local dev = GetSelf() local update_time_step = 0.035 make_default_activity(update_time_step) local sensor_data = get_base_data() local autoControl = 0 local IAS local TAS local mach local currentSweep = 0.0 local SweepStops = {0.0, 0.222, 1.0} local targetSweepIndex = 0 local targetSweepSize = table.getn(SweepStops) local targetSweep = 0.222 local sweepStep = update_time_step/15 function post_initialize() end function update() currentSweep = get_aircraft_draw_argument_value(7) if autoControl == 1 then mach = sensor_data.getMachNumber() ias = sensor_data.getIndicatedAirSpeed() if mach > 0.8 and currentSweep < .223 then targetsweep = sweepStops(3) set_aircraft_draw_argument_value(7,targetsweep) elseif ias < 110.0 and currentSweep > 0.0 then targetsweep = sweepStops(1) set_aircraft_draw_argument_value(7,targetsweep) elseif ias > 120 and currentSweep < 0.22 then targetsweep = sweepStops(2) set_aircraft_draw_argument_value(7,targetsweep) elseif mach < .78 and currentSweep > .223 then targetsweep = sweepStops(2) set_aircraft_draw_argument_value(7,targetsweep) end end if math.abs(targetSweep-currentSweep) <= sweepStep then set_aircraft_draw_argument_value(7,targetSweep) elseif targetSweep > currentSweep then set_aircraft_draw_argument_value(7,currentSweep+sweepStep) elseif targetSweep < currentSweep then set_aircraft_draw_argument_value(7,currentSweep-sweepStep) end end function SetCommand(command,value) if command == 3001 then -- Increase Sweep --targetSweepIndex = min(targetSweepIndex+1,targetSweepSize) elseif command == 3002 then --targetSweepIndex = max(targetSweepIndex-1,targetSweepSize) end targetSweep = 1.0--SweepStops[targetSweepIndex] end --need_to_be_closed = true It contains a switch, autoControl, that lets you switch back and forth between automatic control based on airspeeds, and manual control. Unlike the real thing, the automatic mode works great, but for manual control, somewhere between these 3001 and 3002 commands: function SetCommand(command,value) if command == 3001 then -- Increase Sweep --targetSweepIndex = min(targetSweepIndex+1,targetSweepSize) elseif command == 3002 then --targetSweepIndex = max(targetSweepIndex-1,targetSweepSize) end targetSweep = 1.0--SweepStops[targetSweepIndex] end and these teensy little inputs in my keyboad definition Input/Tu-22M3/keyboard/default.lua: {combos = {{key = 'PageUp'}}, down = 3001, cockpit_device_id=devices.SWEEP, value_down = 1.0, value_up = 0.0, name = _('Wing Sweep Decrease'), category = _('Systems')}, {combos = {{key = 'PageDown'}}, down = 3002, cockpit_device_id=devices.SWEEP, value_down = 1.0, value_up = 0.0, name = _('Wing Sweep Increase'), category = _('Systems')}, something is not connecting, and I'm just not seeing it. I could use some more eyeballs to spot my error. As best I can tell, SetCommand() never even gets called. My device_init.lua is short: mount_vfs_texture_archives("Bazar/Textures/AvionicsCommon") attributes = { "support_for_cws", } --------------------------------------------- --dofile(LockOn_Options.common_script_path.."KNEEBOARD/declare_kneeboard_device_left.lua") --------------------------------------------- dofile(LockOn_Options.script_path.."devices.lua") MainPanel = {"ccMainPanel", LockOn_Options.script_path.."mainpanel_init.lua", --{{"SWEEP",devices.SWEEP}}, } creators = {} creators[devices.SWEEP] = {"avLuaDevice",LockOn_Options.script_path.."Sweep.lua",{}} devices.lua: local count = 0 local function counter() count = count + 1 return count end devices = {} devices["SWEEP"] = counter() and mainpanel_init.lua: shape_name = "Cockpit_Tu-22M3" is_EDM = true new_model_format = true ambient_light = {255,255,255} ambient_color_day_texture = {72, 100, 160} ambient_color_night_texture = {40, 60 ,150} ambient_color_from_devices = {50, 50, 40} ambient_color_from_panels = {35, 25, 25} dusk_border = 0.4 draw_pilot = false external_model_canopy_arg = 38 use_external_views = true --cockpit_local_point = {2.419, 0.818, 0.0} day_texture_set_value = 0.0 night_texture_set_value = 0.1 local controllers = LoRegisterPanelControls() need_to_be_closed = true I'm using the Su-25T cockpit, and haven't otherwise modified it. Anybody? Bueller? Здравствуйте! Я извиняюсь за грубый язык. Я сделал 'скрипт', чтобы подметать крылья. Автоматические работы, прямой нет! Я стараюсь, чтобы описать проблему. Вы определяете проблему, или предложить? Thanks, Спасибо, Brian
gospadin Posted April 18, 2016 Posted April 18, 2016 I think what you're missing is that your sweep.lua needs to listen for commands 3001/3002. My liveries, mods, and missions for DCS:World M-2000C English Cockpit | Extra Beacons Mod | Nav Kneeboard | Community A-4E
Cadarth Posted April 18, 2016 Posted April 18, 2016 I'm just thinking (fairly new to Lua coding so please bare with me). Going on gospadin's train of thought; if you have to define your wing sweep commands of 3001 and 3002 similar to how they did for engine start and engine stop found in Macro_handler.lua located in Scripts\Aircrafts\_Common\Cockpit\: Line 4: local illumination = 300 Line 5: local iCommandEnginesStart = 309 --Запуск двигателей Line 6: local iCommandEnginesStop = 310 --Остановка двигателей Line 8: local dev = GetSelf() Line 10: -- subscribe Line 11: dev:listen_command(illumination) Line 12: dev:listen_command(iCommandEnginesStart) Line 13: dev:listen_command(iCommandEnginesStop)Which then is used in the A-10C's keyboard input under: Line 3: join(base.keyCommands,{ Line 4: {combos = {{key = 'Home', reformers = {'RWin'}}} , down = iCommandEnginesStart, name = _('Start Procedure'), category = _('Cheat')}, Line 5: {combos = {{key = 'End', reformers = {'RWin'}}} , down = iCommandEnginesStop, name = _('Stop Procedure'), category = _('Cheat')}, Salute! :3
gospadin Posted April 18, 2016 Posted April 18, 2016 It should be as simple as adding this: dev:listen_command(3001) dev:listen_command(3002) near the top of Sweep.lua, after dev has been assigned, but before the definition of SetCommand() My liveries, mods, and missions for DCS:World M-2000C English Cockpit | Extra Beacons Mod | Nav Kneeboard | Community A-4E
kobac Posted April 19, 2016 Posted April 19, 2016 It would be interesting to use it with the Su-24M flyable mod. It's not clear where to place the file. Can you put detailed instructions when finished programming? [sIGPIC][/sIGPIC]Everything is possible ...
brianacooper11 Posted April 19, 2016 Author Posted April 19, 2016 It should work with any swept wing aircraft. There should be a conversation sometime amongst those interested what keys ought to be bound, as the koyboard commands seem pretty full as it is. To update, I've got the two dev:listen() commands in Sweep.lua now, practically at the top. I've cleaned up all remaining errors, and I still can't get it to work. the log entry is this: 00101.505 INFO EDTERRAINGRAPHICS3: force loading finished! 00101.505 INFO EDTERRAINGRAPHICS3: Force loading pipeline 'map'. Radius 20990.400391. Pos=-125553.062500,434.374329,759518.000000! 00101.629 INFO EDTERRAINGRAPHICS3: force loading finished! [b][u][i]00115.215 ERROR Trigger: can't execute trigger, err:"[string "?"]:1: bad argument #1 to 'loadstring' (string expected, got function)"[/i][/u][/b] 00130.364 WARNING LOG: 1 duplicate message(s) skipped. 00130.364 INFO EDTERRAINGRAPHICS3: edtg::DeleteSurfaceRenderItem() 00 That's kind of a vague problem, but I've been thinking about it, and have several more ideas to try. Not done yet though. This was meant as a coding exercise for me, and in that regard, it's perfect! It's been years since I had a regular debugging setup, so it's slow going. Thanks, spaciba, Brian
NRG-Vampire Posted April 19, 2016 Posted April 19, 2016 Does your first lua file work in your tu-22 mod (as automatic movements) ?
brianacooper11 Posted April 20, 2016 Author Posted April 20, 2016 Does your first lua file work in your tu-22 mod (as automatic movements) ? Yes, works perfectly. I've thought about making a youtube video to convince the non-believers, but as it transitions the various speeds, it animates smoothly to the specified position. I gave it a movement speed of about 15 seconds over the total range. Not sure how fast the real thing works, but I read it was not like an F-14 where it's so fast, they can sweep it before the crowd in a flyby. Still trying stuff. I'm basically deleting files and text little by little to find out what deletion makes that message go away. it takes time...
BR55Sevas Posted April 20, 2016 Posted April 20, 2016 Try to check command number and value if command == 3001 and value == 1 then -- Increase Sweep The problem definitely somewhere in your code. Cause my lua devices works perfect in both modes - lua only and linked to dll. [ame] [/ame] Also I strongly recommend you to test your device with some simple debug functions - with pop uped text label, to make sure all your key inputs works. And only after that add your code for wing sweept...and so on. МиГ-29 Fly by wire СДУ Su-27SM second display panel https://www.youtube.com/embed/videoseries?list=PL_2GGwNpWNp_fKXfRtDhIk8s5Jf4a9XHS http://berkuts.ru Пилотажный сервер с роботом | Aerobatic server with PhantomControl
Чарик80 Posted December 4, 2022 Posted December 4, 2022 Did you manage to do a manual folding of the wing?Share it?
Recommended Posts