Initial commit
[debian/openrocket] / src / net / sf / openrocket / util / Test.java
1 package net.sf.openrocket.util;
2
3 import net.sf.openrocket.database.Databases;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.rocketcomponent.BodyTube;
6 import net.sf.openrocket.rocketcomponent.Bulkhead;
7 import net.sf.openrocket.rocketcomponent.CenteringRing;
8 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
9 import net.sf.openrocket.rocketcomponent.InnerTube;
10 import net.sf.openrocket.rocketcomponent.LaunchLug;
11 import net.sf.openrocket.rocketcomponent.MassComponent;
12 import net.sf.openrocket.rocketcomponent.Motor;
13 import net.sf.openrocket.rocketcomponent.NoseCone;
14 import net.sf.openrocket.rocketcomponent.Rocket;
15 import net.sf.openrocket.rocketcomponent.Stage;
16 import net.sf.openrocket.rocketcomponent.Transition;
17 import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
18 import net.sf.openrocket.rocketcomponent.TubeCoupler;
19 import net.sf.openrocket.rocketcomponent.FinSet.CrossSection;
20 import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
21
22 public class Test {
23
24         public static double noseconeLength=0.10,noseconeRadius=0.01;
25         public static double bodytubeLength=0.20,bodytubeRadius=0.01,bodytubeThickness=0.001;
26         
27         public static int finCount=3;
28         public static double finRootChord=0.04,finTipChord=0.05,finSweep=0.01,finThickness=0.003, finHeight=0.03;
29         
30         public static double materialDensity=1000;  // kg/m3
31         
32
33         public static Rocket makeRocket() {
34                 Rocket rocket;
35                 Stage stage,stage2;
36                 NoseCone nosecone;
37                 BodyTube bodytube, bt2;
38                 Transition transition;
39                 TrapezoidFinSet finset;
40                 
41                 rocket = new Rocket();
42                 stage = new Stage();
43                 stage.setName("Stage1");
44                 stage2 = new Stage();
45                 stage2.setName("Stage2");
46                 nosecone = new NoseCone(Transition.Shape.ELLIPSOID,noseconeLength,noseconeRadius);
47                 bodytube = new BodyTube(bodytubeLength,bodytubeRadius,bodytubeThickness);
48                 transition = new Transition();
49                 bt2 = new BodyTube(bodytubeLength,bodytubeRadius*2,bodytubeThickness);
50                 bt2.setMotorMount(true);
51
52                 finset = new TrapezoidFinSet(finCount,finRootChord,finTipChord,finSweep,finHeight);
53                 
54                 
55                 // Stage construction
56                 rocket.addChild(stage);
57                 rocket.addChild(stage2);
58
59                 
60                 // Component construction
61                 stage.addChild(nosecone);
62                 
63                 stage.addChild(bodytube);
64
65                 
66                 stage2.addChild(transition);
67                 
68                 stage2.addChild(bt2);
69                 
70                 bodytube.addChild(finset);
71                 
72                 
73                 rocket.getDefaultConfiguration().setAllStages();
74                 
75                 return rocket;
76         }
77         
78
79         public static Rocket makeSmallFlyable() {
80                 Rocket rocket;
81                 Stage stage;
82                 NoseCone nosecone;
83                 BodyTube bodytube;
84                 TrapezoidFinSet finset;
85                 
86                 rocket = new Rocket();
87                 stage = new Stage();
88                 stage.setName("Stage1");
89
90                 nosecone = new NoseCone(Transition.Shape.ELLIPSOID,noseconeLength,noseconeRadius);
91                 bodytube = new BodyTube(bodytubeLength,bodytubeRadius,bodytubeThickness);
92
93                 finset = new TrapezoidFinSet(finCount,finRootChord,finTipChord,finSweep,finHeight);
94                 
95                 
96                 // Stage construction
97                 rocket.addChild(stage);
98
99                 
100                 // Component construction
101                 stage.addChild(nosecone);
102                 stage.addChild(bodytube);
103
104                 bodytube.addChild(finset);
105                 
106                 Material material = Prefs.getDefaultComponentMaterial(null, Material.Type.BULK);
107                 nosecone.setMaterial(material);
108                 bodytube.setMaterial(material);
109                 finset.setMaterial(material);
110                 
111                 String id = rocket.newMotorConfigurationID();
112                 bodytube.setMotorMount(true);
113                 
114                 for (Motor m: Databases.MOTOR) {
115                         if (m.getDesignation().equals("B4")) {
116                                 bodytube.setMotor(id, m);
117                                 break;
118                         }
119                 }
120                 bodytube.setMotorOverhang(0.005);
121                 rocket.getDefaultConfiguration().setMotorConfigurationID(id);
122                 
123                 rocket.getDefaultConfiguration().setAllStages();
124                 
125                 
126                 return rocket;
127         }
128
129
130         public static Rocket makeBigBlue() {
131                 Rocket rocket;
132                 Stage stage;
133                 NoseCone nosecone;
134                 BodyTube bodytube;
135                 FreeformFinSet finset;
136                 MassComponent mcomp;
137                 
138                 rocket = new Rocket();
139                 stage = new Stage();
140                 stage.setName("Stage1");
141
142                 nosecone = new NoseCone(Transition.Shape.ELLIPSOID,0.105,0.033);
143                 nosecone.setThickness(0.001);
144                 bodytube = new BodyTube(0.69,0.033,0.001);
145
146                 finset = new FreeformFinSet();
147                 finset.setPoints(new Coordinate[] {
148                                 new Coordinate(0, 0),
149                                 new Coordinate(0.115, 0.072),
150                                 new Coordinate(0.255, 0.072),
151                                 new Coordinate(0.255, 0.037),
152                                 new Coordinate(0.150, 0)
153                 });
154                 finset.setThickness(0.003);
155                 finset.setFinCount(4);
156                 
157                 finset.setCantAngle(0*Math.PI/180);
158                 System.err.println("Fin cant angle: "+(finset.getCantAngle() * 180/Math.PI));
159                 
160                 mcomp = new MassComponent(0.2,0.03,0.045 + 0.060);
161                 mcomp.setRelativePosition(Position.TOP);
162                 mcomp.setPositionValue(0);
163                 
164                 // Stage construction
165                 rocket.addChild(stage);
166                 rocket.setPerfectFinish(false);
167
168                 
169                 // Component construction
170                 stage.addChild(nosecone);
171                 stage.addChild(bodytube);
172
173                 bodytube.addChild(finset);
174                 
175                 bodytube.addChild(mcomp);
176                 
177 //              Material material = new Material("Test material", 500);
178 //              nosecone.setMaterial(material);
179 //              bodytube.setMaterial(material);
180 //              finset.setMaterial(material);
181                 
182                 String id = rocket.newMotorConfigurationID();
183                 bodytube.setMotorMount(true);
184                 
185                 for (Motor m: Databases.MOTOR) {
186                         if (m.getDesignation().equals("F12J")) {
187                                 bodytube.setMotor(id, m);
188                                 break;
189                         }
190                 }
191                 bodytube.setMotorOverhang(0.005);
192                 rocket.getDefaultConfiguration().setMotorConfigurationID(id);
193                 
194                 rocket.getDefaultConfiguration().setAllStages();
195                 
196                 
197                 return rocket;
198         }
199         
200         
201
202         public static Rocket makeIsoHaisu() {
203                 Rocket rocket;
204                 Stage stage;
205                 NoseCone nosecone;
206                 BodyTube tube1, tube2, tube3;
207                 TrapezoidFinSet finset;
208                 TrapezoidFinSet auxfinset;
209                 MassComponent mcomp;
210                 
211                 final double R = 0.07;
212                 
213                 rocket = new Rocket();
214                 stage = new Stage();
215                 stage.setName("Stage1");
216
217                 nosecone = new NoseCone(Transition.Shape.OGIVE,0.53,R);
218                 nosecone.setThickness(0.005);
219                 nosecone.setMassOverridden(true);
220                 nosecone.setOverrideMass(0.588);
221                 stage.addChild(nosecone);
222                 
223                 tube1 = new BodyTube(0.505,R,0.005);
224                 tube1.setMassOverridden(true);
225                 tube1.setOverrideMass(0.366);
226                 stage.addChild(tube1);
227                 
228                 tube2 = new BodyTube(0.605,R,0.005);
229                 tube2.setMassOverridden(true);
230                 tube2.setOverrideMass(0.427);
231                 stage.addChild(tube2);
232                 
233                 tube3 = new BodyTube(1.065,R,0.005);
234                 tube3.setMassOverridden(true);
235                 tube3.setOverrideMass(0.730);
236                 stage.addChild(tube3);
237                 
238                 
239                 LaunchLug lug = new LaunchLug();
240                 tube1.addChild(lug);
241                 
242                 TubeCoupler coupler = new TubeCoupler();
243                 coupler.setOuterRadiusAutomatic(true);
244                 coupler.setThickness(0.005);
245                 coupler.setLength(0.28);
246                 coupler.setMassOverridden(true);
247                 coupler.setOverrideMass(0.360);
248                 coupler.setRelativePosition(Position.BOTTOM);
249                 coupler.setPositionValue(-0.14);
250                 tube1.addChild(coupler);
251                 
252                 
253                 // Parachute
254                 MassComponent mass = new MassComponent(0.05, 0.05, 0.280);
255                 mass.setRelativePosition(Position.TOP);
256                 mass.setPositionValue(0.2);
257                 tube1.addChild(mass);
258                 
259                 // Cord
260                 mass = new MassComponent(0.05, 0.05, 0.125);
261                 mass.setRelativePosition(Position.TOP);
262                 mass.setPositionValue(0.2);
263                 tube1.addChild(mass);
264                 
265                 // Payload
266                 mass = new MassComponent(0.40, R, 1.500);
267                 mass.setRelativePosition(Position.TOP);
268                 mass.setPositionValue(0.25);
269                 tube1.addChild(mass);
270                 
271                 
272                 auxfinset = new TrapezoidFinSet();
273                 auxfinset.setName("CONTROL");
274                 auxfinset.setFinCount(2);
275                 auxfinset.setRootChord(0.05);
276                 auxfinset.setTipChord(0.05);
277                 auxfinset.setHeight(0.10);
278                 auxfinset.setSweep(0);
279                 auxfinset.setThickness(0.008);
280                 auxfinset.setCrossSection(CrossSection.AIRFOIL);
281                 auxfinset.setRelativePosition(Position.TOP);
282                 auxfinset.setPositionValue(0.28);
283                 auxfinset.setBaseRotation(Math.PI/2);
284                 tube1.addChild(auxfinset);
285                 
286                 
287                 
288                 
289                 coupler = new TubeCoupler();
290                 coupler.setOuterRadiusAutomatic(true);
291                 coupler.setLength(0.28);
292                 coupler.setRelativePosition(Position.TOP);
293                 coupler.setPositionValue(0.47);
294                 coupler.setMassOverridden(true);
295                 coupler.setOverrideMass(0.360);
296                 tube2.addChild(coupler);
297                 
298                 
299                 
300                 // Parachute
301                 mass = new MassComponent(0.1, 0.05, 0.028);
302                 mass.setRelativePosition(Position.TOP);
303                 mass.setPositionValue(0.14);
304                 tube2.addChild(mass);
305                 
306                 Bulkhead bulk = new Bulkhead();
307                 bulk.setOuterRadiusAutomatic(true);
308                 bulk.setMassOverridden(true);
309                 bulk.setOverrideMass(0.050);
310                 bulk.setRelativePosition(Position.TOP);
311                 bulk.setPositionValue(0.27);
312                 tube2.addChild(bulk);
313                 
314                 // Chord
315                 mass = new MassComponent(0.1, 0.05, 0.125);
316                 mass.setRelativePosition(Position.TOP);
317                 mass.setPositionValue(0.19);
318                 tube2.addChild(mass);
319                 
320                 
321                 
322                 InnerTube inner = new InnerTube();
323                 inner.setOuterRadius(0.08/2);
324                 inner.setInnerRadius(0.0762/2);
325                 inner.setLength(0.86);
326                 inner.setMassOverridden(true);
327                 inner.setOverrideMass(0.388);
328                 tube3.addChild(inner);
329                 
330                 
331                 CenteringRing center = new CenteringRing();
332                 center.setInnerRadiusAutomatic(true);
333                 center.setOuterRadiusAutomatic(true);
334                 center.setLength(0.005);
335                 center.setMassOverridden(true);
336                 center.setOverrideMass(0.038);
337                 center.setRelativePosition(Position.BOTTOM);
338                 center.setPositionValue(0);
339                 tube3.addChild(center);
340                 
341                 
342                 center = new CenteringRing();
343                 center.setInnerRadiusAutomatic(true);
344                 center.setOuterRadiusAutomatic(true);
345                 center.setLength(0.005);
346                 center.setMassOverridden(true);
347                 center.setOverrideMass(0.038);
348                 center.setRelativePosition(Position.TOP);
349                 center.setPositionValue(0.28);
350                 tube3.addChild(center);
351                 
352                 
353                 center = new CenteringRing();
354                 center.setInnerRadiusAutomatic(true);
355                 center.setOuterRadiusAutomatic(true);
356                 center.setLength(0.005);
357                 center.setMassOverridden(true);
358                 center.setOverrideMass(0.038);
359                 center.setRelativePosition(Position.TOP);
360                 center.setPositionValue(0.83);
361                 tube3.addChild(center);
362                 
363                 
364                 
365                 
366                 
367                 finset = new TrapezoidFinSet();
368                 finset.setRootChord(0.495);
369                 finset.setTipChord(0.1);
370                 finset.setHeight(0.185);
371                 finset.setThickness(0.005);
372                 finset.setSweep(0.3);
373                 finset.setRelativePosition(Position.BOTTOM);
374                 finset.setPositionValue(-0.03);
375                 finset.setBaseRotation(Math.PI/2);
376                 tube3.addChild(finset);
377                 
378                 
379                 finset.setCantAngle(0*Math.PI/180);
380                 System.err.println("Fin cant angle: "+(finset.getCantAngle() * 180/Math.PI));
381                 
382                 
383                 // Stage construction
384                 rocket.addChild(stage);
385                 rocket.setPerfectFinish(false);
386
387                 
388                 
389                 String id = rocket.newMotorConfigurationID();
390                 tube3.setMotorMount(true);
391                 
392                 for (Motor m: Databases.MOTOR) {
393                         if (m.getDesignation().equals("L540")) {
394                                 tube3.setMotor(id, m);
395                                 break;
396                         }
397                 }
398                 tube3.setMotorOverhang(0.02);
399                 rocket.getDefaultConfiguration().setMotorConfigurationID(id);
400
401 //              tube3.setIgnitionEvent(MotorMount.IgnitionEvent.NEVER);
402                 
403                 rocket.getDefaultConfiguration().setAllStages();
404                 
405                 
406                 return rocket;
407         }
408         
409         
410         
411 }