Beat me to it :) Here are two other calculations you'll need, vertical speed error and mach error.
Hi David,
The reason we needed extra special handling of heading errors is that to drive the PID module we want the error to be +/-180. Without some sort of hack you could have a target heading = +1 deg, and a current heading of 359 degrees and come up with an error 1 - 359 = -358 This could totally screw up the math if a gust blows your current heading to +2 and the error then to -1 ... there's a discontinuity there. That is why we need to normalize the heading error to +/- 180. Because we are fiddling with the values anyway, it's easy to compute the heading error, and then in the PID controller we try to drive the heading error to zero.
Now on to your two items below. They aren't strictly needed as written. We don't have to precompute errors and drive those to zero. All we need is a current (or process) value and a target (or reference) value. The PID system will try to make the difference between those become zero.
So for vertical speed, the only problem is that internally we have it in fps and you want fpm for interface convenience. All we have to do with that is:
// Calculate vertical speed in fpm
static SGPropertyNode *vs_fps
= fgGetNode( "/velocities/vertical-speed-fps", true );
static SGPropertyNode *vs_fpm
= fgGetNode( "/autopilot/internal/vert-speed-fpm", true );vs_fpm->setDoubleValue( vs_fps->getDoubleValue() * 60.0 );
Now, just build your PID controller with the <input> property set to /autopilot/internal/vert-speed-fpm, the output value set to /autopilot/settings/vert-speed-fpm (or whatever you want to call it.) Output to /controls/flight/elevator-trim and the system will use elevator trim to try to match the current vs_fpm to the target_vs_fpm.
For mach, it's even simpler, the system has the current mach, you can store the target mach in /autopilot/settings/target-speed-mach or something like that. No need to do anything with helper functions for this. Arguably, it should be the FDM that provides vertical speed in fps but if that doesn't happen in the near term, then I don't see a problem with the autopilot doing a quick conversion for it's own use.
Regards,
Curt.
// Calculate vertical speed error static SGPropertyNode *target_vert_speed = fgGetNode( "/autopilot/settings/vert-speed-fpm", true ); static SGPropertyNode *vert_speed = fgGetNode( "/velocities/vertical-speed-fps", true ); static SGPropertyNode *vs_error = fgGetNode( "/autopilot/internal/vert-speed-error-fpm", true );
vs_error->setDoubleValue( target_vert_speed->getDoubleValue() -
vert_speed->getDoubleValue() * 60.0);
// Calculate mach error static SGPropertyNode *target_mach = fgGetNode( "/autopilot/settings/mach", true ); static SGPropertyNode *mach = fgGetNode( "/velocities/mach", true ); static SGPropertyNode *mach_error = fgGetNode( "/autopilot/internal/mach-error", true );
mach_error->setDoubleValue( target_mach->getDoubleValue() -
mach->getDoubleValue() );
Dave
-- Curtis Olson Intelligent Vehicles Lab FlightGear Project Twin Cities [EMAIL PROTECTED] [EMAIL PROTECTED] Minnesota http://www.menet.umn.edu/~curt http://www.flightgear.org
_______________________________________________ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
