I am currently looking for a way to control a plane using a LUA script.
In general my target is to let one plane follow another one much like it is currently available for copters in follow mode.
If I understood that correctly since Arduplane 4.2 the command vehicle:set_target_throttle_rate_rpy
is available to control the plane in certain flight modes. In my opinion and for my use case the downside of this command is that I have to run control loops for throttle, roll-, pitch- and yaw-rate which I find a bit complicated for what I would like to archive.
For Arducopter there are commands like vehicle:set_target_angle_and_climbrate or vehicle:set_target_location which would allow a much easier control.
Is there a way to control the plane using LUA in a similay way to using a RC control? e.g. putting the plane in FBWA/FBWB and sending throttle/speed, target roll, target pitch/height or just sending target speed + target direction + target height?
I hope someone can give me a hint or send me in the right direction for further research. Although I am using Arduplane since at least 3 years as a user, looking at the actual code, using scripting and trying to do something outside of the standard features is new to me
The scripts there command aerobatic maneuvers, and surely a subset of those methods can be leveraged to your use.
I am not well versed in ArduPlane (or follow mode for that matter), so I’m afraid I can’t be of specific help with respect to scripted formation flying.
I think it may be possible to use GUIDED mode and set the target as the other aircraft’s location while keeping the speed similar (modulating it to keep a safe distance, and keeping in mind that any mismatched turn geometry will cause variations in follow distance). This method will require the use of a GCS to monitor both aircraft and send the commands.
Thank you for your suggestions.
I was also looking at the aerobatics examples and the use of control loops for pitch, roll, yaw, height scared be a bit to be honest, especially considering that there must be some form of control loop within the code to stabilize the plane doing the movement requested by vehicle:set_target_throttle_rate_rpy
After a bit more research into guided mode I found the following mavlink commands available for Arduplane that would fit my use case perfectly:
MAV_CMD_GUIDED_CHANGE_SPEED
MAV_CMD_GUIDED_CHANGE_ALTITUDE
MAV_CMD_GUIDED_CHANGE_HEADING
Would it be possible to provide a similar interface for lua scripts or is there a way to “inject” mavlink messages using lua?