I’m trying to code a custom pitch and roll controller, where the vehicle’s pitch and roll are dictated by mathematical functions.
In the ArduPlane code, it looks like the plane.nav_roll_cd and plane.nav_pitch_cd variables determine the desired roll and pitch of the plane. However, when I set these variables to integers (ie. plane.nav_roll_cd = 1000; for a roll angle of 10 degrees, since the comments indicate that the variables refer to hundredths of a degree), the plane does not react at all.
I am wondering if anyone is familiar with the C++ coding aspect, or if they know of any other projects that have attempted to do something similar that I could perhaps look at?
The attitude parameters are determined by a neural network, and I’ve found a way to integrate the network into one of the flight modes in the source code. Would Lua scripting be more appropriate for this?
Ok, I doubt you will successfully implement a neural net of any worth within the scripting environment, so modifying the source may be your best bet unless you could offload the computational load to a GCS computer and send MAVLink messages to set the attitude in GUIDED mode.
Unfortunately, the scope of the project involves onboard control so I’m not allowed to communicate with any ground stations. All commands must originate from the aircraft itself.
If scripting or offboard control were your intent, I could be of more help. I’m not as familiar with the control loops for Plane as I should be to assist further. I’d venture a guess that GUIDED mode is still a good place to start.
Hi, I’m trying out Lua scripting, and running the set-angle.lua script (ardupilot/set-angle.lua at master · ArduPilot/ardupilot · GitHub) through Mission Planner with SITL through XPlane10, and while I can get text to display on the MP Messages panel, I can’t seem to get the aircraft to pitch, roll, or yaw according to the angles I set in the script.
Right, it is in Guided, but the aircraft attitude appears to be changing randomly.
Messages log: (setting rpy is message from script)
Setting rpy
Setting rpy
EKF2 IMU1 yaw aligned to GPS velocity
EKF2 IMU0 yaw aligned to GPS velocity
EKF2 IMU1 is using GPS
EKF2 IMU0 is using GPS
EKF2 IMU1 origin set
EKF2 IMU0 origin set
Setting rpy
I’m thinking some other flightmode is interfering with the script?
I’m not sure to be honest, it was always just set to EKF2 by default. I changed the MP parameters list so that EKF2 is disabled and EKF3 is enabled. The aircraft is simply loitering in guided mode however
Right, that example is copter only, we don’t have so many options available on plane yet. You can set a target location from scripting, but that is about it I think.