1 #ifndef _CONTROL_MAP_HPP 2 #define _CONTROL_MAP_HPP 3 4 #include <simgear/props/props.hxx> 5 #include "yasim-common.hpp" 6 #include "Vector.hpp" 7 8 namespace yasim { 9 10 11 12 13 class ControlMap { 14 public: 15 ~ControlMap(); 16 17 //! keep this enum in sync with the static vector ControlNames in ControlMap.cpp ! 18 enum ControlType { 19 THROTTLE, 20 MIXTURE, 21 CONDLEVER, 22 STARTER, 23 MAGNETOS, 24 ADVANCE, 25 REHEAT, 26 PROP, 27 BRAKE, 28 STEER, 29 EXTEND, 30 HEXTEND, 31 LEXTEND, 32 LACCEL, 33 INCIDENCE, 34 FLAP0, 35 FLAP1, 36 SLAT, 37 SPOILER, 38 VECTOR, 39 FLAP0EFFECTIVENESS, 40 FLAP1EFFECTIVENESS, 41 BOOST, 42 CASTERING, 43 PROPPITCH, 44 PROPFEATHER, 45 COLLECTIVE, 46 CYCLICAIL, 47 CYCLICELE, 48 ROTORGEARENGINEON, 49 TILTYAW, 50 TILTPITCH, 51 TILTROLL, 52 ROTORBRAKE, 53 ROTORENGINEMAXRELTORQUE, 54 ROTORRELTARGET, 55 ROTORBALANCE, 56 REVERSE_THRUST, 57 WASTEGATE, 58 WINCHRELSPEED, 59 HITCHOPEN, 60 PLACEWINCH, 61 FINDAITOW, 62 }; //! keep this enum in sync with the static vector ControlNames in ControlMap.cpp ! 63 64 65 enum { 66 OPT_SPLIT = 0x01, 67 OPT_INVERT = 0x02, 68 OPT_SQUARE = 0x04 69 }; 70 71 struct PropHandle { 72 char* name {nullptr}; 73 int handle {0}; 74 }; 75 // to identify controls per wing section we need wing object + section id 76 struct ObjectID { 77 void* object {nullptr}; 78 int subObj {0}; 79 }; 80 81 // map control name to int (enum) 82 static ControlType parseControl(const char* name); 83 static ControlType getControlByName(const std::string& name); 84 static std::string getControlName(ControlType c); 85 // create ID from object and optional sub index (e.g. for wing section) 86 static ObjectID getObjectID(void* object, int subObj = 0); 87 88 // add input property for a control to an object 89 90 // same with limits. Input values are clamped to [src0:src1] and then mapped to 91 // [dst0:dst1] before being set on the objects control. 92 void addMapping(const char* inputProp, ControlType control, ObjectID id, int options, float src0, float src1, float dst0, float dst1); 93 94 // Resets our accumulated input values. Call before any 95 // setInput() invokations. 96 void reset(); 97 98 // Sets the specified input (as returned by getPropertyHandle()) to the 99 // specified value. 100 void setInput(int propHandle, float value); 101 102 /// Calculates and applies the settings received since the last reset(). 103 /// dt defaults to a large value used at solve time. 104 void applyControls(float dt=1e6); 105 106 // Returns the input/output range appropriate for the given 107 // control. Ailerons go from -1 to 1, while throttles are never 108 // lower than zero, etc... 109 static float rangeMin(ControlType control); 110 static float rangeMax(ControlType control); 111 112 // Each output record is identified by both an object/type tuple 113 // and a numeric handle. 114 int getOutputHandle(ObjectID id, ControlType control); 115 116 // Sets the transition time for the control output to swing 117 // through its full range. 118 void setTransitionTime(int handle, float time); 119 120 // Retrieves the current value of the control output. Controls 121 // with OPT_SPLIT settable on inputs will have a separately 122 // computed "right side" value. 123 float getOutput(int handle); 124 float getOutputR(int handle); 125 126 // register property name, return handle 127 int getInputPropertyHandle(const char* name); numProperties()128 int numProperties() { return _properties.size(); } 129 PropHandle* getProperty(const int i); 130 131 private: 132 //output data for a control of an object 133 struct OutRec { 134 int id {0}; 135 ControlType control; 136 ObjectID oid; 137 Vector maps; 138 float transitionTime {0}; 139 float oldValueLeft {0}; 140 float oldValueRight {0}; 141 }; 142 struct MapRec { 143 int id {0}; 144 int opt {0}; 145 float val {0}; 146 float src0 {0}; 147 float src1 {0}; 148 float dst0 {0}; 149 float dst1 {0}; 150 }; 151 152 // A list of (sub)Vectors containing a bunch of MapRec objects for 153 // each input handle. 154 Vector _inputs; 155 156 // An unordered list of output settings. 157 Vector _outputs; 158 159 Vector _properties; // list of PropHandle* 160 161 OutRec* getOutRec(ObjectID id, ControlType control); 162 }; 163 164 }; // namespace yasim 165 #endif // _CONTROL_MAP_HPP 166