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