Custom pitch and roll control inputs

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?

Is there a compelling reason to modify the source code itself rather than using onboard Lua scripting to specify your desired attitude parameters?

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.

1 Like

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.

I’m wondering if you have any advice?

The craft must be in GUIDED mode for that script to work.

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?

What version firmware are you running? EKF3 is the default on the more recent versions that better support GUIDED mode inputs.

I’m running MP 1.3.76 build 1.3.8029.15962 Arduplane V4.2.0dev

Then why is EKF2 enabled?

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

It appears the example was intended for Copters. I’m not sure if the commands work the same for Plane.

Maybe @iampete, who wrote the script and possibly the code exposing the attitude commands can shed some light?

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.

1 Like

I see. Well, I guess my only option is to directly edit one of the existing flightmodes in C++. Thanks a ton for your help @Yuri_Rage and @iampete.