1
0
Fork 0

AIBallistic: Maintenance

virtual dtor
_submodel and _elevation_m hiding parent members
ensure all members are initialized
use double constants with double types
This commit is contained in:
Scott Giese 2022-01-15 17:27:59 -06:00
parent a6a29f5482
commit a9cb94fdbd
2 changed files with 44 additions and 55 deletions

View file

@ -80,8 +80,6 @@ _impact_report_node(fgGetNode("/ai/models/model-impact", true))
no_roll = false;
}
FGAIBallistic::~FGAIBallistic() {
}
void FGAIBallistic::readFromScenario(SGPropertyNode* scFileNode) {
if (!scFileNode){
@ -738,56 +736,53 @@ void FGAIBallistic::Run(double dt) {
}
// Calculate velocity due to external force
double force_speed_north_deg_sec = 0;
double force_speed_east_deg_sec = 0;
double hs_force_fps = 0;
double v_force_acc_fpss = 0;
double force_speed_north_fps = 0;
double force_speed_east_fps = 0;
double h_force_lbs = 0;
double normal_force_lbs = 0;
double normal_force_fpss = 0;
double static_friction_force_lbs = 0;
double dynamic_friction_force_lbs = 0;
double friction_force_speed_north_fps = 0;
double friction_force_speed_east_fps = 0;
double friction_force_speed_north_deg_sec = 0;
double friction_force_speed_east_deg_sec = 0;
double force_elevation_deg = 0;
double force_azimuth_deg = 0;
double force_lbs = 0;
double force_speed_north_deg_sec = 0.0;
double force_speed_east_deg_sec = 0.0;
double v_force_acc_fpss = 0.0;
double force_speed_north_fps = 0.0;
double force_speed_east_fps = 0.0;
double h_force_lbs = 0.0;
double normal_force_fpss = 0.0;
double friction_force_speed_north_fps = 0.0;
double friction_force_speed_east_fps = 0.0;
double friction_force_speed_north_deg_sec = 0.0;
double friction_force_speed_east_deg_sec = 0.0;
double force_elevation_deg = 0.0;
if (_external_force) {
//cout << _name << " external force " << hdg << " az " << _azimuth << endl;
SGPropertyNode *n = fgGetNode(_force_path.c_str(), true);
force_lbs = n->getChild("force-lb", 0, true)->getDoubleValue();
double force_lbs = n->getChild("force-lb", 0, true)->getDoubleValue();
force_elevation_deg = n->getChild("force-elevation-deg", 0, true)->getDoubleValue();
force_azimuth_deg = n->getChild("force-azimuth-deg", 0, true)->getDoubleValue();
double force_azimuth_deg = n->getChild("force-azimuth-deg", 0, true)->getDoubleValue();
// Resolve force into vertical and horizontal components:
double v_force_lbs = force_lbs * sin( force_elevation_deg * SG_DEGREES_TO_RADIANS );
h_force_lbs = force_lbs * cos( force_elevation_deg * SG_DEGREES_TO_RADIANS );
double normal_force_lbs = 0.0;
double dynamic_friction_force_lbs = 0.0;
// Perform ground interaction if impacts are not calculated
if (!_report_impact && getHtAGL(10000)) {
double deadzone = 0.1;
if (_ht_agl_ft <= (0 + _ground_offset + deadzone) && _solid) {
if (_ht_agl_ft <= (_ground_offset + deadzone) && _solid) {
normal_force_lbs = (_mass * slugs_to_lbs) - v_force_lbs;
if (normal_force_lbs < 0)
normal_force_lbs = 0;
if (normal_force_lbs < 0.0)
normal_force_lbs = 0.0;
pos.setElevationFt(0 + _ground_offset);
if (vs_fps < 0)
if (vs_fps < 0.0)
vs_fps *= -0.5;
// Calculate friction. We assume a static coefficient of
// friction (mu) of 0.62 (wood on concrete)
double mu = 0.62;
static_friction_force_lbs = mu * normal_force_lbs * _frictionFactor;
double static_friction_force_lbs = mu * normal_force_lbs * _frictionFactor;
// Adjust horizontal force. We assume that a speed of <= 5 fps is static
if (h_force_lbs <= static_friction_force_lbs && hs <= 5) {
@ -795,7 +790,7 @@ void FGAIBallistic::Run(double dt) {
_speed_north_fps = _speed_east_fps = 0;
}
else
dynamic_friction_force_lbs = (static_friction_force_lbs * 0.95);
dynamic_friction_force_lbs = static_friction_force_lbs * 0.95;
// Ignore wind when on the ground for now
//TODO fix this
@ -811,7 +806,7 @@ void FGAIBallistic::Run(double dt) {
double dynamic_friction_acc_fpss = dynamic_friction_force_lbs / _mass;
// velocity = acceleration * dt
hs_force_fps = h_force_acc_fpss * dt;
double hs_force_fps = h_force_acc_fpss * dt;
double friction_force_fps = dynamic_friction_acc_fpss * dt;
//resolve horizontal speeds into north and east components:
@ -854,13 +849,12 @@ void FGAIBallistic::Run(double dt) {
setOffsetPos(pos,
manager->get_user_heading(),
manager->get_user_pitch(),
manager->get_user_roll()
);
manager->get_user_roll());
pos.setLatitudeDeg(_offsetpos.getLatitudeDeg());
pos.setLongitudeDeg(_offsetpos.getLongitudeDeg());
pos.setElevationFt(_offsetpos.getElevationFt());
if (getHtAGL(10000)) {
if (getHtAGL(10000.0)) {
double deadzone = 0.1;
if (_ht_agl_ft <= (0 + _ground_offset + deadzone) && _solid) {

View file

@ -19,15 +19,14 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef _FG_AIBALLISTIC_HXX
#define _FG_AIBALLISTIC_HXX
#pragma once
#include <cmath>
#include <vector>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/scene/material/mat.hxx>
#include "AIManager.hxx"
#include "AIBase.hxx"
@ -36,8 +35,9 @@ class FGAIBallistic : public FGAIBase {
public:
FGAIBallistic(object_type ot = otBallistic);
~FGAIBallistic();
virtual ~FGAIBallistic() = default;
const char* getTypeString(void) const override { return "ballistic"; }
void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override;
@ -45,8 +45,6 @@ public:
void reinit() override;
void update(double dt) override;
const char* getTypeString(void) const override { return "ballistic"; }
void Run(double dt);
void setAzimuth( double az );
@ -111,7 +109,7 @@ public:
bool getSlaved() const;
bool getSlavedLoad() const;
FGAIBallistic *ballistic;
FGAIBallistic *ballistic = nullptr;
static const double slugs_to_kgs; //conversion factor
static const double slugs_to_lbs; //conversion factor
@ -142,10 +140,10 @@ public:
double _azimuth; // degrees true
double _elevation; // degrees
double _rotation; // degrees
double _speed_north_fps;
double _speed_east_fps;
double _wind_from_east; // fps
double _wind_from_north; // fps
double _speed_north_fps = 0.0;
double _speed_east_fps = 0.0;
double _wind_from_east = 0.0; // fps
double _wind_from_north = 0.0; // fps
double hs;
@ -159,9 +157,9 @@ public:
double getTgtYOffset() const;
double getTgtZOffset() const;
double _tgt_x_offset;
double _tgt_y_offset;
double _tgt_z_offset;
double _tgt_x_offset = 0.0;
double _tgt_y_offset = 0.0;
double _tgt_z_offset = 0.0;
double _elapsed_time;
SGGeod _parentpos;
@ -185,14 +183,14 @@ private:
bool _random; // modifier for Cd, life, az
double _life_randomness; // dimension for _random, only applies to life at present
double _load_resistance; // ground load resistanc N/m^2
double _frictionFactor; // dimensionless modifier for Coefficient of Friction
double _frictionFactor = 0.0; // dimensionless modifier for Coefficient of Friction
bool _solid; // if true ground is solid for FDMs
double _elevation_m; // ground elevation in meters
// double _elevation_m = 0.0; // ground elevation in meters
bool _force_stabilised;// if true, object will align to external force
bool _slave_to_ac; // if true, object will be slaved to the parent ac pos and orientation
bool _slave_load_to_ac;// if true, object will be slaved to the parent ac pos
double _contents_lb; // contents of the object
double _weight_lb; // weight of the object (no contents if appropriate) (lbs)
double _weight_lb = 0.0; // weight of the object (no contents if appropriate) (lbs)
std::string _mat_name;
bool _report_collision; // if true a collision point with AI Objects is calculated
@ -203,9 +201,8 @@ private:
SGPropertyNode_ptr _impact_report_node; // report node for impact and collision
SGPropertyNode_ptr _contents_node; // node for droptank etc. contents
double _fuse_range;
double _fuse_range = 0.0;
std::string _submodel;
std::string _force_path;
std::string _contents_path;
@ -224,11 +221,9 @@ private:
double getRecip(double az);
double getMass() const;
double _ground_offset;
double _load_offset;
double _ground_offset = 0.0;
double _load_offset = 0.0;
SGVec3d _oldcartoffsetPos;
SGVec3d _oldcartPos;
};
#endif // _FG_AIBALLISTIC_HXX