shibekora Posted December 28, 2020 Report Posted December 28, 2020 I am very new for scripting lua file. So, I am sorry for my inquiry may be out of question. I have registered version of FSUIPC6 as attached log file (sorry for the allowable size, I have cut same lines in the middle), my sim is P3D V5.1 HF1, and the aircraft is QW787. Since I could got my purpose successfully with PMDG737 on which I could move throttle and yoke by motorized servo in autopilot condition utilizing mobiflight and arduino, I am trying to get same thing with QW787 too. However, there are no information on the related offset as in PMDG. Only things I could get are Lvars that are shown in QW's document. I have checked which Lvars are the ones necessary for getting the information about the condition of autopilot, and real movement of aileron and elevator by utilizing Spad.next. Eventually, I have got the Lvars as follows; QW_MCP_L_AP_Button ; 1 or 0 QW_aileron_left ; numerial with + QW_elevator_left; numerical with + Reviewing this forum, and documents as FSUIPC Lua Library.pdf, FSUIPC Lua Plug-Ins.pdf and so on in the FSUIPC folder. I have tried to make following lua file named ap_qw.lua. function ap_on("L:QW_MCP_L_AP_Button", value) value=ipc.readLvar("L:QW_MCP_L_AP_Button") ipc.writeUW("66C0", value) end function servo_ai("L:QW_aileron_left", value) value=ipc.readLvar("L:QW_aileron_left") ipc.writeUW("66C1", value) end function servo_el ("L:QW_elevator_left", value) value=ipc.readLvar("L:QW_elevator_left") ipc.writeUW("66C2", value) end event.Lvar("L:QW_MCP_L_AP_Button", 100, "ap_on", value) event.Lvar("L:QW_aileron_left", 100, "servo_ai", value) event.Lvar("L:QW_elevator_left", 100, "servo_el", value) I have copied this file into the folder of C:\Users\shibe_fsx\Documents\Prepar3D v5 Add-ons\FSUIPC6. Then, start sim, I have got log file above mentioned and had attached ini file in which I could see the lines [LuaFiles] 1=ap_qw [Auto] 1=ap_qw as stated in the FSUIPC document. Lines of [LuaFiles] were automatically set. Lines of [Auto] were set by myself. During running the sim I made several different options in recording log so as written in the log file. In case of running mobiflight, read command was repeatedly appeared. However, I could not see any figure changes related to Lvars. They are all "0" in offset of 66C1, 66C2 even though those figures are changing according to the real movement of aileron and elevator in the sim. Again, I am very new, so my script should be wrong. Any advice would be very appreciated. Moto Miyawaki FSUIPC6.ini mod_FSUIPC6.log
Pete Dowson Posted December 28, 2020 Report Posted December 28, 2020 First off, you are misunderstanding the types of values. In these lines ipc.writeUW("66C0", value) ipc.writeUW("66C1", value) ipc.writeUW("66C2", value) You are reading a 16-bit (2-byte) Word (UW = Unsigned Word) into successive BYTES, 66C0, 66C1 and 66C2. So the next byte is being overwritten each time. If you want to read Words you need to allow 2-bytes for each -- so 66C0, 66C2, 66C4 etc. Or, if you only need 8 bits (for values in range 0-255) then use ipc.writeUB instead. However, are the aileron and elevator LVars the actual poistion values? If so they would be Signed, not Unsigned (with 0 as centre). So you'd need SW instead of UW in any case. Second, you are misreading the definition of the functions being called: function ap_on("L:QW_MCP_L_AP_Button", value)function servo_ai("L:QW_aileron_left", value)function servo_el ("L:QW_elevator_left", value) The parameters are places which RECEIVE values from the Event. You do NOT provide the variable name -- the Event does! Just define your functions as function ap_on(var, value)function servo_ai(var, value)function servo_el (var, value) but it would be far more efficient for you to use the value supplied. The value has already been read by the event and supplied for you, yet you do: value=ipc.readLvar("L:QW_MCP_L_AP_Button") value=ipc.readLvar("L:QW_aileron_left") value=ipc.readLvar("L:QW_elevator_left") which just overwrites value with the same value! Just delete thse lines! If you really don't want to use any of the parameters supplied for you you can define the functions with no parameters -- (). Also, you are not actually running your plug-in in any case. This is wrong: [Auto] 1=ap_qw The Auto sections are for commands to be executed automatically. "ap_qw" is not a command, but a filename. It should be [Auto] 1=Lua ap_qw which is the command to run that Lua file. The documentation does show this . In fact, I think most of these errors are caused by a lack of reading, perhaps more carefully, the documentation and examples provided. Finally, try using the facilities to log LVars so you can see the values you should be using. There's an assignable control to list them, and a provided Lua plug-in to monitor them and log changes as they occur. Pete
shibekora Posted December 28, 2020 Author Report Posted December 28, 2020 Thank you Pete for your so quick and polite advice. I will do try again upon your advice. According to the real value of aileron and elevator of Lvar, I think they should be signed one too as you said. However as fur as reviewing the figures of them in Spad.next, they are changing in between + side proportionally to the full yoke movement. For me, it does not matter, must thing is "proportional to", they could be modified or calibrated in mobiflight. Anyway, thank you again for your kind advice. Moto. Miyawaki
shibekora Posted December 30, 2020 Author Report Posted December 30, 2020 Today, I have tried autopilot flight with modified lua file adviced by Pete. Everything was done very well as I wanted. After take off, pushing AP button, then yoke was started to be driven by servo motor as same as in sim. During flight yoke moved according to the yoke motion in sim. Before landing, servo driven was disconnected by disengaging AP by disengage bar. That was fun and the circumstance as I wanted. Simflight has been to be much much motivated. Some modifications of offset value and calibration on mobiflight were necessary for coming to above condition. They were not matter but let me know more about lua and offset. Thank you Pete again. Moto. Miyawaki
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