forked from sandbornm/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_placer.py
1542 lines (1309 loc) · 63.9 KB
/
part_placer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import math
import copy
import sys
import random
import argparse
#TODO: link up with part database to get dimension information for bounding box generation
#Placeholder dimensions for part classes
part_dimensions = {"f":{"x_width":5, "y_height":5, "z_depth":5},
"w": {"x_width":20, "y_height":2, "z_depth":5},
"p": {"x_width":2, "y_height":2.5, "z_depth":2},
"h": {"x_width":2, "y_height":2, "z_depth":2.5},
"cg": {"x_width":5, "y_height":5, "z_depth":5},
"l" : {"x_width":1, "y_height":6, "z_depth":2}}
# "non_parallel_wing": {"x_width":14.85, "y_height":14.85, "z_depth":5}}
# """bounding box formula for non-parallel wings:
# x_width = cos(theta)*length + sin(theta)*thickness
# y_height = sin(theta)*length + cos(theta)*thickness
# """
def parse_clusters(text):
clusters = []
return clusters
def custom_encoder(design, design_num, remove_boilerplate = True):
output_string = '[\n {\n "connections": [\n '
parameters = [
# ("Front_Rail_Length", "80"),
# ("Front_Wing_Tube_Length", "55"),
# ("FwdFacingCCW_PropType", "-1"),
# ("FwdFacingCCW_Spin", "1"),
# ("FwdFacingCW_Spin", "1"),
# ("Mid_Tube_Length", "140"),
# ("NACA_profile", "0012"),
# ("Param_11", "180"),
# ("Param_12", "90"),
# ("Param_14", "448.68"),
# ("Rear_Rail_Length", "220"),
# ("Rudder_Tube_Length", "41"),
# ("Top_Leg_Tube_Length", "150.1524"),
# ("Vertical_Tube_Length", "150"),
# ("angle_270", "270"),
# ("front_l_wing_offset", "289.68"),
# ("front_r_wing_offset", "160.32"),
# ("front_wing_chord", "150"),
# ("front_wing_span", "450"),
("fuse_floor", "20", False),
("Orient_Z_ANGLE", "90", False),
("fuse_height", "105",False),
("fuse_width", "80",False),
("l_rudder_offset", "90",False),
("r_rudder_offset", "50",False),
("rear_wing_chord", "180",False),
("rear_wing_offset", "90",False),
("rear_wing_span", "609",False),
("rudder_chord", "100",False),
("rudder_span", "140",False),
("wing_thickness", "12",False)]
type_parameters = {
'p' : [("Direction", "Direction", False, "-1"), ("Prop_type", "Prop_type", False, "1")],
'h' : [("Direction", "Direction", False, "-1"), ("Prop_type", "Prop_type", False, "1")],
'w' : [("AILERON_BIAS","AILERON_BIAS", False, "0.5" ), ("CHORD_1", "wing_chord", True, "150"),("CHORD_2", "wing_chord", True, "150"), ("CONTROL_CHANNEL", "CONTROL_CHANNEL", False, "1"),
("FLAP_BIAS", "FLAP_BIAS", False, "0.5"),("LOAD", "LOAD", False, "30"), ("NACA_Profile", "NACA_Profile", False, "0012"),("SERVO_LENGTH", "SERVO_LENGTH", False, "0.1"),
("SERVO_THICKNESS", "SERVO_THICKNESS", False, "0.1"),("SERVO_WIDTH", "SERVO_WIDTH", False, "0.1"), ("SPAN", "SPAN", False, "1200"), ("TAPER_OFFSET", "TAPER_OFFSET", False, "0"),
("THICKNESS", "THICKNESS", False, "12"),("TUBE_DIAMETER", "TUBE_DIAMETER", False, "7.1474"),("TUBE_OFFSET", "TUBE_OFFSET", False, "600"), ("TUBE_ROTATION", "TUBE_ROTATION", False, "180")],
'l': [("AILERON_BIAS","AILERON_BIAS", False, "0.5" ), ("CHORD_1", "wing_chord", True, "150"),("CHORD_2", "wing_chord", True, "150"), ("CONTROL_CHANNEL", "CONTROL_CHANNEL", False, "1"),
("FLAP_BIAS", "FLAP_BIAS", False, "0.5"),("LOAD", "LOAD", False, "30"), ("NACA_Profile", "NACA_Profile", False, "0012"),("SERVO_LENGTH", "SERVO_LENGTH", False, "0.1"),
("SERVO_THICKNESS", "SERVO_THICKNESS", False, "0.1"),("SERVO_WIDTH", "SERVO_WIDTH", False, "0.1"), ("SPAN", "SPAN", False, "1200"), ("TAPER_OFFSET", "TAPER_OFFSET", False, "0"),
("THICKNESS", "THICKNESS", False, "12"),("TUBE_DIAMETER", "TUBE_DIAMETER", False, "7.1474"),("TUBE_OFFSET", "TUBE_OFFSET", False, "600"), ("TUBE_ROTATION", "TUBE_ROTATION", False, "180")],
't' : [("BASE_ROT", "BASE_ROT", False, "0"),("END_ROT", "END_ROT", False, "0"),("Length", "Length", False, "100"),("Offset1", "Offset1", False, "0"),("Offset2Offset2", "Offset2", False, "0")],
'pt' : [("BASE_ROT", "BASE_ROT", False, "0"),("END_ROT", "END_ROT", False, "0"),("Length", "Length", False, "100"),("Offset1", "Offset1", False, "0"),("Offset2Offset2", "Offset2", False, "0")],
'bc' : [("ANGHORZCONN", "ANGHORZCONN", False, "90"),("ANGVERTCONN", "ANGVERTCONN", False, "0"),("DIAMETER", "DIAMETER", False, "7.1474")],
'c' : [("ANGHORZCONN", "ANGHORZCONN", False, "90"),("ANGVERTCONN", "ANGVERTCONN", False, "0"),("DIAMETER", "DIAMETER", False, "7.1474")],
'fl' : [("BOTTOM_ANGLE", "BOTTOM_ANGLE", False, "0"),("SIDE_ANGLE", "SIDE_ANGLE", False, "0")],
'm' : [("CONTROL_CHANNEL", "CONTROL_CHANNEL", False)],
'f' : [("BOTTOM_CONNECTOR_OFFSET_LENGTH","BOTTOM_CONNECTOR_OFFSET_LENGTH", False, "0" ), ("BOTTOM_CONNECTOR_OFFSET_WIDTH", "BOTTOM_CONNECTOR_OFFSET_WIDTH", False, "0"),("BOTTOM_CONNECTOR_ROTATION", "BOTTOM_CONNECTOR_ROTATION", True, "0"),
("BOTTOM_CONNECTOR_ROTATION", "BOTTOM_CONNECTOR_ROTATION", False, "0"),
("FLOOR_CONNECTOR_1_DISP_WIDTH", "FLOOR_CONNECTOR_1_DISP_WIDTH", False, "30"),("FLOOR_CONNECTOR_2_DISP_LENGTH", "FLOOR_CONNECTOR_2_DISP_LENGTH", False, "0"), ("FLOOR_CONNECTOR_2_DISP_WIDTH", "FLOOR_CONNECTOR_2_DISP_WIDTH", False, "-30"),("FLOOR_CONNECTOR_3_DISP_LENGTH", "FLOOR_CONNECTOR_3_DISP_LENGTH", False, "-160"),
("FLOOR_CONNECTOR_3_DISP_WIDTH", "FLOOR_CONNECTOR_3_DISP_WIDTH", False, "13"),("FLOOR_CONNECTOR_4_DISP_LENGTH", "FLOOR_CONNECTOR_4_DISP_LENGTH", False, "-160"), ("FLOOR_CONNECTOR_4_DISP_WIDTH", "FLOOR_CONNECTOR_4_DISP_WIDTH", False, "-18"), ("FLOOR_CONNECTOR_5_DISP_LENGTH", "FLOOR_CONNECTOR_5_DISP_LENGTH", False, "115"),
("FLOOR_CONNECTOR_5_DISP_WIDTH", "FLOOR_CONNECTOR_5_DISP_WIDTH", False, "0"),("FLOOR_CONNECTOR_6_DISP_LENGTH", "FLOOR_CONNECTOR_6_DISP_LENGTH", False, "155"),("FLOOR_CONNECTOR_6_DISP_WIDTH", "FLOOR_CONNECTOR_6_DISP_WIDTH", False, "18"), ("FLOOR_CONNECTOR_7_DISP_LENGTH", "FLOOR_CONNECTOR_7_DISP_LENGTH", False, "-120"),
("FLOOR_CONNECTOR_7_DISP_WIDTH", "FLOOR_CONNECTOR_7_DISP_WIDTH", False, "0"),("FLOOR_CONNECTOR_8_DISP_LENGTH", "FLOOR_CONNECTOR_8_DISP_LENGTH", False, "155"),("FLOOR_CONNECTOR_8_DISP_WIDTH", "FLOOR_CONNECTOR_8_DISP_WIDTH", False, "-18"), ("FLOOR_HEIGHT", "FLOOR_HEIGHT", False, "20"),
("FUSE_CYL_LENGTH", "FUSE_CYL_LENGTH", False, "270"),("HORZ_DIAMETER", "HORZ_DIAMETER", False, "190"),("VERT_DIAMETER", "VERT_DIAMETER", False, "125")],
'cg' : [("Rotation", "Rotation", False, "0")]
}
default_value_dict = {}
for key in type_parameters.keys():
for param in type_parameters[key]:
if len(param) >= 4:
default_value_dict[param[1]] = param[3]
uav_type_models = {
'm' : 'kde_direct_KDE2315XF_885', 'fl' : '0394_para_flange', 't' : '0394OD_para_tube',
'w' : 'Wing_horiz_hole', 'l': 'Wing_horiz_hole', 'p' : 'apc_propellers_7x5E','h' : 'apc_propellers_7x5E', 'c' : '0394od_para_hub_4',
'f' : 'capsule_fuselage', 'cg' : 'CargoCase'
}
def generate_instance_params(pid, part_type):
return_string = ''
return_parameters = []
for param in type_parameters[part_type]:
value = param[1] if param[2] else pid + '_' + param[1]
return_string += '"{}" : "{}",\n'.format(param[0], value)
return_parameters.append((value, value, param[2]))
return_string = return_string[:-2]
return_string += "\n"
return return_string, return_parameters
for key in design.parts.keys():
connections = design.parts[key].connections
pid = design.parts[key].pid
for conn_key in connections.keys():
dest = connections[conn_key]
if dest:
dest_connections = design.parts[dest].connections
for dest_key in dest_connections.keys():
if dest_connections[dest_key] == pid:
if not output_string[-1] == ' ':
output_string += ",\n"
if design.parts[key].part_type in ['p', 'h']:
output_string = output_string[:-2]
elif design.parts[dest].part_type in ['p', 'h']:
if design.uav:
motor = 'm' + dest[1:]
motor_anchor_port = 'Base_Connector'
motor_propeller_port = 'Prop_Connector'
flange = 'fl' + dest[1:]
flange_anchor_port = 'BottomConnector'
flange_motor_port = "TopConnector"
prop_tube = 'pt' + dest[1:]
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(conn_key, flange_anchor_port, pid, flange)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(flange_anchor_port, conn_key, flange, pid)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(flange_motor_port, motor_anchor_port, flange, motor)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(motor_anchor_port, flange_motor_port, motor, flange)
# output_string += '{{'\
# '"connector1": "{}",\n'\
# '"connector2": "{}",\n'\
# '"instance1": "{}",\n'\
# '"instance2": "{}"\n'\
# '}},'.format("EndConnection", motor_anchor_port, prop_tube, motor)
# output_string += '{{'\
# '"connector1": "{}",\n'\
# '"connector2": "{}",\n'\
# '"instance1": "{}",\n'\
# '"instance2": "{}"\n'\
# '}},'.format(motor_anchor_port, "EndConnection", motor, prop_tube)
# output_string += '{{'\
# '"connector1": "{}",\n'\
# '"connector2": "{}",\n'\
# '"instance1": "{}",\n'\
# '"instance2": "{}"\n'\
# '}},'.format('MOTOR_CONNECTOR_CS_IN', motor_propeller_port, pid, motor)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(motor_propeller_port, 'MOTOR_CONNECTOR_CS_IN',motor , dest)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format('MOTOR_CONNECTOR_CS_IN', motor_propeller_port,dest , motor)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format("MotorPower", "MotorPower", "BatteryController", motor)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}}'.format("MotorPower", "MotorPower", motor, "BatteryController")
else:
motor = 'm' + pid[1:]
motor_port = 'Base_Connector'
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(conn_key, motor_port, pid, motor)
motor_port = 'Prop_Connector'
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}}'.format(motor_port, 'MOTOR_CONNECTOR_CS_IN',motor , pid)
#TODO: change to dictionary system for cargo/fuselage/etc.
else:
connector_port = conn_key
dest_port = dest_key
uav_conversions = {'left': 'Side_Connector_1', 'front': 'Side_Connector_2', 'right': 'Side_Connector_3', 'rear': 'Side_Connector_4', 'top': 'Top_Connector', 'bottom': 'Bottom_Connector'}
part_type = design.parts[pid].part_type
if part_type == 'c':
connector_port = uav_conversions[conn_key]
elif part_type == 'cg':
#disable
connector_port = 'Case2HubConnectore' #RUIN NAME TO REMOVE CASE
part_type = design.parts[dest].part_type
if part_type == 'c':
dest_port = uav_conversions[dest_key]
elif part_type == 'cg':
#disable
dest_port = 'Case2HubConnectore' ##RUIN NAME TO REMOVE CASE
source_name = 'fuselage' if pid[0] == 'f' else pid
dest_name = 'fuselage' if dest[0] == 'f' else dest
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}}'.format(connector_port, dest_port, source_name, dest_name)
if design.parts[dest].part_type == 'w':
# output_string = output_string[:-1]
output_string += ',\n'
connector_port = 'Wing_Servo_Connector'
dest_port = 'Connector'
source_name = dest
dest_name = 'servo' + dest[1:]
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}},'.format(connector_port, dest_port, source_name, dest_name)
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}}'.format(dest_port, connector_port, dest_name, source_name)
boiler_plate_connections = [
{'connector1': 'FloorConnector1', 'connector2': 'Bottom_Connector', 'instance1':'fuselage', 'instance2':'Main_Battery'},
{'connector1': 'BatteryPower', 'connector2': 'PowerBus', 'instance1':'BatteryController', 'instance2':'Main_Battery'},
{'connector1': 'SensorConnector', 'connector2': 'FloorConnector3', 'instance1':'RpmTemp', 'instance2':'fuselage'},
{'connector1': 'SensorConnector', 'connector2': 'FloorConnector4', 'instance1':'Current', 'instance2':'fuselage'},
{'connector1': 'SensorConnector', 'connector2': 'FloorConnector5', 'instance1':'Autopilot', 'instance2':'fuselage'},
{'connector1': 'SensorConnector', 'connector2': 'FloorConnector6', 'instance1':'Voltage', 'instance2':'fuselage'},
{'connector1': 'SensorConnector', 'connector2': 'FloorConnector7', 'instance1':'GPS', 'instance2':'fuselage'},
{'connector1': 'SensorConnector', 'connector2': 'FloorConnector8', 'instance1':'Variometer', 'instance2':'fuselage'},
{'connector1': 'CargoConnector', 'connector2': 'CargoConnector', 'instance1':'cargo', 'instance2':'cargo_case'},
{'connector1': 'ORIENTCONN', 'connector2': 'Orient_Connector', 'instance1':'Orient', 'instance2':'main_hub'}
]
if design.uav:
if not remove_boilerplate:
for connection in boiler_plate_connections:
output_string += ',\n'
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}}'.format(connection['connector1'], connection['connector2'], connection['instance1'], connection['instance2'])
output_string += ',\n'
output_string += '{{'\
'"connector1": "{}",\n'\
'"connector2": "{}",\n'\
'"instance1": "{}",\n'\
'"instance2": "{}"\n'\
'}}'.format(connection['connector2'], connection['connector1'], connection['instance2'], connection['instance1'])
output_string += "],\n"
output_string += '"design": "Generated_{}",\n'.format(design_num)
output_string += '"instances": [\n '
for key in design.parts.keys():
if output_string[-1] == '}':
output_string += ',\n'
if design.parts[key].part_type in ['p','h']:
motor_model_name = uav_type_models['m'] if design.uav else 'MAGiDRIVE150'
if design.uav:
flange_model = uav_type_models['fl']
tube_model = uav_type_models['t']
#Add flange
output_string += '{\n'\
'"assignment": {\n'
param_string, new_params = generate_instance_params('fl' + key[1:], 'fl')
output_string += param_string
parameters = parameters + new_params
output_string += '}},\n'\
'"model" : "{}",\n'\
'"name": "{}"\n'\
'}},'.format(flange_model,'fl' + design.parts[key].pid[1:])
#Add prop tube
# output_string += '{\n'\
# '"assignment": {\n'
# param_string, new_params = generate_instance_params('pt' + key[1:], 'pt')
# output_string += param_string
# parameters.extend(new_params)
# output_string += '}},\n'\
# '"model" : "{}",\n'\
# '"name": "{}"\n'\
# '}},'.format(tube_model,'pt' + design.parts[key].pid[1:])
output_string += '{\n'\
'"assignment": {\n'
param_string, new_params = generate_instance_params('m' + key[1:], 'm')
output_string += param_string
parameters.extend(new_params)
output_string += '}},\n'\
'"model" : "{}",\n'\
'"name": "{}"\n'\
'}},'.format(motor_model_name,'m' + design.parts[key].pid[1:])
# if design.parts[key].part_type == 'f':
# model_name = 'capsule_fuselage' if design.uav else "FUSE_SPHERE_CYL_CONE"
# if design.uav:
# output_string += '{{\n'\
# '"assignment": {{\n'\
# '"FLOOR_HEIGHT": "FuselageFloorHeight",\n'\
# '"LENGTH": "FuselageLength",\n'\
# '"MIDDLE_LENGTH": "FuselageMiddleLength",\n'\
# '"PORT_THICKNESS": "FuselagePortThickness",\n'\
# '"SEAT_1_FB": "FuselageSeatFB",\n'\
# '"SEAT_1_LR": "FuselageSeat1LR",\n'\
# '"SEAT_2_FB": "FuselageSeatFB",\n'\
# '"SEAT_2_LR": "FuselageSeat2LR",\n'\
# '"SPHERE_DIAMETER": "FuselageSphereDiameter",\n'\
# '"BOTTOM_CONNECTOR_OFFSET_LENGTH": "fuselage_BOTTOM_CONNECTOR_OFFSET_LENGTH",\n'\
# '"BOTTOM_CONNECTOR_OFFSET_WIDTH": "fuselage_BOTTOM_CONNECTOR_OFFSET_WIDTH",\n'\
# '"BOTTOM_CONNECTOR_ROTATION": "fuselage_BOTTOM_CONNECTOR_ROTATION",\n'\
# '"FLOOR_CONNECTOR_1_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_1_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_1_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_1_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_2_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_2_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_2_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_2_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_3_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_3_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_3_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_3_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_4_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_4_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_4_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_4_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_5_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_5_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_5_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_5_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_6_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_6_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_6_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_6_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_7_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_7_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_7_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_7_DISP_WIDTH",\n'\
# '"FLOOR_CONNECTOR_8_DISP_LENGTH": "fuselage_FLOOR_CONNECTOR_8_DISP_LENGTH",\n'\
# '"FLOOR_CONNECTOR_8_DISP_WIDTH": "fuselage_FLOOR_CONNECTOR_8_DISP_WIDTH",\n'\
# '"FLOOR_HEIGHT": "fuselage_FLOOR_HEIGHT",\n'\
# '"FUSE_CYL_LENGTH": "fuselage_FUSE_CYL_LENGTH",\n'\
# '"HORZ_DIAMETER": "fuselage_HORZ_DIAMETER",\n'\
# '"VERT_DIAMETER": "fuselage_VERT_DIAMETER",\n'\
# '"TAIL_DIAMETER": "FuselageTailDiameter"\n'\
# '}},\n'\
# '"model" : "{}",\n'\
# '"name": "{}"\n'\
# '}}'.format(model_name,'fuselage')
# else:
# output_string += '{{\n'\
# '"assignment": {{\n'\
# '"FLOOR_HEIGHT": "fuse_floor",\n'\
# '"BOTTOM_CONNECTOR_ROTATION": "BodyRotAngle",\n'\
# '"HORZ_DIAMETER": "fuse_width",\n'\
# '"TUBE_LENGTH": "Vertical_Tube_Length",\n'\
# '"VERT_DIAMETER": "fuse_height"\n'\
# '}},\n'\
# '"model" : "{}",\n'\
# '"name": "{}"\n'\
# '}}'.format(model_name,design.parts[key].pid)
# elif design.parts[key].part_type == 'cg':
# model_name = 'CargoCase'
# instance_name = 'cargo_case'
# output_string += '{{\n'\
# '"assignment": {{\n'\
# '"Rotation": "cargo_case_Rotation"\n'\
# '}},\n'\
# '"model" : "{}",\n'\
# '"name": "{}"\n'\
# '}}'.format(model_name,instance_name)
# else:
model_name = uav_type_models[design.parts[key].part_type]
output_string += '{\n'\
'"assignment": {\n'
param_string, new_params = generate_instance_params(key, design.parts[key].part_type)
output_string += param_string
parameters.extend(new_params)
output_string += '}},\n'\
'"model" : "{}",\n'\
'"name": "{}"\n'\
'}},'.format(model_name,design.parts[key].pid)
if design.parts[key].part_type == 'w':
servo_name = 'servo' + key[1:]
servo_model = 'Hitec_HS_40'
output_string += '{{\n'\
'"assignment": {{}},\n'\
'"model" : "{}",\n'\
'"name": "{}"\n'\
'}}'.format(servo_model,servo_name)
if design.uav:
if not remove_boilerplate:
boiler_plate_instances = [
{'assignment': [('ROTATION', 'Autopilot_ROTATION')], 'model': 'Autopilot', 'name': 'Autopilot'},
{'assignment': [], 'model': 'BatteryController', 'name': 'BatteryController'},
{'assignment': [], 'model': 'TurnigyGraphene6000mAh6S75C', 'name': 'Main_Battery'},
{'assignment': [], 'model': 'ControlBox', 'name': 'ControlBox'},
# {'assignment': [('ROTATION', 'Battery_1_ROTATION')], 'model': 'TurnigyGraphene6000mAh6S75C', 'name': 'Battery_1'},
# {'assignment': [('ROTATION', 'Battery_2_ROTATION')], 'model': 'TurnigyGraphene6000mAh6S75C', 'name': 'Battery_2'},
{'assignment': [('ROTATION', 'Current_ROTATION')], 'model': 'Current', 'name': 'Current'},
{'assignment': [('ROTATION', 'GPS_ROTATION')], 'model': 'GPS', 'name': 'GPS'},
{'assignment': [('Z_ANGLE', 'Orient_Z_ANGLE')], 'model': 'Orient', 'name': 'Orient'},
{'assignment': [('ROTATION', 'RpmTemp_ROTATION')], 'model': 'RpmTemp', 'name': 'RpmTemp'},
{'assignment': [('ROTATION', 'Variometer_ROTATION')], 'model': 'Variometer', 'name': 'Variometer'},
{'assignment': [('ROTATION', 'Voltage_ROTATION')], 'model': 'Voltage', 'name': 'Voltage'},
{'assignment': [('Rotation', 'cargo_case_Rotation')], 'model': 'CargoCase', 'name': 'cargo_case'},
{'assignment': [('WEIGHT', 'cargo_WEIGHT')], 'model': 'Cargo', 'name': 'cargo'}]
for instance in boiler_plate_instances:
output_string += '{\n'\
'"assignment": {\n'
for assignment in instance['assignment']:
output_string += '"{}" : "{}",'.format(assignment[0], assignment[1])
output_string = output_string[:-1]
output_string += '}},\n'\
'"model" : "{}",\n'\
'"name": "{}"\n'\
'}},'.format(instance['model'], instance['name'])
output_string = output_string[:-1]
output_string += "],"
if design.uav:
control_channel_counter = 2
output_string += '"parameters":{\n'
for param in parameters:
cleaned_param = param[1] if param[2] else param[0][param[0].index("_") + 1:]
if param[1][:4] == 'main':
cleaned_param = param[1][9:]
if cleaned_param == "CONTROL_CHANNEL":
output_string += '"{}" : "{}",\n'.format(param[0], '{}'.format(str(control_channel_counter)))
control_channel_counter += 1
elif cleaned_param == "Length":
pid = param[0][:param[0].index("_")]
base_part = design.parts[design.parts[pid].connections["BaseConnection"]]
end_part = design.parts[design.parts[pid].connections["EndConnection"]]
if (base_part.part_type in ['bc', 'c']) and (end_part.part_type in ['bc', 'c']):
if (base_part.hub_type in ['main', 'fuselage']) and (end_part.hub_type in ['main', 'fuselage']):
output_string += '"{}" : "{}",\n'.format(param[0], 350)
else:
output_string += '"{}" : "{}",\n'.format(param[0], default_value_dict[cleaned_param])
elif cleaned_param == "SPAN":
pid = param[0][:param[0].index("_")]
base_part = design.parts[pid]
if (base_part.part_type in ['l']):
output_string += '"{}" : "{}",\n'.format(param[0], 150)
else:
output_string += '"{}" : "{}",\n'.format(param[0], default_value_dict[cleaned_param])
elif cleaned_param == "BASE_ROT":
pid = param[0][:param[0].index("_")]
if design.parts[pid].connections["BaseConnection"][0] in ['w','l']:
origin_hub = design.parts[design.parts[pid].connections["EndConnection"]]
origin_connection = None
for connection in origin_hub.connections.keys():
if origin_hub.connections[connection] == pid:
origin_connection = connection
if origin_connection in ['rear', 'left']:
output_string += '"{}" : "{}",\n'.format(param[0], 90)
elif origin_connection in ['front', 'right']:
output_string += '"{}" : "{}",\n'.format(param[0], 270)
elif origin_connection in ['top']:
output_string += '"{}" : "{}",\n'.format(param[0], 270)
elif origin_connection in ['bottom']:
output_string += '"{}" : "{}",\n'.format(param[0], 90)
elif cleaned_param in default_value_dict.keys():
output_string += '"{}" : "{}",\n'.format(param[0], default_value_dict[cleaned_param])
else:
output_string += '"{}" : "{}",\n'.format(param[0], param[1])
output_string = output_string[:-2]
output_string += '}}]'
else:
output_string += '"parameters":{\n'
for param in parameters:
if param[0] in default_value_dict.keys():
output_string += '"{}" : "{}",\n'.format(param[0], default_value_dict[param[0]])
else:
output_string += '"{}" : "{}",\n'.format(param[0], param[1])
output_string = output_string[:-1]
output_string += '}}]'
return output_string
#Define a bounding box class for use in checking for collisions
class bounding_box:
def __init__(self, min_x, max_x, min_y, max_y, min_z, max_z):
self.min_x = min_x
self.max_x = max_x
self.min_y = min_y
self.max_y = max_y
self.min_z = min_z
self.max_z = max_z
def print_bounds(self):
print("x [{},{}], y [{},{}], z [{},{}]".format(str(self.min_x), str(self.max_x),str(self.min_y), str(self.max_y),str(self.min_z), str(self.max_z)))
#Define a part class for containing bounding box and/or any future information that will be critical to the part (ports, orientation requirements, etc.)
class part():
def __init__(self, pid, part_type = 'p', centroid = (0,0,0), x_width = 1, y_height = 1, z_depth = 1):
self.centroid = centroid
self.x_width = x_width
self.y_height = y_height
self.z_depth = z_depth
self.part_type = part_type
self.pid = pid
self.connections = {}
min_x = centroid[0] - x_width/2
max_x = centroid[0] + x_width/2
min_y = centroid[1] - y_height/2
max_y = centroid[1] + y_height/2
min_z = centroid[2] - z_depth/2
max_z = centroid[2] + z_depth/2
self.bounding_box = bounding_box(min_x, max_x, min_y, max_y, min_z, max_z)
#TODO: add a complex bounding box for non_parallel wings. Worst case scenario: set of consecutive, contiguous, cuboid bounding boxes.
#Theta should be in radians
def calculate_non_parallel_wing_bounding_box(theta, x_width, y_height, z_depth):
functional_x_width = math.cos(theta)*x_width + math.sin(theta)*y_height
functional_y_height = math.sin(theta)*x_width + math.cos(theta)*y_height
return (functional_x_width,functional_y_height,z_depth)
def add_connection(self, src, dst):
self.connections[src] = dst
class connector(part):
def __init__(self, pid, centroid = [0,0,0], buffer_connector = False, uav = False, hub_type = 'part'):
part.__init__(self, pid, part_type = 'c')
self.centroid = centroid
self.buffer_connector = buffer_connector
self.hub_type = hub_type
if not uav:
self.connections = {'front': None, 'rear' : None, 'top': None, 'bottom': None, 'left': None, 'right': None}
else:
if hub_type == 'main':
self.connections = {'front': None, 'rear' : None, 'top': None, 'left': None, 'right': None}
elif hub_type == 'buffer':
self.connections = {'front': None, 'rear' : None, 'top': None, 'bottom': None}
elif hub_type == 'part':
self.connections = {'front': None, 'rear' : None, 'top': None, 'bottom': None, 'right': None}
elif hub_type == 'fuselage':
self.connections = {'front': None, 'rear' : None, 'top': None, 'bottom': None, 'left': None, 'right': None}
class tube(part):
def __init__(self, pid, centroid = [0,0,0]):
part.__init__(self, pid, part_type = 't')
# self.centroid = centroid
# self.buffer_connector = buffer_connector
self.connections = {'front': None, 'rear' : None}
#Cluster class for string segments. May not be necessary
#TODO: change this class to consider individual parts and separate connector groups as tokens
class cluster:
def __init__(self, tokens = [], positionally_locked = False, separate_connector = False):
self.tokens = tokens
self.positionally_locked = positionally_locked
self.separate_connector = separate_connector
#Design class for holding and calculating everything relevant to the design's part placement including
#bounding boxes, parts, clusters and the functions for parsing and placing those items
class design:
def __init__(self, clusters = [], uav = False):
self.bounding_boxes = []
self.parts = {}
self.part_id_count = 0
self.tube_id_count = 0
self.part_id_count = 0
self.uav = uav
self.initial_connector = connector("c" + str(self.part_id_count))
self.add_part(self.initial_connector)
self.part_id_count += 1
self.connectors = {}
self.frontmost_connector = self.initial_connector
self.rearmost_connector = self.initial_connector
self.initial_fuselage_placed = False
self.clusters = clusters
self.order_clusters()
#TODO: inefficient boolean, should be able to reduce to three or
def check_interference(self, box1, box2):
if (box1.max_x > box2.min_x and box1.max_x < box2.max_x) or (box1.min_x > box2.min_x and box1.min_x < box2.max_x) or ((box1.min_x < box2.min_x and box1.max_x > box2.max_x)):
if (box1.max_y > box2.min_y and box1.max_y < box2.max_y) or (box1.min_y > box2.min_y and box1.min_y < box2.max_y) or ((box1.min_y < box2.min_y and box1.max_y > box2.max_y)):
if (box1.max_z > box2.min_z and box1.max_z < box2.max_z) or (box1.min_z > box2.min_z and box1.min_z < box2.max_z) or ((box1.min_z < box2.min_z and box1.max_z > box2.max_z)):
return True
return False
#Simultaneously check for conflicts and add new bounding box
def add_bounding_box(self, new_box):
for bounding_box1 in self.bounding_boxes:
for bounding_box2 in self.bounding_boxes:
if self.check_interference(bounding_box1,bounding_box2):
return False
self.bounding_boxes.append(new_box)
return True
#Add a part, calls bounding box check
def add_part(self, part):
if not part.part_type in ['c','t']:
if self.add_bounding_box(part.bounding_box):
self.parts[part.pid] = part
else:
print("Return value:" + str(self.add_bounding_box(part.bounding_box)))
print("Collision detected, failed to add part")
print("PID:" + part.pid)
print("centroid:")
print(part.centroid)
self.print_parts_and_centroids()
sys.exit()
else:
self.parts[part.pid] = part
def make_connection(self, src_pid, src_conn, dst_pid, dst_conn):
# If we are using UAV style connections, utilize a tube to connect the two parts
if self.uav and not (self.parts[dst_pid].part_type in ['cg','f']):
connecting_tube = tube(pid = 't' + str(self.tube_id_count))
self.tube_id_count += 1
self.parts[src_pid].connections[src_conn] = connecting_tube.pid
connecting_tube.connections["BaseConnection"] = src_pid
self.parts[dst_pid].connections[dst_conn] = connecting_tube.pid
connecting_tube.connections["EndConnection"] = dst_pid
self.add_part(connecting_tube)
# If we are using UAM, simply connect the two parts
else:
self.parts[src_pid].connections[src_conn] = dst_pid
self.parts[dst_pid].connections[dst_conn] = src_pid
def print_parts_and_centroids(self):
for key in self.parts.keys():
part = self.parts[key]
print(part.pid)
part.bounding_box.print_bounds()
def z_bound_check(self, part, z_min, z_max):
if part.bounding_box.max_z > z_max:
z_max = part.bounding_box.max_z
if part.bounding_box.min_z > z_min:
z_min = part.bounding_box.min_z
return z_min, z_max
def get_buffer_connectors(self, z = None, y = None):
buffer_connectors = []
for key in self.parts.keys():
part = self.parts[key]
if part.part_type in ['bc','c']:
if part.buffer_connector:
if z:
if y:
if part.centroid[1] == y and part.centroid[2] == z:
buffer_connectors.append(part)
else:
if part.centroid[2] == z:
buffer_connectors.append(part)
else:
buffer_connectors.append(part)
return buffer_connectors
def find_valid_buffer(self, z_bound, minimum_position, direction, y_bound = None):
possible_connectors = self.get_buffer_connectors(z = z_bound, y = y_bound)
# minimum_position = x_bound + ((subcluster_width/2) * direction)
for connector in possible_connectors:
if direction == 1:
if connector.centroid[0] >= minimum_position:
return connector
else:
if connector.centroid[0] <= minimum_position:
return connector
return None
def determine_quadrant(self, schema, index, centered):
centered_adder = 1 if centered else 0
# print(schema)
if schema == "Staggered":
return (index + centered_adder) % 4
if schema == "Inverse Staggered":
return ((index + centered_adder) % 4) + 2
if schema == "Grouped":
return ((index + centered_adder) % 2)
if schema == "Inverse Grouped":
return ((index + centered_adder) % 2) + 2
#set clusters in order they should be processed (center, fuselage containing cluster first, left, then right.)
def order_clusters(self):
new_clusters = []
index = math.floor(len(self.clusters)/2)
alternator = -1
offset = 0
i = 0
while i < len(self.clusters):
new_clusters.append(self.clusters[index + (offset * alternator)])
if alternator == -1:
offset += 1
alternator *= -1
i += 1
# for cluster in self.clusters:
# if 'f' in cluster:
# new_clusters = [cluster] + new_clusters
# else:
# new_clusters.append(cluster)
self.clusters = new_clusters
#Main function call for placing parts in 3d space
#TODO: possible replace cursor list with a class for readability
def place_all_parts(self):
# Create cursors to track position both in front of and behind base
cursor = [0,0,0]
front_cursor = [0,0,0]
rear_cursor = [0,0,0]
z_min = 0
z_max = 0
# Create an alternator for going between front and rear when placing clusters
alternator = 1
direction = "front"
cluster = self.clusters[0]
connector = self.frontmost_connector
print("placing cluster: ")
print(cluster)
cursor, z_min, z_max, return_connector = self.place_cluster_pos_lock(cluster, cursor, connector, direction)
temporary_z_buffer = 10
rear_cursor[2] += z_min
rear_cursor[2] -= temporary_z_buffer
front_cursor[2] += z_max
front_cursor[2] += temporary_z_buffer
#For each cluster, identify a connector to branch off of and a cursor to use. Update cursors from maxes of last iteration and place
temporary_z_buffer = 10
for cluster in self.clusters[1:]:
print("placing cluster: ")
print(cluster)
if alternator == -1:
connector = self.frontmost_connector
rear_cursor[2] += z_min
rear_cursor[2] -= temporary_z_buffer
cursor = front_cursor
direction = "front"
cursor, z_min, z_max, self.frontmost_connector = self.place_cluster_pos_lock(cluster, cursor, connector, direction)
else:
front_cursor[2] += z_max
front_cursor[2] += temporary_z_buffer
connector = self.rearmost_connector
cursor = rear_cursor
direction = "rear"
cursor, z_min, z_max, self.rearmost_connector = self.place_cluster_pos_lock(cluster, cursor, connector, direction)
alternator *= -1
#Place clusters where parts' centroids have the same z value
#Account for number of separate connector clusters
def place_cluster_pos_lock(self, cluster, cursor, origin_connector, direction = "front"):
#Count subclusters and track where they start/end
base_connector = None
subcluster_count = 0
tokens = cluster
subcluster_boundaries = []
subclusters = []
i = 0
while i < len(tokens):
if tokens[i] == '(':
subcluster_count += 1
subcluster_start = i
subcluster_end = tokens.index(')',i)
subclusters.append(tokens[subcluster_start+1:subcluster_end])
cutting_floor = subcluster_start if subcluster_start == 0 else subcluster_start
cutting_roof = subcluster_end + 1 if subcluster_end == len(tokens)-1 else subcluster_end + 1
tokens = tokens[:subcluster_start] + tokens[subcluster_end+1:]
# schema = 'even' if (subcluster_count % 2 == 0) else 'odd'
else:
i += 1
i = 0
subcluster_index = 0
subcluster_processing_order = []
subcluster_boundary_index = len(subclusters)//2
subcluster_boundary_offset = 0
subcluster_boundary_alternator = 1
j = 0
while j < len(subclusters):
subcluster_processing_order.append(subclusters[
subcluster_boundary_index + (subcluster_boundary_offset *
subcluster_boundary_alternator)])
subcluster_boundary_alternator *= -1
if j % 2 == 0:
subcluster_boundary_offset += 1
j += 1
new_tokens = []
buffer_size = 1
k = 0
alternator = -1
offset = 0
#-x direction
leftmost = [x for x in cursor]
#+x direction
rightmost = [x for x in cursor]
# Count tokens in current cluster
w_count = 0
l_count = 0
p_count = 0
h_count = 0
for token in tokens:
w_count += 1 if token == 'w' else 0
l_count += 1 if token == 'l' else 0
p_count += 1 if token == 'p' else 0
h_count += 1 if token == 'h' else 0
#track how far we've moved along principle axis, forward or rearward
z_max = 0
z_min = 0
#fuselage cluster
if 'f' in tokens and not self.initial_fuselage_placed:
string_index = tokens.index('f')
# Get dimensions of fuselage, create is for fuselage, add part to design
fuselage_dimensions = part_dimensions['f']
fuselage_id = 'fuselage'
# 'f' + str(self.part_id_count)
self.part_id_count += 1
# differentiate uav/uam style interpretation
if not self.uav:
new_part = part(fuselage_id ,centroid=cursor, part_type='f', x_width=fuselage_dimensions["x_width"], y_height=fuselage_dimensions["y_height"], z_depth=fuselage_dimensions["z_depth"])
self.add_part(new_part)
# Track min and max z for incrementation (this will be repeated without comment)
z_min, z_max = self.z_bound_check(new_part, z_min, z_max)
# connect single initial connector to front fuselage, and connect rear of connector to front of fuselage
self.frontmost_connector.connections["rear"] = fuselage_id
self.parts[fuselage_id].connections['front'] = self.frontmost_connector.pid
# create rear connector, connect front of rear connector to rear of fuselage
new_connector = connector('c' + str(self.part_id_count))
new_connector.connections["front"] = fuselage_id
self.parts[fuselage_id].connections['rear'] = new_connector.pid
self.part_id_count += 1
self.rearmost_connector = new_connector
self.add_part(new_connector)
else:
temp_cursor = [x for x in cursor]
base_hub = connector('main_hub', cursor, uav = True, hub_type = 'fuselage')
self.add_part(base_hub)
temp_cursor[1] += fuselage_dimensions["y_height"]/2
fuselage = part(fuselage_id ,centroid=temp_cursor, part_type='f', x_width=fuselage_dimensions["x_width"], y_height=fuselage_dimensions["y_height"], z_depth=fuselage_dimensions["z_depth"])
self.add_part(fuselage)
temp_cursor[1] -= fuselage_dimensions["y_height"]/2
cargo_dimensions = part_dimensions['cg']
temp_cursor[1] -= cargo_dimensions["y_height"]/2
cargo = part('cargo_case', centroid = temp_cursor, part_type = 'cg', x_width=cargo_dimensions["x_width"], y_height=cargo_dimensions["y_height"], z_depth=cargo_dimensions["z_depth"])
self.add_part(cargo)
#disable
self.make_connection(base_hub.pid, 'top', fuselage.pid, 'BottomConnectore') #RUIN BOTTOM CONNECTOR NAME TO REMOVE FUSELAGE
self.make_connection(base_hub.pid, 'bottom', cargo.pid, 'top')
self.frontmost_connector = base_hub
self.rearmost_connector = base_hub
# If there are two wings
if w_count == 2:
if not self.uav:
# Create temporary cursor for placing parts. Start on left wing, moving cursor by fuselage/2
temp_cursor = [cursor[0] - fuselage_dimensions["x_width"]/2, cursor[1], cursor[2]]
# Grab dimensions of the wing and move cursor to new wing centroic
dimensions = part_dimensions['w']
temp_cursor[0] -= dimensions["x_width"]/2
# Create new part id and create new wing, place at current temp cursor location
new_id = 'w' + str(self.part_id_count)
self.part_id_count += 1
new_part = part(new_id, centroid = [temp_cursor[0],temp_cursor[1],temp_cursor[2]], part_type = 'w', x_width=dimensions["x_width"], y_height=dimensions["y_height"], z_depth=dimensions["z_depth"])
# Connect wing to fuselage and add part
new_part.connections["naca"] = fuselage_id
self.parts[fuselage_id].connections['naca1'] = new_part.pid
self.add_part(new_part)
z_min, z_max = self.z_bound_check(new_part, z_min, z_max)
# Move cursor to other side of fuselage + half of wing width to reach centroid
temp_cursor = [temp_cursor[0] + dimensions['x_width'], temp_cursor[1], temp_cursor[2]]
temp_cursor[0] += dimensions['x_width']
temp_cursor[0] += fuselage_dimensions['x_width']
# Create new part id and create new wing, place at current temp cursor location
new_id = 'w' + str(self.part_id_count)
new_part = part(new_id, centroid = [temp_cursor[0],temp_cursor[1],temp_cursor[2]], part_type = 'w', x_width=dimensions["x_width"], y_height=dimensions["y_height"], z_depth=dimensions["z_depth"])
self.part_id_count += 1
# Connect wing to fuselage and add part
new_part.connections["naca"] = fuselage_id
self.parts[fuselage_id].connections['naca2'] = new_part.pid
self.add_part(new_part)
z_min, z_max = self.z_bound_check(new_part, z_min, z_max)
# Add propeller on top of fuselage, if specified
if 'p' in tokens:
# Create temporary cursor for placing parts. Start on top of fuselage
temp_cursor[1] += fuselage_dimensions["y_height"]/2
# Grab dimensions for vertical propeller, move cursor to centroid
dimensions = part_dimensions['p']
temp_cursor[1] += direction["y_height"]/2
# Create new part and add to design, set connections
new_id = 'p' + str(self.part_id_count)
self.part_id_count += 1
new_part = part(new_id, centroid = temp_cursor, part_type = 'p', x_width=dimensions["x_width"], y_height=dimensions["y_height"], z_depth=dimensions["z_depth"])
new_part.connections["baseplate"] = fuselage_id
self.parts[fuselage_id].connections['top'] = new_part.pid
self.add_part(new_part)
z_min, z_max = self.z_bound_check(new_part, z_min, z_max)
else:
temp_cursor = [x for x in cursor]