Rise
The Vieneo Province
Loading...
Searching...
No Matches
OrbitPitchControl.h
Go to the documentation of this file.
1#pragma once
2#include "OrbitState.h"
3
4namespace Orbital {
5inline bool AscentPitchControl(const BusState& b,bool engaged,double now,bool airborne,bool frozen)
6{
7 return engaged&&airborne&&!frozen&&b.guidance.valid&&(b.guidance.ascentControl||b.guidance.poweredRendezvous)&&
9}
10struct PitchAllocation { double surface=0,rcsMoment=0,residual=0; };
11// All moments use the live client's lb-m convention. Search the actual tail
12// curve: near stall it need not be monotonic. Surfaces cancel airframe moments;
13// RCS supplies the remaining attitude demand within installed authority.
14template<class TailMoment>
15PitchAllocation AllocatePitch(double desired,double external,double rcsCapacity,
16 double previous,double surfaceLimit,double dt,TailMoment tail)
17{
19 surfaceLimit=(std::clamp)(surfaceLimit,0.0,1.0);
20 previous=(std::clamp)(previous,-surfaceLimit,surfaceLimit);
21 // Existing Rise AFCS surface-rate limit, in normalized deflection/second.
22 const double travel=.45*(std::clamp)(dt,0.0,1.0);
23 const double lo=(std::max)(-surfaceLimit,previous-travel),hi=(std::min)(surfaceLimit,previous+travel);
24 double best=1e100;
25 auto evaluate=[&](double surface) {
26 const double need=desired-external-tail(surface);
27 const double rcs=(std::clamp)(need,-rcsCapacity,rcsCapacity);
28 const double residual=need-rcs;
29 const double scale=(std::max)(1.0,rcsCapacity);
30 const double cost=100*std::pow(residual/scale,2)+std::pow(rcs/scale,2)+1e-5*std::pow(surface-previous,2);
31 if(cost<best) {best=cost;out={surface,rcs,residual};}
32 };
33 // When the entire tail has negligible authority compared with installed
34 // pitch RCS, stow the surface at its normal rate. Do not chase tiny torque
35 // savings with a near-full elevator in orbit. If RCS cannot carry the
36 // residual, retain all available surface authority instead.
37 const double neutralNeed=desired-external-tail(0);
38 const double neutral=tail(0);
39 double tailAuthority=0;
40 for(int i=0;i<=32;++i)tailAuthority=(std::max)(tailAuthority,std::abs(tail(-surfaceLimit+2*surfaceLimit*i/32)-neutral));
41 if(tailAuthority<.01*rcsCapacity&&std::abs(neutralNeed)<.9*rcsCapacity) {
42 evaluate((std::clamp)(0.0,lo,hi));return out;
43 }
44 evaluate(previous);
45 for(int i=0;i<=32;++i)evaluate(lo+(hi-lo)*i/32);
46 const double center=out.surface,width=(hi-lo)/32;
47 for(int i=0;i<=16;++i)evaluate((std::clamp)(center-width+2*width*i/16,lo,hi));
48 return out;
49}
50}
bool AscentPitchControl(const BusState &b, bool engaged, double now, bool airborne, bool frozen)
PitchAllocation AllocatePitch(double desired, double external, double rcsCapacity, double previous, double surfaceLimit, double dt, TailMoment tail)