diff --git a/models/fhw/effectors/rcs_generic/include/rcs_build_trail.hh b/models/fhw/effectors/rcs_generic/include/rcs_build_trail.hh index 2194c069..42f0bd20 100644 --- a/models/fhw/effectors/rcs_generic/include/rcs_build_trail.hh +++ b/models/fhw/effectors/rcs_generic/include/rcs_build_trail.hh @@ -16,8 +16,6 @@ PROGRAMMERS: #ifndef CML_RCS_BUILD_TRAIL_HH #define CML_RCS_BUILD_TRAIL_HH -#include "rcs_scale_factor_interface.hh" - /***************************************************************************** RcsBuildUpTrailOffJetData Purpose:(Jet-specific data for RcsBuildUpTrailOff) @@ -25,15 +23,24 @@ Purpose:(Jet-specific data for RcsBuildUpTrailOff) class RcsBuildUpTrailOffJetData { public: - double rise_time{0.0}; /* (s) Rise time */ - double decay_time{0.0}; /* (s) Decay time */ - double decay_time_abort{0.0}; /* (s) Decay time when post LAS abort */ - double tf_build_up{1.0}; /* (--) Thrust factor from the build-up model */ - double tf_trail_off{1.0}; /* (--) Thrust factor from the trail-off model */ + double rise_time; /* (s) Rise time */ + double decay_time; /* (s) Decay time */ + double decay_time_abort; /* (s) Decay time when post LAS abort */ + double tf_build_up; /* (--) Thrust factor from the build-up model */ + double tf_trail_off; /* (--) Thrust factor from the trail-off model */ - RcsBuildUpTrailOffJetData() = default; + RcsBuildUpTrailOffJetData() + : + rise_time(0.0), + decay_time(0.0), + decay_time_abort(0.0), + tf_build_up(1.0), + tf_trail_off(1.0) + {} }; +#include "rcs_scale_factor_interface.hh" + /***************************************************************************** RcsBuildUpTrailOff Purpose:(Models RCS jets' build-up to full thrust and trail-off to zero thrust) @@ -48,14 +55,16 @@ class RcsBuildUpTrailOff const double & current_time; /* (s) Current time */ public: - bool active{false}; /* (--) Flag to enable the build-up/trail-off model */ + bool active; /* (--) Flag to enable the build-up/trail-off model */ RcsBuildUpTrailOff( RcsScaleFactorInterface& interface_, RcsBuildUpTrailOffJetData * const jet_, const double& time); - RcsBuildUpTrailOff & operator = ( const RcsBuildUpTrailOff &) = delete; - RcsBuildUpTrailOff( const RcsBuildUpTrailOff &) = delete; virtual ~RcsBuildUpTrailOff() = default; virtual void build_up_trail_off_effects(); + + private: + RcsBuildUpTrailOff & operator = ( const RcsBuildUpTrailOff &); + RcsBuildUpTrailOff( const RcsBuildUpTrailOff &); }; -#endif \ No newline at end of file +#endif diff --git a/models/fhw/effectors/rcs_generic/include/rcs_generic.hh b/models/fhw/effectors/rcs_generic/include/rcs_generic.hh index c44d8b01..c268aada 100644 --- a/models/fhw/effectors/rcs_generic/include/rcs_generic.hh +++ b/models/fhw/effectors/rcs_generic/include/rcs_generic.hh @@ -26,9 +26,10 @@ PROGRAMMERS: #ifndef CML_RCS_GENERIC_HH #define CML_RCS_GENERIC_HH -#include #include #include +#include "cml/models/utilities/cml_message/include/cml_message.hh" +#include "jeod/models/utils/math/include/vector3.hh" #include "cml/models/utilities/subscriptions/include/subscriptions.hh" // Forward declaration @@ -42,7 +43,7 @@ Purpose:( The manager-level object for the overall RcsGeneric model) *****************************************************************************/ class RcsGeneric : public SubscriptionBase { protected: - const double * cm{nullptr}; /* (--) + const double * cm; /* (--) pointer to the 3-array representing the position of center of mass of the vehicle in the structural frame. */ const unsigned int num_propellant_components; /* (--) @@ -67,23 +68,23 @@ class RcsGeneric : public SubscriptionBase { std::vector groups; /* (--) RCS jet groups */ /****** Inputs ******/ - bool mult_jet_flag{false}; /* (--) + bool mult_jet_flag; /* (--) Flag if multiple jet effects on thrust and flow rates are to be enabled. SET AT INITIALIZATION ONLY. */ - bool calc_flow_rate{false}; /* (--) + bool calc_flow_rate; /* (--) Flag indicating whether flow rate should be calculated based on thrust, specific impulse and mixture ratio. Can only be used with mono or bi-propellants. Will result in an override of any default settings for jet component-flow-rates. INITIALIZATION ONLY. */ public: /****** Inputs ******/ - bool self_impingement{false}; /* (--) Flag indicating whether impingement is on.*/ + bool self_impingement; /* (--) Flag indicating whether impingement is on.*/ - bool apply_thrust_factor_per_jet{false}; /* (--) + bool apply_thrust_factor_per_jet; /* (--) On = per jet thrust factor is provided by external model or data. System level setting passed through to all jets.*/ - double imp_ref_center[3]{}; /* (m) + double imp_ref_center[3];/* (m) Point in Vehicle Structural frame about which the impingement torques are referenced. Used at runtime and only if self_impingement set. */ @@ -92,15 +93,15 @@ class RcsGeneric : public SubscriptionBase { mag_and_uvec = 1, // force magnitude and unit vector vector = 2 // force vector }; - InputForce input_force{input_force_error}; /* (--) + InputForce input_force; /* (--) Flag indicating method of user input for jet force */ - double time_step{0.0}; /* (s) + double time_step; /* (s) The cycle rate of the rcs_gen module. Set here at initialization and subsequently accessed by RcsGroup, RcsJet and RcsPropPod.*/ - unsigned int seed{0}; /* (--) Seed for random number generator */ + unsigned int seed; /* (--) Seed for random number generator */ std::mt19937 generator; /* (--) Random number generator; using mt19937 rather than the default generator to avoid the problem of correlation with low seeds on uniform @@ -111,44 +112,47 @@ class RcsGeneric : public SubscriptionBase { #endif /****** Outputs ******/ - double force[3]{}; /* (N) sum of the jet forces */ - double torque[3]{}; /* (N*m) sum of the jet torques */ - double total_imp_force[3]{}; /* (N) sum of the jet self impingement forces */ - double total_imp_torque[3]{}; /* (N*m) sum of the self impingement jet torques */ + double force[3]; /* (N) sum of the jet forces */ + double torque[3]; /* (N*m) sum of the jet torques */ + double total_imp_force[3]; /* (N) sum of the jet self impingement forces */ + double total_imp_torque[3];/* (N*m) sum of the self impingement jet torques */ std::vector sum_component_consumptions; /* (kg) sum of the propellant component consumptions. NOTE - this is public for the purposes of data-logging only. It is considered read-only. In particular, the size of this vector must not be changed.*/ - double sum_consumption{0.0}; /* (kg) sum of the propellant consumptions */ - double sum_time{0.0}; /* (s) sum of the jet on times */ - size_t num_jets{0}; /* (count) number of jets at initialization (output only).*/ + double sum_consumption; /* (kg) sum of the propellant consumptions */ + double sum_time; /* (s) sum of the jet on times */ + size_t num_jets; /* (count) number of jets at initialization (output only).*/ explicit RcsGeneric (const unsigned int num_propellant_components_); ~RcsGeneric() override = default; - RcsGeneric (const RcsGeneric& rhs) = delete; - RcsGeneric & operator = (const RcsGeneric& rhs) = delete; - virtual void initialize( double time_step_in, + virtual void initialize( double time_step, const double * center_of_mass); void update( const int * rcs_command); void update( const bool * rcs_command); - const double * get_cm() const {return cm;} - bool get_calc_flow_rate() const {return calc_flow_rate;} - double get_prop_loss_on(unsigned int ii) const {return prop_loss_on.at(ii);} - double get_prop_loss_off(unsigned int ii) const {return prop_loss_off.at(ii);} + const double * get_cm() {return cm;} + bool get_calc_flow_rate() {return calc_flow_rate;} + double get_prop_loss_on(unsigned int ii) {return prop_loss_on.at(ii);} + double get_prop_loss_off(unsigned int ii) {return prop_loss_off.at(ii);} void set_prop_loss_on( unsigned int ix, double value); void set_prop_loss_off( unsigned int ix, double value); - void set_mult_jet_flag (bool new_value); - void set_calc_flow_rate(bool new_value); + void set_mult_jet_flag (bool mult_jet_flag); + void set_calc_flow_rate(bool calc_flow_rate); protected: void compute_force_and_fuel(); void apply_self_impingement(); - bool update_part_I(const void * rcs_command); + bool update_part_I(const void *); void update_part_II(); void check_mult_jet_flag_init(); + + private: + // Not implemented: + RcsGeneric (const RcsGeneric& rhs); + RcsGeneric & operator = (const RcsGeneric& rhs); }; -#endif \ No newline at end of file +#endif diff --git a/models/fhw/effectors/rcs_generic/include/rcs_generic_classes.hh b/models/fhw/effectors/rcs_generic/include/rcs_generic_classes.hh new file mode 100644 index 00000000..4a0393ee --- /dev/null +++ b/models/fhw/effectors/rcs_generic/include/rcs_generic_classes.hh @@ -0,0 +1,9 @@ +#ifndef CML_RCS_GENERIC_CLASSES_HH +#define CML_RCS_GENERIC_CLASSES_HH + +#include "rcs_generic.hh" +#include "rcs_prop_pod.hh" +#include "rcs_group.hh" +#include "rcs_jet.hh" + +#endif diff --git a/models/fhw/effectors/rcs_generic/include/rcs_group.hh b/models/fhw/effectors/rcs_generic/include/rcs_group.hh index 89786927..e49bb36c 100644 --- a/models/fhw/effectors/rcs_generic/include/rcs_group.hh +++ b/models/fhw/effectors/rcs_generic/include/rcs_group.hh @@ -18,6 +18,8 @@ PROGRAMMERS: #define CML_RCS_GROUP_HH #include +#include "cml/models/utilities/cml_message/include/cml_message.hh" +#include "cml/models/utilities/math_utils/include/math_utils.hh" /***************************************************************************** RcsGenericModel @@ -25,38 +27,38 @@ Purpose:(Jet models) *****************************************************************************/ class RcsJetGroup { protected: - double consumption_epsilon{1.0e-12}; /* (--) + double consumption_epsilon; /* (--) value for comparing consumption-ratio sum against the value 1. The components should sum to 1 +/- consumption_epsilon. */ const unsigned int & num_prop_components; /* (--) reference to the number of propulsion components as defined in RcsGeneric.*/ - bool blow_down{false} ; /* (--) + bool blow_down ; /* (--) Flag indicating if the thruster blow down model should be used for this module, Yes = use model */ public: /****** Inputs ******/ // Control flags: - bool propc_use_isp{false}; /* (--) + bool propc_use_isp; /* (--) Determines whether to use Isp or mass-flow for propellant consumption calculations. */ // General inputs - double signal_delay_time{0.0}; /* (s) Delay time from command to start of actuation */ - double on_dead_time{0.0}; /* (s) + double signal_delay_time; /* (s) Delay time from command to start of actuation */ + double on_dead_time; /* (s) Time from when the jet's motor is activated until the thrust is seen.*/ - double off_dead_time{0.0}; /* (s) + double off_dead_time; /* (s) Time from when the jet's motor is activated until the thrust starts to be reduced. */ - double build_up_time{0.0}; /* (s) Time taken to build up to full thrust */ - double trail_off_time{0.0}; /* (s) Time taken to trail off from full thrust */ - double min_on_time{0.0}; /* (s) Min allowed time between command on and off */ - double min_off_time{0.0}; /* (s) + double build_up_time; /* (s) Time taken to build up to full thrust */ + double trail_off_time; /* (s) Time taken to trail off from full thrust */ + double min_on_time; /* (s) Min allowed time between command on and off */ + double min_off_time; /* (s) Min allowed time between burn completion and new burn start */ // Specialized inputs, not always needed: - double mixture_ratio{0.0} ; /* (--) + double mixture_ratio ; /* (--) (Ratio) of fuel to oxidizer: fuel/oxidizer. Used when RcsGeneric::num_prop_comp = 2 AND RcsGeneric::calc_flow_rate = true AND @@ -76,29 +78,32 @@ class RcsJetGroup { std::vector bd_isp_coef; /* (--) coefficients for blowdown isp calc. Used only when blow_down set */ - double bd_pressure_limit{0.0}; /* (N/m2) + double bd_pressure_limit; /* (N/m2) limit below which blowdown jets stop functioning. Used only when blow_down set */ /****** Work space ******/ - bool buffer_flag{false} ; /* (--) Flag if buffering of commands is required */ - unsigned int buffer_on_size{0} ; /* (--) buffer size for on commands */ - unsigned int buffer_off_size{0}; /* (--) buffer size for off commands */ - double delay_time_on{0.0}; /* (s) + bool buffer_flag ; /* (--) Flag if buffering of commands is required */ + unsigned int buffer_on_size ; /* (--) buffer size for on commands */ + unsigned int buffer_off_size; /* (--) buffer size for off commands */ + double delay_time_on; /* (s) The delay into an rcs cycle before a command is executed = Modulus of total_on_delay / cycle time, note this is NOT a user input */ - double delay_time_off{0.0}; /* (s) + double delay_time_off; /* (s) The delay into an rcs cycle before a command off is executed = Modulus of total_off_delay / cycle time, note this is NOT a user input */ - explicit RcsJetGroup( const unsigned int & num_prop_components_); - RcsJetGroup (const RcsJetGroup& rhs) = delete; - RcsJetGroup & operator = (const RcsJetGroup& rhs) = delete; + explicit RcsJetGroup( const unsigned int & num_prop_components); void initialize (double time_step); void set_blow_down( bool blow_down_); - bool get_blow_down() const {return blow_down;} - unsigned int get_num_prop_components() const {return num_prop_components;} + bool get_blow_down() {return blow_down;} + unsigned int get_num_prop_components() {return num_prop_components;} + + private: + // Not implemented: + RcsJetGroup (const RcsJetGroup& rhs); + RcsJetGroup & operator = (const RcsJetGroup& rhs); }; #endif diff --git a/models/fhw/effectors/rcs_generic/include/rcs_jet.hh b/models/fhw/effectors/rcs_generic/include/rcs_jet.hh index b2fc0a91..f82eb982 100644 --- a/models/fhw/effectors/rcs_generic/include/rcs_jet.hh +++ b/models/fhw/effectors/rcs_generic/include/rcs_jet.hh @@ -16,6 +16,10 @@ PROGRAMMERS: #include #include +#include "cml/models/utilities/cml_message/include/cml_message.hh" +#include "jeod/models/utils/math/include/vector3.hh" +#include "jeod/models/utils/math/include/matrix3x3.hh" +#include "jeod/models/utils/quaternion/include/quat.hh" #include "rcs_prop_pod.hh" #include "rcs_group.hh" @@ -34,9 +38,9 @@ class RcsJet { // is given its own reference: const double & time_step; /* (s) reference to RcsGeneric time_step. */ - double isp{0.0}; /* (s) Specific impulse. Set only if blow_down NOT set */ - double isp_g{0.0}; /* (m/s) isp * g at earth surface. */ - const double g_at_earth_surface{9.80665}; /* (m/s2) g at earth surface. */ + double isp; /* (s) Specific impulse. Set only if blow_down NOT set */ + double isp_g; /* (m/s) isp * g at earth surface. */ + const double g_at_earth_surface; /* (m/s2) g at earth surface. */ std::vector component_flow_rate; /* (kg/s) Propellant flow rates for each propellant component assuming only one @@ -48,31 +52,38 @@ class RcsJet { std::vector component_consumption;/* (kg) Work space for prop consumption during delta_time_on maximum for each propellant component */ + std::vector sum_component_consumption;/* (kg) + Accumulated values of component_consumption, provides pre-component + consumption over the duration of the simulation.*/ + double sum_consumption; /* (kg) + accumulated values of component_consumption across all components. + Provides total consumption by the jet over the duration of the + simulation.*/ - double force_hat[3]{}; /* (--) + double force_hat[3]; /* (--) Unit-vector force direction. */ - double T_str_to_case[3][3]{{1.0, 0.0, 0.0},{0.0, 1.0, 0.0},{0.0, 0.0, 1.0}}; /* (--) + double T_str_to_case[3][3]; /* (--) transformation matrix from structural frame to a frame oriented such that the nominal force is oriented along the x-axis. y-axis and z-axis are ambiguous but not important.*/ - bool force_hat_changed{true}; /* (--) + bool force_hat_changed; /* (--) set to true when force_hat is changed externally, used by generate_force_direction_matrix.*/ - double force_cl_with_err{0.0}; /* (N) + double force_cl_with_err; /* (N) force_cl + force_cl_err. */ - double force_hat_with_err[3]{}; /* (--) + double force_hat_with_err[3]; /* (--) A direction unit-vector including the directional errors.*/ - double cone_angle_err{0.0}; /* (rad) + double cone_angle_err; /* (rad) Angle of rotation of dispersed force_hat away from force_hat */ - double azimuth_angle_err{0.0}; /* (rad) + double azimuth_angle_err; /* (rad) Angle of rotation of dispersed force_hat in plane perpendiculer to force_hat */ public: /****** Inputs AND Outputs ******/ - double force[3]{}; /* (N) + double force[3]; /* (N) Force applied during a time step. It is also an Input during initialization if input_force=2) */ @@ -83,20 +94,20 @@ class RcsJet { Calc_Fire, // calculate errors when a jet begins a new fire Calc_Always // calculate errors whenever the jet is on }; - RCSJetError error{No_Errors}; /* (--) switch for random jet error implementation */ + RCSJetError error; /* (--) switch for random jet error implementation */ - double location[3]{}; /* (m) position vector of the jet in structural frame */ - double force_cl{0.0}; /* (N) + double location[3]; /* (m) position vector of the jet in structural frame */ + double force_cl; /* (N) Force along the center line of the jet Set his value as an input only if: ((RcsGeneric::input_force == RcsGeneric::mag_and_uvec) AND (RcsJetGroup::blow_down == false)). */ - double force_mag_std_dev{0.0}; /* (--) + double force_mag_std_dev; /* (--) Force magnitude error standard deviation as a fraction of the nominal center-line thrust. Used only if: (error != No_Errors) */ - double force_mag_bias_frac{0.0}; /* (--) + double force_mag_bias_frac; /* (--) Force magnitude error bias as a fraction of nominal center-line-thrust Total force error = force_cl * (force_bias_frac + random * force_std_dev_frac) @@ -106,50 +117,50 @@ class RcsJet { Vector = 0, Angle = 1 }; - RcsDirectionError direction_error{Vector}; /* (--) + RcsDirectionError direction_error; /* (--) switch for determining which method to use for dispersing directional aspect of force error. */ - double force_cl_err{0.0}; /* (N) + double force_cl_err; /* (N) Error in force magnitude along the jet centerline. Input only in case of error = Input_Errors. */ - double force_hat_err[3]{}; /* (--) + double force_hat_err[3]; /* (--) Error in force direction. Will be calculated if random noise added, will be an input otherwise. No need to be set if: (error != No_Errors) AND ((force_hat_std_dev != [0,0,0]) OR (force_axial_std_dev > 0) */ - double force_hat_std_dev[3]{}; /* (--) + double force_hat_std_dev[3];/* (--) Force direction error standard deviation as a fraction of the unit direction vector Set only if: (error != No_Errors) */ - double force_hat_std_mean[3]{}; /* (m) + double force_hat_std_mean[3];/* (m) Force direction error standard mean Set only if: (error != No_Errors) */ - bool direction_dispersion{false}; /* (--) + bool direction_dispersion; /* (--) Flag indicating whether the nominal force_hat vector should have a dispersion applied to it. Defaults to false.*/ - double cone_angle_disp{0.0}; /* (rad) + double cone_angle_disp; /* (rad) Angle of rotation of dispersed force_hat away from force_hat. Used to represent a relatively constant dispersion rather than a random error. For errors, use cone_angle_std and cone_angle_bias.*/ - double azimuth_angle_disp{0.0}; /* (rad) + double azimuth_angle_disp; /* (rad) Angle of rotation of dispersed force_hat in plane perpendicular to force_hat. Used to represent a relatively constant dispersion rather than a random error. For random errors, azimuth angle is automatically generated as a random value between 0 and pi.*/ - double cone_angle_bias{0.0}; /* (rad) + double cone_angle_bias; /* (rad) Fixed component used in computing cone_angle_err. */ - double cone_angle_std_dev{0.0}; /* (rad) + double cone_angle_std_dev; /* (rad) Standard deviation of random distribution used in computing cone_angle_err. */ - double base_impingement_force[3]{}; /* (N) + double base_impingement_force[3]; /* (N) Basis for computation of self-impingement force, structural frame referenced. Scaled to provide scaled_impingement_force. */ - double base_impingement_torque[3]{}; /* (N*m) + double base_impingement_torque[3]; /* (N*m) Basis for computation of self-impingement torque, about impingement reference centeri, referenced to the structural frame. Scaled to provide scaled_impingement_torque. */ @@ -158,8 +169,8 @@ class RcsJet { Failed_Off = 0, // jet never fires Failed_On = 1 // jet continuously fires }; - RcsJetFailure failure{No_Failure}; /* (--) Monitoring jet failures.*/ - double thrust_factor{0.0}; /* (--) + RcsJetFailure failure; /* (--) Monitoring jet failures.*/ + double thrust_factor; /* (--) Per jet thrust factor (used if bool apply_thrust_factor_per_jet is on) */ /****** Work space + Pointers + Structures ******/ @@ -169,52 +180,50 @@ class RcsJet { Status_BuildUp = 2, Status_TrailOff = 3 }; - RcsJetStatus status{Status_Off}; /* (--) jet status */ - double on_com_time{0.0}; /* (s) + RcsJetStatus status; /* (--) jet status */ + double on_com_time; /* (s) Time since on command input not including any buffered time, i.e. on_com_time = 0 during the first time step that an rcs jet force is applied and is incremented by time_step while in build up or on*/ - double off_com_time{0.0}; /* (s) + double off_com_time; /* (s) Time since off command input not including any buffered time, i.e. off_com_time = 0 during the first time step that an rcs jet force is not applied and is incremented by time_step while in trail off or off*/ - double on_com_time1{0.0}; /* (s) + double on_com_time1; /* (s) Time since on command input not including any buffered time, i.e. on_com_time = 0 during the first time step that an rcs jet force is applied and is incremented by time_step while in build up or on*/ - double off_com_time1{0.0}; /* (s) + double off_com_time1; /* (s) Time since off command input not including any buffered time, i.e. off_com_time = 0 during the first time step that an rcs jet force is not applied and is incremented by time_step while in trail off or off*/ - double time_left_in_trailoff{0.0}; /* (s) Time left in trail off */ - double delta_time_on{0.0}; /* (s) Work space for time jet is on */ - double scaled_force{0.0}; /* (N) + double time_left_in_trailoff; /* (s) Time left in trail off */ + double delta_time_on; /* (s) Work space for time jet is on */ + double scaled_force; /* (N) Scaled Force due to thrust degradation when multiple jets are firing; is equal to force_cl * thrust_factor */ - double total_delay_on{0.0}; /* (s) Total delay before turning jets on */ - double total_delay_off{0.0}; /* (s) Total delay before turning jets off */ + double total_delay_on; /* (s) Total delay before turning jets on */ + double total_delay_off; /* (s) Total delay before turning jets off */ /****** Outputs ******/ std::list commands; /* (--) Jet command buffer to accomodate delays that are > time_step*/ - bool command{false}; /* (--) Current command-on status. */ - int nfired{0}; /* (--) number of times this jet has fired */ - double sum_time{0.0}; /* (s) total time over which this jet is fired */ - double torque[3]{}; /* (N*m) Torque applied during a time step */ - double scaled_impingement_force[3]{}; /* (N) + bool command; /* (--) Current command-on status. */ + int nfired; /* (--) number of times this jet has fired */ + double sum_time; /* (s) total time over which this jet is fired */ + double torque[3]; /* (N*m) Torque applied during a time step */ + double scaled_impingement_force[3]; /* (N) Scaled value of base_impingement_force. */ - double scaled_impingement_torque[3]{}; /* (N*m) + double scaled_impingement_torque[3]; /* (N*m) Scaled value of base_impingement_torque. */ RcsJet( RcsGeneric & rcs_system_, RcsPropPod & prop_pod_, RcsJetGroup & group_); - RcsJet (const RcsJet& rhs) = delete; - RcsJet & operator = (const RcsJet& rhs) = delete; void initialize(); - void update (bool new_command); + void update (bool command_); void compute_jet_forces(); void compute_prop_consumption(); void get_force_direction(double force_dir[3]); @@ -225,8 +234,10 @@ class RcsJet { void set_force_direction( double force_dir_x, double force_dir_y, double force_dir_z); void scale_self_impingement(); - void set_isp( double isp_); - double get_isp() const {return isp;} + void set_isp( double new_isp); + double get_isp() {return isp;} + + const double & get_sum_consumption() const {return sum_consumption;} protected: void compute_component_flow_rates(); void blow_down(); @@ -236,5 +247,10 @@ class RcsJet { void apply_direction_error(); void apply_direction_dispersion(); void switch_status( RcsJetStatus new_status); + + private: + // Not implemented: + RcsJet (const RcsJet& rhs); + RcsJet & operator = (const RcsJet& rhs); }; -#endif \ No newline at end of file +#endif diff --git a/models/fhw/effectors/rcs_generic/include/rcs_prop_pod.hh b/models/fhw/effectors/rcs_generic/include/rcs_prop_pod.hh index cc6743c3..e3b45e47 100644 --- a/models/fhw/effectors/rcs_generic/include/rcs_prop_pod.hh +++ b/models/fhw/effectors/rcs_generic/include/rcs_prop_pod.hh @@ -19,6 +19,7 @@ PROGRAMMERS: #define CML_RCS_PROP_POD_HH #include +#include "cml/models/utilities/cml_message/include/cml_message.hh" #include "cml/models/dynamics/mass/dynamic_mass/include/dynamic_mass_body_properties.hh" /***************************************************************************** @@ -41,7 +42,7 @@ class RcsPodComponent{ Mass consumed in this time-step. For monitoring only.*/ double * consumable_mass; /* (kg) Consumable mass remaining. For consistency only.*/ - bool using_dyn_mass{false}; /* (--) + bool using_dyn_mass; /* (--) Indicates whether there is a true Dyn-Mass interface or whether the model is using the fake one provided here. Defaults to false (using fake) until one is provided. */ @@ -56,7 +57,7 @@ class RcsPodComponent{ flow_rate_sf.at(2) is the scale factor when 3 jets are firing. Use if RcsJetGroup::propc_use_isp = false and RcsGeneric::mult_jet_flag = true */ - double sum_consumption{0.0}; /* (kg) + double sum_consumption; /* (kg) Sum of all propellant consumed in this component.*/ explicit RcsPodComponent( unsigned int max_num_jets_on); @@ -65,9 +66,9 @@ class RcsPodComponent{ void incr_mass_consumed_step(double incr) {*mass_consumed_step += incr;} protected: - void set_dyn_mass_interface( DynamicMassBodyPropertiesInterface & dyn_mass_interface); + void set_dyn_mass_interface( DynamicMassBodyPropertiesInterface & interface); bool mass_available(); - void increment_mass_consumption( double jet_consumption); + void increment_mass_consumption( double consumption); private: // Don't declare copy constructor and operator to allow @@ -86,25 +87,25 @@ Purpose:(Propulsion Pod feeding some number of RCS jets. *****************************************************************************/ class RcsPropPod{ protected: - double mass_epsilon{1.0e-12}; /* (kg) mass at which mass=0.0 is reasonable approx.*/ - double momentum_epsilon{1.0e-12}; /* (N*s) + double mass_epsilon; /* (kg) mass at which mass=0.0 is reasonable approx.*/ + double momentum_epsilon; /* (N*s) minimum equivalent momentum to register having a jet needed.*/ const double & time_step; /* (s) reference to the time-step in RcsGeneric. */ const unsigned int max_num_jets_on; /* (--) The maximum number of jets that may be on at a time. This should be the size of the thrust_factor vector.*/ - bool using_dyn_mass{false}; /* (--) + bool using_dyn_mass; /* (--) Defaults to false; is set to true if any of the dynamic-mass interfaces are assigned to real dynamic-masses. */ public: /****** Controls ****/ - bool continue_thrust_after_depletion{false}; /* (--) + bool continue_thrust_after_depletion; /* (--) Flag used when the model is used to deplete mass, but it is not desirable for mass-depletion to end the thrust profile. Used only when "using_dyn_mass". Default: false, i.e. thrusters stop when they run out of propellant.)*/ - bool fail_on_depleted_mass{false}; /* (--) + bool fail_on_depleted_mass; /* (--) Flag used to cause an automatic health-status transition to HealthFail if the string exhausts all of any component of its propellant (e.g. all of its fuel). This flag has no effect if "continue_thrust_after_depletion" @@ -117,10 +118,10 @@ class RcsPropPod{ HealthSuspect = 2, HealthFail = 3 }; - PodHealth health{HealthUndefined}; /* (--) Used for marking the health-status of a pod.*/ + PodHealth health; /* (--) Used for marking the health-status of a pod.*/ /****** Inputs ******/ - double nominal_thrust{0.0} ; /* (N) + double nominal_thrust ; /* (N) Thrust level used to determine the thrust factor array, Thrust_factor array is indexed according to equivalent number of nominal_thrust jets being fired. @@ -129,7 +130,7 @@ class RcsPropPod{ the thrust-factor array index. Note that this is likely to be the same as c[0] for the blow-down model. Needed only if RcsGeneric::mult_jet_flag set */ - double pressure{0.0}; /* (N/m2) + double pressure; /* (N/m2) pressure used for blowdown model (from ext source) */ std::vector thrust_factor;/* (--) @@ -147,24 +148,22 @@ class RcsPropPod{ // ********** Outputs ********** - double sum_consumption{0.0}; /* (kg) + double sum_consumption; /* (kg) Sum of all propellant consumed for all components. */ /****** Work space + Pointers + Structures ******/ - double equiv_momentum{0.0}; /* (N*s) + double equiv_momentum; /* (N*s) Working space to determine how many jets are on. Equal to the time jets from each pod are on times the thrust for each jet */ - unsigned int num_jets_on{0}; /* (--) Number of jets firing from a prop pod */ + unsigned int num_jets_on; /* (--) Number of jets firing from a prop pod */ - RcsPropPod( unsigned int max_num_jets_on_, + RcsPropPod( unsigned int max_num_jets_on, unsigned int num_components_, - const double & time_step_); + const double & time_step); virtual ~RcsPropPod() = default; - RcsPropPod (const RcsPropPod& rhs) = delete; - RcsPropPod & operator = (const RcsPropPod& rhs) = delete; - void set_dyn_mass_interface( unsigned int component_index, + void set_dyn_mass_interface( unsigned int component_ix, DynamicMassBodyPropertiesInterface & dyn_mass_interface); void activate_dyn_mass(); void deactivate_dyn_mass(); @@ -172,11 +171,16 @@ class RcsPropPod{ bool mass_available(); void increment_mass_consumption( std::vector & jet_consumption); void compute_jets_on( bool mult_jet_flag ); - double get_flow_rate_scale_factor( const unsigned int component_index) const; - double get_thrust_factor() const; - unsigned int get_max_num_jets_on() const {return max_num_jets_on;} + double get_flow_rate_scale_factor( const unsigned int component_index); + double get_thrust_factor(); + unsigned int get_max_num_jets_on(); void set_thrust_factor(unsigned int index, double value); - bool is_healthy() const { return health != HealthFail;} + bool is_healthy(){ return (health != HealthFail);} + + private: + // Not implemented: + RcsPropPod (const RcsPropPod& rhs); + RcsPropPod & operator = (const RcsPropPod& rhs); }; -#endif \ No newline at end of file +#endif diff --git a/models/fhw/effectors/rcs_generic/include/rcs_scale_factor_interface.hh b/models/fhw/effectors/rcs_generic/include/rcs_scale_factor_interface.hh index b19733e9..0a73c16c 100644 --- a/models/fhw/effectors/rcs_generic/include/rcs_scale_factor_interface.hh +++ b/models/fhw/effectors/rcs_generic/include/rcs_scale_factor_interface.hh @@ -17,12 +17,17 @@ Purpose:(Jet-specific data for RcsScaleFactorInterface) class RcsScaleFactorInterfaceJet { public: - bool rcs_valve_open{false}; /* (--) true: Jet valve is open + bool rcs_valve_open; /* (--) true: Jet valve is open false: Jet valve is closed */ - double rcs_thrusting_start_time{-1.0}; /* (s) Sim-time when the jet valve opened */ - double rcs_thrusting_stop_time{-1.0}; /* (s) Sim-time when the jet valve closed */ + double rcs_thrusting_start_time; /* (s) Sim-time when the jet valve opened */ + double rcs_thrusting_stop_time; /* (s) Sim-time when the jet valve closed */ - RcsScaleFactorInterfaceJet() = default; + RcsScaleFactorInterfaceJet() + : + rcs_valve_open(false), + rcs_thrusting_start_time(-1.0), + rcs_thrusting_stop_time(-1.0) + {} }; /***************************************************************************** @@ -34,10 +39,10 @@ class RcsScaleFactorInterface public: const unsigned int num_jets; /* (--) Number of jets in the system */ - double valve_rise_time{0.0}; /* (s) + double valve_rise_time; /* (s) Time required for the solenoid to generate a magnetic field strong enough to open the valve */ - double valve_decay_time{0.0}; /* (s) + double valve_decay_time; /* (s) Time required for the solenoid's magnetic field to weaken and allow the valve to close */ @@ -49,11 +54,15 @@ class RcsScaleFactorInterface RcsScaleFactorInterface( const unsigned int num_jets_) : - num_jets(num_jets_) + num_jets(num_jets_), + valve_rise_time(0.0), + valve_decay_time(0.0) {} virtual ~RcsScaleFactorInterface() = default; - RcsScaleFactorInterface(const RcsScaleFactorInterface&) = delete; - RcsScaleFactorInterface & operator= (const RcsScaleFactorInterface&) = delete; + + private: + RcsScaleFactorInterface(const RcsScaleFactorInterface&); + RcsScaleFactorInterface & operator= (const RcsScaleFactorInterface&); }; -#endif \ No newline at end of file +#endif diff --git a/models/fhw/effectors/rcs_generic/src/rcs_build_trail.cc b/models/fhw/effectors/rcs_generic/src/rcs_build_trail.cc index 094e40a4..1a33089f 100644 --- a/models/fhw/effectors/rcs_generic/src/rcs_build_trail.cc +++ b/models/fhw/effectors/rcs_generic/src/rcs_build_trail.cc @@ -2,9 +2,6 @@ PURPOSE: (Simulates the effects of RCS thruster build-up and trail-off.) -LIBRARY DEPENDENCIES: - ((cml/models/utilities/cml_message/src/cml_message.cc)) - PROGRAMMERS: (((Michael McCarthy) (OSR) (Jul 2019) (ANTARES) (CM RCS Refactor, removed C interfacing, split scale factors model into @@ -14,9 +11,8 @@ LIBRARY DEPENDENCIES: ******************************************************************************/ #include "../include/rcs_build_trail.hh" -#include "../include/rcs_scale_factor_interface.hh" -#include +#include // min #include "cml/models/utilities/cml_message/include/cml_message.hh" RcsBuildUpTrailOff::RcsBuildUpTrailOff( RcsScaleFactorInterface& interface_, @@ -25,7 +21,8 @@ RcsBuildUpTrailOff::RcsBuildUpTrailOff( RcsScaleFactorInterface& interface_, : interface(interface_), jet(jet_), - current_time(time) + current_time(time), + active(false) { // NULL check if (jet == nullptr) @@ -37,9 +34,7 @@ RcsBuildUpTrailOff::RcsBuildUpTrailOff( RcsScaleFactorInterface& interface_, void RcsBuildUpTrailOff::build_up_trail_off_effects() { - if (!active) { - return; - } + if (!active) return; for (unsigned int id = 0; id < interface.num_jets; id++) { @@ -56,4 +51,4 @@ void RcsBuildUpTrailOff::build_up_trail_off_effects() (jet[id].decay_time - interface.valve_decay_time)), 1.0); } } -} \ No newline at end of file +} diff --git a/models/fhw/effectors/rcs_generic/src/rcs_generic.cc b/models/fhw/effectors/rcs_generic/src/rcs_generic.cc index 6607b9a5..9524df34 100644 --- a/models/fhw/effectors/rcs_generic/src/rcs_generic.cc +++ b/models/fhw/effectors/rcs_generic/src/rcs_generic.cc @@ -12,9 +12,6 @@ PURPOSE: (The front-end of the rcs-generic model, which provides a Robert Bailey/LinCom/87, Douglas Hamilton/RSOC/95 and partially based on rcs_generic by Willian Othon/LinCom/93) -LIBRARY DEPENDENCIES: - ((cml/models/utilities/cml_message/src/cml_message.cc)) - REFERENCE: ((Trick code - rcs_orbiter.c by John Whynott/McDonnell Douglas/91, Robert Bailey/LinCom/87, Douglas Hamilton/RSOC/95) @@ -70,19 +67,13 @@ ASSUMPTIONS AND LIMITATIONS: ((Gary Turner) (OSR) (Apr 2017) (Antares) (Conversion to Object-oriented))) **********************************************************************/ -#include "cml/models/utilities/cml_message/include/cml_message.hh" #include "cml/models/utilities/math_utils/include/math_utils.hh" -#include "cml/models/utilities/subscriptions/include/subscriptions.hh" #include "../include/rcs_generic.hh" #include "../include/rcs_prop_pod.hh" #include "../include/rcs_group.hh" #include "../include/rcs_jet.hh" -#include "jeod/models/utils/math/include/vector3.hh" - -#include - /***************************************************************************** Constructor Purpose:() @@ -90,12 +81,31 @@ Purpose:() RcsGeneric::RcsGeneric( const unsigned int num_propellant_components_) : + cm (nullptr), num_propellant_components(num_propellant_components_), prop_loss_on(num_propellant_components, 0.0), prop_loss_off(num_propellant_components, 0.0), + jets(), + prop_pods(), + groups(), + mult_jet_flag(false), + calc_flow_rate(false), + self_impingement(false), + apply_thrust_factor_per_jet(false), + imp_ref_center{0.0, 0.0, 0.0}, + input_force( input_force_error), + time_step(0.0), + seed(0), normal(0.0, 1.0), uniform(-1.0, 1.0), - sum_component_consumptions(num_propellant_components, 0.0) + force{0.0, 0.0, 0.0}, + torque{0.0, 0.0, 0.0}, + total_imp_force{0.0, 0.0, 0.0}, + total_imp_torque{0.0, 0.0, 0.0}, + sum_component_consumptions(num_propellant_components, 0.0), + sum_consumption(0.0), + sum_time(0.0), + num_jets(0) { subscribe_name = "RcsGeneric:"; } @@ -141,24 +151,24 @@ RcsGeneric::initialize( generator.seed(seed); - for (const auto * jet : jets) { - if (jet == nullptr) { + for (unsigned int ii=0; ii< jets.size(); ii++) { + if (jets.at(ii) == nullptr) { CMLMessage::fail( __FILE__,__LINE__,"Invalid configuration\n", "One of the jets pointers is NULL.\n" "This vector must be populated with valid pointers.\n"); } } - for (const auto * prop_pod : prop_pods) { - if (prop_pod == nullptr) { + for (unsigned int ii=0; ii< prop_pods.size(); ii++) { + if (prop_pods.at(ii) == nullptr) { CMLMessage::fail( __FILE__,__LINE__,"Invalid configuration\n", "One of the prop-pod pointers is NULL.\n" "This vector must be populated with valid pointers.\n"); } } - for (const auto * group : groups) { - if (group == nullptr) { + for (unsigned int ii=0; ii< groups.size(); ii++) { + if (groups.at(ii) == nullptr) { CMLMessage::fail( __FILE__,__LINE__,"Invalid configuration\n", "One of the group pointers is NULL.\n" @@ -175,11 +185,11 @@ RcsGeneric::initialize( else { // no change in thrust due to number of jets active, // thrust factor[0] always 1.0 - for (auto * prop_pod : prop_pods) { - prop_pod->thrust_factor[0] =1.0; + for (unsigned int ii=0; ii < prop_pods.size(); ii++) { + prop_pods[ii]->thrust_factor[0] =1.0; /* and flow rate scale factor[0] always 1.0 */ - for (auto & component : prop_pod->components) { - component.flow_rate_sf[0] = 1.0; + for (unsigned int jj=0; jj< prop_pods[ii]->components.size(); jj++) { + prop_pods[ii]->components[jj].flow_rate_sf[0] = 1.0; } } } @@ -198,8 +208,8 @@ RcsGeneric::initialize( //***************************************************************************** // initialize each of the groups //***************************************************************************** - for (auto * group : groups) { - group->initialize(time_step); + for (unsigned int ii=0; ii< groups.size() ; ii++) { + groups.at(ii)->initialize(time_step); } //***************************************************************************** @@ -293,8 +303,10 @@ RcsGeneric::update_part_I( return false; } // Clear all pod data from last cycle - for (auto * prop_pod : prop_pods) { - prop_pod->reset_cycle(); + for (std::vector::iterator pod_it = prop_pods.begin(); + pod_it != prop_pods.end(); + ++pod_it) { + (**pod_it).reset_cycle(); } return true; } @@ -303,8 +315,10 @@ void RcsGeneric::update_part_II() { // Determine how many jets are on for calculation of the thrust factor */ - for (auto * prop_pod : prop_pods) { - prop_pod->compute_jets_on(mult_jet_flag); + for (std::vector::iterator pod_it = prop_pods.begin(); + pod_it != prop_pods.end(); + ++pod_it) { + (**pod_it).compute_jets_on(mult_jet_flag); } /*****************************************************/ @@ -344,16 +358,18 @@ RcsGeneric::compute_force_and_fuel() jeod::Vector3::initialize(force); jeod::Vector3::initialize(torque); - for (auto * jet : jets) { - jet->compute_jet_forces(); + for (std::vector::iterator jet_it = jets.begin(); + jet_it != jets.end(); + ++jet_it) { + (**jet_it).compute_jet_forces(); - jeod::Vector3::incr( jet->force, force); - jeod::Vector3::incr( jet->torque, torque); + jeod::Vector3::incr( (**jet_it).force, force); + jeod::Vector3::incr( (**jet_it).torque, torque); - jet->compute_prop_consumption(); + (**jet_it).compute_prop_consumption(); for (unsigned int ii = 0; ii < num_propellant_components; ++ii) { - const double jet_component_step_consump = - jet->get_component_consumption(ii); + double jet_component_step_consump = + (**jet_it).get_component_consumption(ii); sum_component_consumptions[ii] += jet_component_step_consump; sum_consumption += jet_component_step_consump; } @@ -390,10 +406,12 @@ ASSUMPTIONS AND LIMITATIONS: void RcsGeneric::apply_self_impingement() { - for (auto * jet : jets) { - jet->scale_self_impingement(); - jeod::Vector3::incr( jet->scaled_impingement_force, total_imp_force); - jeod::Vector3::incr( jet->scaled_impingement_torque, total_imp_torque); + for (std::vector::iterator jet_it = jets.begin(); + jet_it != jets.end(); + ++jet_it) { + (**jet_it).scale_self_impingement(); + jeod::Vector3::incr( (**jet_it).scaled_impingement_force, total_imp_force); + jeod::Vector3::incr( (**jet_it).scaled_impingement_torque, total_imp_torque); } /******************************************************************************/ @@ -483,4 +501,4 @@ RcsGeneric::set_calc_flow_rate(bool new_value) else { calc_flow_rate = new_value; } -} \ No newline at end of file +} diff --git a/models/fhw/effectors/rcs_generic/src/rcs_group.cc b/models/fhw/effectors/rcs_generic/src/rcs_group.cc index 89bae1f8..e6e71e5c 100644 --- a/models/fhw/effectors/rcs_generic/src/rcs_group.cc +++ b/models/fhw/effectors/rcs_generic/src/rcs_group.cc @@ -5,9 +5,6 @@ PURPOSE: (The RcsJetGroup provides a convenient mechanism for grouping had several instances of RCS_MODEL that needed instantiating; this object represents a very similar concept to RCS_MODEL.) -LIBRARY DEPENDENCIES: - ((cml/models/utilities/cml_message/src/cml_message.cc)) - PROGRAMMERS: (((Gary Turner) (OSR) (April 2017) (Antares) (initial object-oriented implementation)) @@ -15,11 +12,8 @@ LIBRARY DEPENDENCIES: **********************************************************************/ #include -#include -#include +#include // abs #include "../include/rcs_group.hh" -#include "cml/models/utilities/cml_message/include/cml_message.hh" -#include "cml/models/utilities/math_utils/include/math_utils.hh" /***************************************************************************** @@ -28,8 +22,27 @@ Constructor RcsJetGroup::RcsJetGroup( const unsigned int & num_prop_components_) : + consumption_epsilon (1.0e-12), num_prop_components (num_prop_components_), - isp_prop_comp_ratio(num_prop_components, 0.0) + blow_down (false), + propc_use_isp(false), + signal_delay_time(0.0), + on_dead_time(0.0), + off_dead_time(0.0), + build_up_time(0.0), + trail_off_time(0.0), + min_on_time(0.0), + min_off_time(0.0), + mixture_ratio (0.0), + isp_prop_comp_ratio(num_prop_components, 0.0), + bd_force_coef(), + bd_isp_coef(), + bd_pressure_limit(0.0), + buffer_flag(false), + buffer_on_size (0), + buffer_off_size(0), + delay_time_on(0.0), + delay_time_off(0.0) {} @@ -46,9 +59,9 @@ RcsJetGroup::initialize( /* Set up command buffers and initialize delays */ /************************************************/ /* total on delay is sum of signal delay and valve reaction time (dead_time) */ - const double total_on_delay = std::max(0.0, signal_delay_time + on_dead_time); + double total_on_delay = std::max(0.0, signal_delay_time + on_dead_time); /* total off delay is sum of signal delay and valve reaction time (dead_time) */ - const double total_off_delay = std::max(0.0, signal_delay_time + off_dead_time); + double total_off_delay = std::max(0.0, signal_delay_time + off_dead_time); // Check to see if a buffer is needed: // if on or off delays are equal or greater than one time_step, then @@ -58,8 +71,14 @@ RcsJetGroup::initialize( // buffer size is the number of full time-steps necessary before a command // will be seen - buffer_on_size = static_cast(total_on_delay / time_step); - buffer_off_size = static_cast(total_off_delay / time_step); + buffer_on_size = static_cast( + MathUtils::divide_protected( total_on_delay, + time_step, + 0.0, true)); + buffer_off_size = static_cast( + MathUtils::divide_protected( total_off_delay, + time_step, + 0.0, true)); /* delay time = remainder of last time_step before jet is turned on or off */ delay_time_on = total_on_delay - buffer_on_size * time_step; @@ -70,12 +89,13 @@ RcsJetGroup::initialize( // usage. if (propc_use_isp) { if (num_prop_components > 1){ /* multi-propellant case */ + double sum_comp_ratio_ = 0.0; // Add up the values of isp_prop_comp_ratio. It should come to 1.0 - const double sum_comp_ratio_ = std::accumulate( - isp_prop_comp_ratio.begin(), - isp_prop_comp_ratio.end(), - 0.0); - + for (std::vector::iterator it = isp_prop_comp_ratio.begin(); + it != isp_prop_comp_ratio.end(); + ++it) { + sum_comp_ratio_ += (*it); + } // Protection against missing isp_prop_comp_ratio setting if( MathUtils::is_near_equal( sum_comp_ratio_, 0.0)){ CMLMessage::fail( @@ -92,8 +112,11 @@ RcsJetGroup::initialize( "It instead has value ", sum_comp_ratio_, "\n" "Normalizing the values to prevent incorrect propellant usage.\n"); - std::for_each(isp_prop_comp_ratio.begin(), isp_prop_comp_ratio.end(), - [&sum_comp_ratio_](double& ratio){ratio /= sum_comp_ratio_;}); + for (std::vector::iterator it=isp_prop_comp_ratio.begin(); + it != isp_prop_comp_ratio.end(); + ++it) { + (*it) /= sum_comp_ratio_; + } } // Otherwise, the isp_prop_comp_ratio values are appropriately valued. } @@ -120,4 +143,4 @@ RcsJetGroup::set_blow_down( return; } blow_down = blow_down_; -} \ No newline at end of file +} diff --git a/models/fhw/effectors/rcs_generic/src/rcs_jet.cc b/models/fhw/effectors/rcs_generic/src/rcs_jet.cc index ea7c8b71..8a86af93 100644 --- a/models/fhw/effectors/rcs_generic/src/rcs_jet.cc +++ b/models/fhw/effectors/rcs_generic/src/rcs_jet.cc @@ -2,25 +2,13 @@ PURPOSE: (Simple model of a single reaction control system jet.) -LIBRARY DEPENDENCIES: - ((cml/models/utilities/cml_message/src/cml_message.cc) - (cml/models/utilities/math_utils/src/math_utils.cc)) - PROGRAMMERS: (((Gary Turner) (OSR) (April 2017) (Antares) (Initial object-oriented implementation))) **********************************************************************/ -#include "cml/models/utilities/cml_message/include/cml_message.hh" -#include "cml/models/utilities/math_utils/include/math_utils.hh" -#include "jeod/models/utils/math/include/matrix3x3.hh" -#include "jeod/models/utils/math/include/vector3.hh" -#include -#include +#include "cml/models/utilities/math_utils/include/math_utils.hh" // MathUtils -#include "../include/rcs_generic.hh" -#include "../include/rcs_group.hh" -#include "../include/rcs_prop_pod.hh" #include "../include/rcs_jet.hh" /***************************************************************************** @@ -35,8 +23,60 @@ RcsJet::RcsJet( prop_pod(prop_pod_), group(group_), time_step( system.time_step), + + isp(0.0), + isp_g(0.0), + g_at_earth_surface(9.80665), + component_flow_rate( prop_pod.components.size()), - component_consumption( prop_pod.components.size()) + component_consumption( prop_pod.components.size()), + sum_component_consumption( prop_pod.components.size()), + sum_consumption(0.0), + force_hat{0.0, 0.0, 0.0}, + T_str_to_case{{1.0, 0.0, 0.0},{0.0, 1.0, 0.0},{0.0, 0.0, 1.0}}, + force_hat_changed(true), + force_cl_with_err(0.0), + force_hat_with_err{0.0, 0.0, 0.0}, + cone_angle_err(0.0), + azimuth_angle_err(0.0), + + force{0.0, 0.0, 0.0}, + error(No_Errors), + location{0.0, 0.0, 0.0}, + force_cl(0.0), + force_mag_std_dev(0.0), + force_mag_bias_frac(0.0), + direction_error(Vector), + force_cl_err(0.0), + force_hat_err{0.0, 0.0, 0.0}, + force_hat_std_dev{0.0, 0.0, 0.0}, + force_hat_std_mean{0.0, 0.0, 0.0}, + direction_dispersion(false), + cone_angle_disp(0.0), + azimuth_angle_disp(0.0), + cone_angle_bias(0.0), + cone_angle_std_dev(0.0), + base_impingement_force{0.0, 0.0, 0.0}, + base_impingement_torque{0.0, 0.0, 0.0}, + failure(No_Failure), + thrust_factor(0.0), + status(Status_Off), + on_com_time(0.0), + off_com_time(0.0), + on_com_time1(0.0), + off_com_time1(0.0), + time_left_in_trailoff(0.0), + delta_time_on(0.0), + scaled_force(0.0), + total_delay_on(0.0), + total_delay_off(0.0), + commands(), + command(false), + nfired(0), + sum_time(0.0), + torque{0.0, 0.0, 0.0}, + scaled_impingement_force{0.0, 0.0, 0.0}, + scaled_impingement_torque{0.0, 0.0, 0.0} { // Start the command list with an "Off": commands.push_back(false); @@ -166,8 +206,8 @@ RcsJet::compute_component_flow_rates() "Specific Impulse = ", isp, " s\nwith g included, velocity = ", isp_g, " m/s\n"); } - const unsigned int num_prop_components = group.get_num_prop_components(); - const double flow_rate = force_cl / isp_g; + unsigned int num_prop_components = group.get_num_prop_components(); + double flow_rate = force_cl / isp_g; if (num_prop_components == 1) { // compute simple fuel flow, all flow on one channel @@ -217,7 +257,12 @@ RcsJet::update( // During build_up and trail_off the force is assumed to have a constant slope */ delta_time_on = 0.0; - std::fill(component_consumption.begin(), component_consumption.end(), 0.0); + // Zero-out the component-consumption values for this cycle to allow + // increments to be accumulated from the start-up, shut-down processes and + // from compute_prop_consumption(). + for (auto & consumption: component_consumption) { + consumption = 0.0; + } //****************************/ // Set command @@ -854,6 +899,12 @@ RcsJet::compute_prop_consumption() } } + // Accumulate component consumption: + for (unsigned int ii = 0; ii < component_consumption.size(); ++ii) { + sum_component_consumption[ii] += component_consumption[ii]; + sum_consumption += component_consumption[ii]; + } + // Add this jet's prop consumption (per component) to the pod prop_pod.increment_mass_consumption( component_consumption); } @@ -1024,7 +1075,7 @@ RcsJet::apply_direction_error() // direction towards the y-axis after the y-z plane has been rotated by // azimuth-angle. double force_case[3]; - const double sin_cone = std::sin(cone_angle_err); + double sin_cone = std::sin(cone_angle_err); force_case[0] = std::cos(cone_angle_err); force_case[1] = sin_cone * std::cos(azimuth_angle_err); force_case[2] = sin_cone * std::sin(azimuth_angle_err); @@ -1052,7 +1103,7 @@ RcsJet::apply_direction_dispersion() // direction towards the y-axis after the y-z plane has been rotated by // azimuth-angle. double force_case[3]; - const double sin_cone = std::sin(cone_angle_disp); + double sin_cone = std::sin(cone_angle_disp); force_case[0] = std::cos(cone_angle_disp); force_case[1] = sin_cone * std::cos(azimuth_angle_disp); force_case[2] = sin_cone * std::sin(azimuth_angle_disp); @@ -1156,4 +1207,4 @@ RcsJet::set_force_direction( scratch[1] = force_dir_y; scratch[2] = force_dir_z; set_force_direction(scratch); -} \ No newline at end of file +} diff --git a/models/fhw/effectors/rcs_generic/src/rcs_prop_pod.cc b/models/fhw/effectors/rcs_generic/src/rcs_prop_pod.cc index cee33d6f..19808c5e 100644 --- a/models/fhw/effectors/rcs_generic/src/rcs_prop_pod.cc +++ b/models/fhw/effectors/rcs_generic/src/rcs_prop_pod.cc @@ -5,9 +5,6 @@ PURPOSE: (The RcsPropPod provides a convenient mechanism for grouping had several instances of RCS_PPOD that needed instantiating; this object represents a very similar concept to RCS_PPOD.) -LIBRARY DEPENDENCIES: - ((cml/models/utilities/cml_message/src/cml_message.cc)) - PROGRAMMERS: (((Gary Turner) (OSR) (April 2017) (Antares) (initial object-oriented implementation)) @@ -15,10 +12,6 @@ LIBRARY DEPENDENCIES: **********************************************************************/ #include "../include/rcs_prop_pod.hh" -#include "cml/models/utilities/cml_message/include/cml_message.hh" -#include - -#include /***************************************************************************** Constructor @@ -26,9 +19,12 @@ Constructor RcsPodComponent::RcsPodComponent( unsigned int max_num_jets_on) : + fake_interface(), mass_consumed_step( &fake_interface.mass_consumed_step), consumable_mass( &fake_interface.consumable_mass), - flow_rate_sf(max_num_jets_on, 0.0) + using_dyn_mass(false), + flow_rate_sf(max_num_jets_on, 0.0), + sum_consumption(0.0) { } /****************************************************************************/ @@ -37,10 +33,21 @@ RcsPropPod::RcsPropPod( unsigned int num_components_, const double & time_step_) : + mass_epsilon( 1.0e-12), + momentum_epsilon( 1.0e-12), time_step(time_step_), max_num_jets_on(max_num_jets_on_), + using_dyn_mass(false), + continue_thrust_after_depletion(false), + fail_on_depleted_mass(false), + health(HealthUndefined), + nominal_thrust(0.0), + pressure(0.0), thrust_factor( max_num_jets_on, 0.0), - components( num_components_, RcsPodComponent(max_num_jets_on_)) + components( num_components_, RcsPodComponent(max_num_jets_on_)), + sum_consumption(0.0), + equiv_momentum(0.0), + num_jets_on(0) { // This is not at all obvious. Having the RcsPodComponent constructor // set the mass_consumed_step and consumable_mass pointers to the addresses @@ -54,8 +61,8 @@ RcsPropPod::RcsPropPod( // component.set_dyn_mass_interface(component.fake_interface); // at this point still results in passing a temporary address for the // fake-interface so the pointers still go to the wrong place. - for (auto & component : components) { - component.set_dyn_mass_interface(component.fake_interface); + for (size_t ii = 0; ii < components.size(); ++ii) { + components[ii].set_dyn_mass_interface(components[ii].fake_interface); } } @@ -65,17 +72,17 @@ Purpose:(pushes the dynamic-mass-interface through to the specified component) *****************************************************************************/ void RcsPropPod::set_dyn_mass_interface( - unsigned int component_index, + unsigned int component_ix, DynamicMassBodyPropertiesInterface & dyn_mass_interface) { - if (component_index >= components.size()) { + if (component_ix >= components.size()) { CMLMessage::error( __FILE__,__LINE__,"Assignment error\n", - "Cannot assign a dyn-mass interface to component index ", component_index, " because\n" + "Cannot assign a dyn-mass interface to component index ", component_ix, " because\n" "there are only ", components.size(), " components (so max index is ", components.size()-1, ").\n"); } else { - components.at(component_index).set_dyn_mass_interface( dyn_mass_interface); + components.at(component_ix).set_dyn_mass_interface( dyn_mass_interface); using_dyn_mass = true; } } @@ -84,7 +91,12 @@ void RcsPodComponent::set_dyn_mass_interface( DynamicMassBodyPropertiesInterface & dyn_mass_interface) { - using_dyn_mass = &dyn_mass_interface != &fake_interface; + if (&dyn_mass_interface != &fake_interface) { + using_dyn_mass = true; + } + else { + using_dyn_mass = false; + } mass_consumed_step = &dyn_mass_interface.mass_consumed_step; consumable_mass = &dyn_mass_interface.consumable_mass; } @@ -103,10 +115,12 @@ RcsPropPod::activate_dyn_mass() if (using_dyn_mass) { return; } - for (auto & component : components) { - if (component.mass_consumed_step != &component.fake_interface.mass_consumed_step) { + for (std::vector::iterator it=components.begin(); + it != components.end(); + ++it) { + if ((*it).mass_consumed_step != &(*it).fake_interface.mass_consumed_step) { using_dyn_mass = true; - component.using_dyn_mass = true; + (*it).using_dyn_mass = true; } } } @@ -120,8 +134,10 @@ RcsPropPod::deactivate_dyn_mass() { if (using_dyn_mass) { using_dyn_mass = false; - for (auto & component : components) { - component.using_dyn_mass = false; + for (std::vector::iterator it=components.begin(); + it != components.end(); + ++it) { + (*it).using_dyn_mass = false; } } } @@ -150,9 +166,11 @@ RcsPropPod::mass_available() return true; // mass is static; there is always mass available. } - for (auto & component : components) { + for (std::vector::iterator it=components.begin(); + it != components.end(); + ++it) { // if any component is out, return false. - if ( !component.mass_available()) { + if ( !(*it).mass_available()) { // if the model is intended to be used such that mass depletes, but // mass-depletion does not prevent thrusting, turn off the dynamic-mass // at this point. Mass will not deplete any further for any component. @@ -196,7 +214,7 @@ RcsPropPod::increment_mass_consumption( } for (unsigned int ii = 0; ii < components.size(); ++ii) { - const double incr_consumption = jet_consumption.at(ii); + double incr_consumption = jet_consumption.at(ii); components.at(ii).increment_mass_consumption( incr_consumption); sum_consumption += incr_consumption; } @@ -226,8 +244,8 @@ RcsPropPod::compute_jets_on( // back out number of active jets: total momentum divided by momentum of // each jet. NOTE: if one jet is on for less than half of time_step, // num_jets_on will round down to 0 - num_jets_on = std::lround(equiv_momentum / - (nominal_thrust * time_step)); + num_jets_on = static_cast( 0.5 + equiv_momentum / + (nominal_thrust * time_step)); } else { // In this case, multiple jets DO NOT degrade thrust performance, and @@ -265,20 +283,20 @@ Purpose:(returns the scale-factor for the specified component in the pod *****************************************************************************/ double RcsPropPod::get_flow_rate_scale_factor( - const unsigned int component_index) const + const unsigned int component_ix) { if (num_jets_on == 0) { return 1.0; } - if (component_index >= components.size()) { + if (component_ix >= components.size()) { CMLMessage::error( __FILE__,__LINE__,"Assignment error\n", - "Cannot extract the flow-rate scale-factor from component index ", component_index, "\n" + "Cannot extract the flow-rate scale-factor from component index ", component_ix, "\n" "because there are only ", components.size(), " components (so max index is ", components.size()-1, ").\n"); return 0.0; } - return components.at(component_index).flow_rate_sf[num_jets_on-1]; + return components.at(component_ix).flow_rate_sf[num_jets_on-1]; } @@ -287,7 +305,7 @@ get_thrust_factor Purpose:(Returns the currently used value from the thrust_factor vector) *****************************************************************************/ double -RcsPropPod::get_thrust_factor() const +RcsPropPod::get_thrust_factor() { if (num_jets_on == 0) { return 1.0; @@ -297,6 +315,16 @@ RcsPropPod::get_thrust_factor() const } } +/***************************************************************************** +get_max_num_jets_on +Purpose:(Returns the protected max_num_jets_on value) +*****************************************************************************/ +unsigned int +RcsPropPod::get_max_num_jets_on() +{ + return max_num_jets_on; +} + /***************************************************************************** set_thrust_factor Purpose:(SWIG-friendly method to set values in the thrust_factor vector) @@ -314,4 +342,4 @@ RcsPropPod::set_thrust_factor( __FILE__,__LINE__,"Invalid assignment\n", "The thrust_factor vector is not sufficiently large to handle index ", index, ".\n"); } -} \ No newline at end of file +} diff --git a/models/fhw/effectors/rcs_generic/verif/data/include/rcs_test_multigroup.hh b/models/fhw/effectors/rcs_generic/verif/data/include/rcs_test_multigroup.hh index 6fed7508..0af495ca 100644 --- a/models/fhw/effectors/rcs_generic/verif/data/include/rcs_test_multigroup.hh +++ b/models/fhw/effectors/rcs_generic/verif/data/include/rcs_test_multigroup.hh @@ -11,11 +11,8 @@ PROGRAMMERS: #ifndef CML_RCS_TEST_MULTIGROUP_HH #define CML_RCS_TEST_MULTIGROUP_HH -#include "trick/units_conv.h" -#include "cml/models/fhw/effectors/rcs_generic/include/rcs_generic.hh" -#include "cml/models/fhw/effectors/rcs_generic/include/rcs_prop_pod.hh" -#include "cml/models/fhw/effectors/rcs_generic/include/rcs_group.hh" -#include "cml/models/fhw/effectors/rcs_generic/include/rcs_jet.hh" +#include "trick/units_conv.h" /* for unit conversion */ +#include "../../../include/rcs_generic_classes.hh" class RcsTestMultigroup : public RcsGeneric {