From ec4e6eed37b90065bb7555b2abe1e4fc53159f92 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 5 Mar 2022 15:49:26 +0100 Subject: [PATCH] [#1204] Add CG override effect to motors The problem was that the overrideCG had no effect in calculateMotors(). --- .../openrocket/masscalc/MassCalculation.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculation.java b/core/src/net/sf/openrocket/masscalc/MassCalculation.java index 03724b1f8..3e985ec1d 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculation.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculation.java @@ -71,6 +71,10 @@ public class MassCalculation { this.centerOfMass = this.centerOfMass.average( pointMass); } } + + public void addMass(double mass) { + this.centerOfMass = this.centerOfMass.setWeight(getMass() + mass); + } public MassCalculation copy( final RocketComponent _root, final Transformation _transform){ return new MassCalculation( this.type, this.config, this.simulationTime, this.activeMotorList, _root, _transform, this.analysisMap); @@ -83,6 +87,10 @@ public class MassCalculation { public double getMass() { return this.centerOfMass.weight; } + + public void setMass(double mass) { + this.centerOfMass = this.centerOfMass.setWeight(mass); + } public double getLongitudinalInertia() { return this.inertia.Iyy; @@ -407,6 +415,13 @@ public class MassCalculation { final int instanceCount = component.getInstanceCount(); Coordinate[] instanceLocations = component.getInstanceLocations(); + if (analysisMap != null) { + if (this.config.isComponentActive(component) && (!analysisMap.containsKey(component.hashCode()))) { + CMAnalysisEntry entry = new CMAnalysisEntry(component); + analysisMap.put(component.hashCode(), entry); + } + } + // // vvv DEBUG // if( this.config.isComponentActive(component) ){ // System.err.println(String.format( "%s[%s]....", prefix, component.getName())); @@ -448,6 +463,45 @@ public class MassCalculation { this.merge( children ); //System.err.println(String.format( "%s....assembly mass (incl/children): %s", prefix, this.toCMDebug())); } + + if (this.config.isComponentActive(component) ){ + Coordinate compCM = component.getComponentCG(); + + // mass data for *this component only* in the rocket-frame + compCM = parentTransform.transform(compCM.add(component.getPosition())); + + // setting zero as the CG position means the top of the component, which is component.getPosition() + final Coordinate compZero = parentTransform.transform( component.getPosition() ); + + if (component.getOverrideSubcomponents()) { + if (component.isCGOverridden()) { + this.setCM(this.getCM().setX(compZero.x + component.getOverrideCGX())); + } + } else { + if (component.isCGOverridden()) { + compCM = compCM.setX(compZero.x + component.getOverrideCGX()); + } + } + + if (null != analysisMap) { + final CMAnalysisEntry entry = analysisMap.get(component.hashCode()); + if (component.getChildCount() > 0) { + // For parent components, record the _assembly_ information + entry.updateEachMass(children.getMass() / component.getInstanceCount()); + entry.updateAverageCM(this.centerOfMass); + } else { + // For actual components, record the mass of the component, and disregard children + entry.updateEachMass(compCM.weight); + entry.updateAverageCM(compCM); + } + } + + final double compIx = component.getRotationalUnitInertia() * compCM.weight; + final double compIt = component.getLongitudinalUnitInertia() * compCM.weight; + final RigidBody componentInertia = new RigidBody(compCM, compIx, compIt, compIt); + this.addInertia(componentInertia); + } + // // vvv DEBUG // if( this.config.isComponentActive(component) && 0 < this.getMass() ) {