openrocket

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

README

pkg/openrocket

This package provides functionality for importing and exporting OpenRocket files.

Responsibility

  • Import OpenRocket files into the launchrail application.
  • Export launchrail data to OpenRocket files.

Scope

  • Support different versions of the OpenRocket file format.
  • Handle different types of data, such as rocket designs and flight simulations.

Gotchas

  • Complexity of the OpenRocket file format.
  • Ensuring data fidelity during import and export.

Test Suite Overview

The test suite includes unit tests for the core functionality of the package, including:

  • Importing OpenRocket files.
  • Exporting launchrail data to OpenRocket files.
  • Handling different versions of the OpenRocket file format.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AngleOffset

type AngleOffset struct {
	XMLName xml.Name `xml:"angleoffset"`
	Method  string   `xml:"method,attr"`
	Value   float64  `xml:",chardata"`
}

AngleOffset represents the angle offset element of the XML document

func (*AngleOffset) String

func (a *AngleOffset) String() string

String returns full string representation of the angleoffset

type AxialOffset

type AxialOffset struct {
	XMLName xml.Name `xml:"axialoffset"`
	Method  string   `xml:"method,attr"`
	Value   float64  `xml:",chardata"`
}

AxialOffset is a calculated offset from the center of the component to the center of the rocket

func (*AxialOffset) String

func (a *AxialOffset) String() string

String returns full string representation of the AxialOffset

type BodyTube

type BodyTube struct {
	XMLName       xml.Name              `xml:"bodytube"`
	Name          string                `xml:"name"`
	ID            string                `xml:"id"`
	Finish        string                `xml:"finish"`
	Material      Material              `xml:"material"`
	Length        float64               `xml:"length"`
	Thickness     float64               `xml:"thickness"`
	Radius        string                `xml:"radius"` // WARN: May be 'auto' and num
	Subcomponents BodyTubeSubcomponents `xml:"subcomponents"`
}

BodyTube represents the body tube element of the XML document

func (*BodyTube) GetMass

func (b *BodyTube) GetMass() float64

GetMass returns the mass of the bodytube material itself (excluding subcomponents). It logs warnings if the mass cannot be calculated due to invalid radius or dimensions.

func (*BodyTube) String

func (b *BodyTube) String() string

String returns full string representation of the BodyTube

type BodyTubeSubcomponents

type BodyTubeSubcomponents struct {
	XMLName         xml.Name        `xml:"subcomponents"`
	InnerTube       InnerTube       `xml:"innertube"`
	TrapezoidFinset TrapezoidFinset `xml:"trapezoidfinset"`
	Parachute       Parachute       `xml:"parachute"`
	CenteringRings  []CenteringRing `xml:"centeringring"`
	Shockcord       Shockcord       `xml:"shockcord"`
}

BodyTubeSubcomponents represents the nested subcomponents element of the XML document

func (*BodyTubeSubcomponents) String

func (b *BodyTubeSubcomponents) String() string

String returns full string representation of the BodyTubeSubcomponents

type CenteringRing

type CenteringRing struct {
	XMLName            xml.Name    `xml:"centeringring"`
	Name               string      `xml:"name"`
	ID                 string      `xml:"id"`
	InstanceCount      int         `xml:"instancecount"`
	InstanceSeparation float64     `xml:"instanceseparation"`
	AxialOffset        AxialOffset `xml:"axialoffset"`
	Position           Position    `xml:"position"`
	Material           Material    `xml:"material"`
	Length             float64     `xml:"length"`
	RadialPosition     float64     `xml:"radialposition"`
	RadialDirection    float64     `xml:"radialdirection"`
	OuterRadius        string      `xml:"outerradius"` // WARN: May be 'auto'
	InnerRadius        string      `xml:"innerradius"` // WARN: May be 'auto'
}

CenteringRing represents the centering ring element of the XML document

func (*CenteringRing) GetMass added in v0.3.0

func (c *CenteringRing) GetMass() float64

GetMass calculates the mass of the centering ring(s). NOTE: Cannot calculate mass if OuterRadius or InnerRadius is "auto". Returns 0 if radii are "auto" or invalid.

func (*CenteringRing) String

func (c *CenteringRing) String() string

String returns full string representation of the CenteringRing

type DeploymentConfig

type DeploymentConfig struct {
	XMLName        xml.Name `xml:"deploymentconfiguration"`
	ConfigID       string   `xml:"configid,attr"`
	DeployEvent    string   `xml:"deployevent"`
	DeployAltitude float64  `xml:"deployaltitude"`
	DeployDelay    float64  `xml:"deploydelay"`
}

DeploymentConfig represents the deployment configuration element of the XML document

func (*DeploymentConfig) String

func (d *DeploymentConfig) String() string

String returns full string representation of the deployment clusterconfiguration

type FilletMaterial

type FilletMaterial struct {
	XMLName xml.Name `xml:"filletmaterial"`
	Type    string   `xml:"type,attr"`
	Density float64  `xml:"density,attr"`
	Name    string   `xml:",chardata"`
}

FilletMaterial represents the fillet material element of the XML document (XMLName is the only delta from Material)

func (*FilletMaterial) String

func (f *FilletMaterial) String() string

String returns full string representation of the filletmaterial

type IgnitionConfig

type IgnitionConfig struct {
	XMLName       xml.Name `xml:"ignitionconfiguration"`
	ConfigID      string   `xml:"configid,attr"`
	IgnitionEvent string   `xml:"ignitionevent"`
	IgnitionDelay float64  `xml:"ignitiondelay"`
}

IgnitionConfig represents the ignition configuration element of the XML document

func (*IgnitionConfig) String

func (i *IgnitionConfig) String() string

String returns full string representation of the ignition clusterconfiguration

type InnerTube

type InnerTube struct {
	XMLName              xml.Name               `xml:"innertube"`
	Name                 string                 `xml:"name"`
	ID                   string                 `xml:"id"`
	AxialOffset          AxialOffset            `xml:"axialoffset"`
	Position             Position               `xml:"position"`
	Material             Material               `xml:"material"`
	Length               float64                `xml:"length"`
	RadialPosition       float64                `xml:"radialposition"`
	RadialDirection      float64                `xml:"radialdirection"`
	OuterRadius          float64                `xml:"outerradius"`
	Thickness            float64                `xml:"thickness"`
	ClusterConfiguration string                 `xml:"clusterconfiguration"`
	ClusterScale         float64                `xml:"clusterscale"`
	ClusterRotation      float64                `xml:"clusterrotation"`
	MotorMount           MotorMount             `xml:"motormount"`    // Direct motor mount info
	Subcomponents        InnerTubeSubcomponents `xml:"subcomponents"` // Contains nested components like another motor mount? (Schema unclear)
}

InnerTube represents the inner tube element of the XML document

func (*InnerTube) GetMass added in v0.3.0

func (i *InnerTube) GetMass() float64

GetMass calculates the mass of the inner tube material itself (excluding subcomponents like motor).

func (*InnerTube) String

func (i *InnerTube) String() string

String returns full string representation of the InnerTube

type InnerTubeSubcomponents added in v0.3.4

type InnerTubeSubcomponents struct {
	XMLName    xml.Name   `xml:"subcomponents"`
	MotorMount MotorMount `xml:"motormount"` // Often empty if motor is directly in InnerTube?
}

InnerTubeSubcomponents represents the nested subcomponents for an InnerTube. Note: The exact structure and purpose within InnerTube needs clarification from OR schema/usage. It seems redundant with the direct MotorMount field.

func (*InnerTubeSubcomponents) String added in v0.3.4

func (s *InnerTubeSubcomponents) String() string

String returns a string representation of InnerTubeSubcomponents.

type LineMaterial

type LineMaterial struct {
	XMLName xml.Name `xml:"linematerial"`
	Type    string   `xml:"type,attr"`
	Density float64  `xml:"density,attr"`
	Name    string   `xml:",chardata"`
}

LineMaterial is the same as Material with a diff XMLName

func (*LineMaterial) String

func (l *LineMaterial) String() string

String returns full string representation of the LineMaterial

type MassComponent

type MassComponent struct {
	XMLName         xml.Name    `xml:"masscomponent"`
	Name            string      `xml:"name"`
	ID              string      `xml:"id"`
	AxialOffset     AxialOffset `xml:"axialoffset"`
	Position        Position    `xml:"position"`
	PackedLength    float64     `xml:"packedlength"`
	PackedRadius    float64     `xml:"packedradius"`
	RadialPosition  float64     `xml:"radialposition"`
	RadialDirection float64     `xml:"radialdirection"`
	Mass            float64     `xml:"mass"`
	Type            string      `xml:"masscomponenttype"`
}

MassComponent represents the mass component element of the XML document

func (*MassComponent) GetMass added in v0.3.0

func (m *MassComponent) GetMass() float64

GetMass returns the pre-defined mass of the component.

func (*MassComponent) String

func (m *MassComponent) String() string

String returns full string representation of the MassComponent

type MassProvider added in v0.3.0

type MassProvider interface {
	GetMass() float64
}

MassProvider defines an interface for components that can provide their mass. This helps in aggregating mass from various component types.

type Material

type Material struct {
	XMLName xml.Name `xml:"material"`
	Type    string   `xml:"type,attr"`
	Density float64  `xml:"density,attr"`
	Name    string   `xml:",chardata"`
}

Material represents the material element of the XML document

func (*Material) String

func (m *Material) String() string

String returns full string representation of the Material

type Motor

type Motor struct {
	XMLName      xml.Name `xml:"motor"`
	ConfigID     string   `xml:"configid,attr"`
	Type         string   `xml:"type"`
	Manufacturer string   `xml:"manufacturer"`
	Digest       string   `xml:"digest"`
	Designation  string   `xml:"designation"`
	Diameter     float64  `xml:"diameter"`
	Length       float64  `xml:"length"`
	Delay        string   `xml:"delay"`
}

Motor represents the motor element of the XML document

func (*Motor) String

func (m *Motor) String() string

String returns full string representation of the motormount

type MotorConfiguration

type MotorConfiguration struct {
	XMLName  xml.Name `xml:"motorconfiguration"`
	ConfigID string   `xml:"configid,attr"`
	Default  bool     `xml:"default,attr"`
	Stages   []Stage  `xml:"stage"`
}

MotorConfiguration represents the motor configuration element of the XML document

func (*MotorConfiguration) String

func (m *MotorConfiguration) String() string

String returns full string representation of the MotorConfiguration

type MotorMount

type MotorMount struct {
	XMLName        xml.Name       `xml:"motormount"`
	IgnitionEvent  string         `xml:"ignitionevent"`
	IgnitionDelay  float64        `xml:"ignitiondelay"`
	Overhang       float64        `xml:"overhang"`
	Motor          Motor          `xml:"motor"`
	IgnitionConfig IgnitionConfig `xml:"ignitionconfiguration"` // WARN: This duplicates field above but let's keep it for now
}

MotorMount represents the motor mount element of the XML document

func (*MotorMount) String

func (m *MotorMount) String() string

String returns full string representation of the motormount

type NoseSubcomponents

type NoseSubcomponents struct {
	XMLName       xml.Name      `xml:"subcomponents"`
	MassComponent MassComponent `xml:"masscomponent"`
}

NoseSubcomponents represents the nested subcomponents element of the XML document

func (*NoseSubcomponents) String

func (n *NoseSubcomponents) String() string

String returns full string representation of the NoseSubcomponents

type Nosecone

type Nosecone struct {
	XMLName              xml.Name          `xml:"nosecone"`
	Name                 string            `xml:"name"`
	ID                   string            `xml:"id"`
	Finish               string            `xml:"finish"`
	Material             Material          `xml:"material"`
	Length               float64           `xml:"length"`
	Thickness            float64           `xml:"thickness"`
	Shape                string            `xml:"shape"`
	ShapeClipped         bool              `xml:"shapeclipped"`
	ShapeParameter       float64           `xml:"shapeparameter"`
	AftRadius            float64           `xml:"aftradius"`
	AftShoulderRadius    float64           `xml:"aftshoulderradius"`
	AftShoulderLength    float64           `xml:"aftshoulderlength"`
	AftShoulderThickness float64           `xml:"aftshoulderthickness"`
	AftShoulderCapped    bool              `xml:"aftshouldercapped"`
	IsFlipped            bool              `xml:"isflipped"`
	Subcomponents        NoseSubcomponents `xml:"subcomponents"`
}

Nosecone represents the nosecone element of the XML document

func (*Nosecone) GetMass

func (n *Nosecone) GetMass() float64

GetMass returns the mass of the nose cone, calculated based on shape and thickness.

func (*Nosecone) String

func (n *Nosecone) String() string

String returns full string representation of the Nosecone

type OpenrocketDocument

type OpenrocketDocument struct {
	XMLName xml.Name       `xml:"openrocket"`
	Version string         `xml:"version,attr"`
	Creator string         `xml:"creator,attr"`
	Rocket  RocketDocument `xml:"rocket"`
}

OpenrocketDocument represents the root of the XML document

func Load

func Load(filename string, version string) (*OpenrocketDocument, error)

func (*OpenrocketDocument) Bytes

func (o *OpenrocketDocument) Bytes() []byte

Bytes returns the byte representation of the OpenrocketDocument

func (*OpenrocketDocument) Describe

func (o *OpenrocketDocument) Describe() string

Describe returns a string representation of the OpenrocketDocument

func (*OpenrocketDocument) String

func (o *OpenrocketDocument) String() string

String returns full string representation of the OpenrocketDocument

func (*OpenrocketDocument) Validate

func (o *OpenrocketDocument) Validate(cfg *config.Engine) error

Validate checks if the OpenrocketDocument is valid for this program

type Parachute

type Parachute struct {
	XMLName          xml.Name         `xml:"parachute"`
	Name             string           `xml:"name"`
	ID               string           `xml:"id"`
	AxialOffset      AxialOffset      `xml:"axialoffset"`
	Position         Position         `xml:"position"`
	PackedLength     float64          `xml:"packedlength"`
	PackedRadius     float64          `xml:"packedradius"`
	RadialPosition   float64          `xml:"radialposition"`
	RadialDirection  float64          `xml:"radialdirection"`
	CD               string           `xml:"cd"` // WARN: May be 'auto' and num
	Material         Material         `xml:"material"`
	DeployEvent      string           `xml:"deployevent"`
	DeployAltitude   float64          `xml:"deployaltitude"`
	DeployDelay      float64          `xml:"deploydelay"`
	DeploymentConfig DeploymentConfig `xml:"deploymentconfiguration"`
	Diameter         float64          `xml:"diameter"`
	LineCount        int              `xml:"linecount"`
	LineLength       float64          `xml:"linelength"`
	LineMaterial     LineMaterial     `xml:"linematerial"`
}

Parachute represents the parachute element of the XML document

func (*Parachute) GetMass added in v0.3.0

func (p *Parachute) GetMass() float64

GetMass calculates the mass of the parachute based on canopy and line materials/dimensions. NOTE: This calculation assumes Parachute.Material.Density represents AREAL density (e.g., kg/m^2). Line mass calculation uses LineMaterial density (assumed linear).

func (*Parachute) String

func (p *Parachute) String() string

String returns full string representation of the parachute

type Position

type Position struct {
	XMLName xml.Name `xml:"position"`
	Value   float64  `xml:",chardata"`
	Type    string   `xml:"type,attr"`
}

Position represents the position of the component in the rocket

func (*Position) String

func (p *Position) String() string

String returns full string representation of the Position

type RadiusOffset

type RadiusOffset struct {
	XMLName xml.Name `xml:"radiusoffset"`
	Method  string   `xml:"method,attr"`
	Value   float64  `xml:",chardata"`
}

RadiusOffset represents the radius offset element of the XML document

func (*RadiusOffset) String

func (r *RadiusOffset) String() string

String returns full string representation of the radiusoffset

type RocketDocument

type RocketDocument struct {
	XMLName            xml.Name           `xml:"rocket"`
	Name               string             `xml:"name"`
	ID                 string             `xml:"id"`
	AxialOffset        AxialOffset        `xml:"axialoffset"`
	Position           Position           `xml:"position"`
	Designer           string             `xml:"designer"`
	Revision           string             `xml:"revision"`
	MotorConfiguration MotorConfiguration `xml:"motorconfiguration"`
	ReferenceType      string             `xml:"referencetype"`
	Subcomponents      Subcomponents      `xml:"subcomponents"`
}

RocketDocument represents the rocket element of the XML document

func (*RocketDocument) String

func (r *RocketDocument) String() string

String returns full string representation of the RocketDocument

type RocketStage

type RocketStage struct {
	XMLName                xml.Name               `xml:"stage"`
	Name                   string                 `xml:"name"`
	ID                     string                 `xml:"id"`
	SustainerSubcomponents SustainerSubcomponents `xml:"subcomponents"`
}

RocketStage represents the stage subcomponent element of the XML document

func (*RocketStage) String

func (r *RocketStage) String() string

String returns full string representation of the RocketStage

type Shockcord

type Shockcord struct {
	XMLName         xml.Name    `xml:"shockcord"`
	Name            string      `xml:"name"`
	ID              string      `xml:"id"`
	AxialOffset     AxialOffset `xml:"axialoffset"`
	Position        Position    `xml:"position"`
	PackedLength    float64     `xml:"packedlength"`
	PackedRadius    float64     `xml:"packedradius"`
	RadialPosition  float64     `xml:"radialposition"`
	RadialDirection float64     `xml:"radialdirection"`
	CordLength      float64     `xml:"cordlength"`
	Material        Material    `xml:"material"`
}

Shockcord represents the shockcord element of the XML document

func (*Shockcord) GetMass added in v0.3.0

func (s *Shockcord) GetMass() float64

GetMass calculates the mass of the shockcord. NOTE: Assumes Material.Density is LINEAR density (e.g., kg/m). If it's volumetric (kg/m^3), this calculation needs cord diameter.

func (*Shockcord) String

func (s *Shockcord) String() string

String returns full string representation of the shockcord

type Stage

type Stage struct {
	XMLName xml.Name `xml:"stage"`
	Number  int      `xml:"number,attr"`
	Active  bool     `xml:"active,attr"`
}

Stage represents motor configuration stages

func (*Stage) String

func (s *Stage) String() string

String returns full string representation of the Stage

type Subcomponents

type Subcomponents struct {
	XMLName xml.Name      `xml:"subcomponents"`
	Stages  []RocketStage `xml:"stage"`
}

Subcomponents represents the subcomponents element of the XML document

func (*Subcomponents) List

func (s *Subcomponents) List() []RocketStage

List returns a list of all subcomponents so we can iterate over them

func (*Subcomponents) String

func (s *Subcomponents) String() string

String returns full string representation of the Subcomponents

type SustainerSubcomponents

type SustainerSubcomponents struct {
	XMLName  xml.Name `xml:"subcomponents"`
	Nosecone Nosecone `xml:"nosecone"`
	BodyTube BodyTube `xml:"bodytube"`
}

SustainerSubcomponents represents the sustainer subcomponents element of the XML document

func (*SustainerSubcomponents) String

func (s *SustainerSubcomponents) String() string

String returns full string representation of the SustainerSubcomponents

type TabPosition

type TabPosition struct {
	RelativeTo string  `xml:"relativeto,attr"`
	Value      float64 `xml:",chardata"`
}

TabPosition represents the tabposition element of the XML document

func (*TabPosition) String

func (t *TabPosition) String() string

String returns full string representation of the tabposition

type TrapezoidFinset

type TrapezoidFinset struct {
	XMLName        xml.Name       `xml:"trapezoidfinset"`
	Name           string         `xml:"name"`
	ID             string         `xml:"id"`
	InstanceCount  int            `xml:"instancecount"`
	FinCount       int            `xml:"fincount"`
	RadiusOffset   RadiusOffset   `xml:"radiusoffset"`
	AngleOffset    AngleOffset    `xml:"angleoffset"`
	Rotation       float64        `xml:"rotation"`
	AxialOffset    AxialOffset    `xml:"axialoffset"`
	Position       Position       `xml:"position"`
	Finish         string         `xml:"finish"`
	Material       Material       `xml:"material"`
	Thickness      float64        `xml:"thickness"`
	CrossSection   string         `xml:"crosssection"`
	Cant           float64        `xml:"cant"`
	TabHeight      float64        `xml:"tabheight"`
	TabLength      float64        `xml:"tablength"`
	TabPositions   []TabPosition  `xml:"tabposition"`
	FilletRadius   float64        `xml:"filletradius"`
	FilletMaterial FilletMaterial `xml:"filletmaterial"`
	RootChord      float64        `xml:"rootchord"`
	TipChord       float64        `xml:"tipchord"`
	SweepLength    float64        `xml:"sweeplength"`
	Height         float64        `xml:"height"`
}

TrapezoidFinset represents the trapezoid finset element of the XML document

func (*TrapezoidFinset) GetMass

func (t *TrapezoidFinset) GetMass() float64

GetMass calculates mass based on material density and dimensions

func (*TrapezoidFinset) String

func (t *TrapezoidFinset) String() string

String returns full string representation of the TrapezoidFinset

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL