Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 00591 00592 00593 00594 00595 00596 00597 00598 00599 00600 00601 00602 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 00621 00622 00623 00624 00625 00626 00627 00628 00629 00630 00631 00632 00633 00634 00635 00636 00637 00638 00639 00640 00641 00642 00643 00644 00645 00646 00647 00648 00649 00650 00651 00652 00653 00654 00655 00656 00657 00658 00659 00660 00661 00662 00663 00664 00665 00666 00667 00668 00669 00670 00671 00672 00673 00674 00675 00676 00677 00678 00679 00680 00681 00682 00683 00684 00685 00686 00687 00688 00689 00690 00691 00692 00693 00694 00695 00696 00697 00698 00699 00700 00701 00702 00703 00704 00705 00706 00707 00708 00709 00710 00711 00712 00713 00714 00715 00716 00717 00718 00719 00720 00721 00722 00723 00724 00725 00726 00727 00728 00729 00730 00731 00732 00733 00734 00735 00736 00737 00738 00739 00740 00741 00742 00743 00744 00745 00746 00747 00748 00749 00750 00751 00752 00753 00754 00755 00756 00757 00758 00759 00760 00761 00762 00763 00764 00765 00766 00767 00768 00769 00770 00771 00772 00773 00774 00775 00776 00777 00778 00779 00780 00781 00782 00783 00784 00785 00786 00787 00788 00789 00790 00791 00792 00793 00794 00795 00796 00797 00798 00799 00800 00801 00802 00803 00804 00805 00806 00807 00808 00809 00810 00811 00812 00813 00814 00815 00816 00817 00818 00819 00820 00821 00822 00823 00824 00825 00826 00827 00828 00829 00830 00831 00832 00833 00834 00835 00836 00837 00838 00839 00840 00841 00842 00843 00844 00845 00846 00847 00848 00849 00850 00851 00852 00853 00854 00855 00856 00857 00858 00859 00860 00861 00862 00863 00864 00865 00866 00867 00868 00869 00870 00871 00872 00873 00874 00875 00876 00877 00878 00879 00880 00881 00882 00883 00884 00885 00886 00887 00888 00889 00890 00891 00892 00893 00894 00895 00896 00897 00898 00899 00900 00901 00902 00903 00904 00905 00906 00907 00908 00909 00910 00911 00912 00913 00914 00915 00916 00917 00918 00919 00920 00921 00922 00923 00924 00925 00926 00927 00928 00929 00930 00931 00932 00933 00934 00935 00936 00937 00938 00939 00940 00941 00942 00943 00944 00945 00946 00947 00948 00949 00950 00951 00952 00953 00954 00955 00956 00957 00958 00959 00960 00961 00962 00963 00964 00965 00966 00967 00968 00969 00970 00971 00972 00973 00974 00975 00976 00977 00978 00979 00980 00981 00982 00983 00984 00985 00986 00987 00988 00989 00990 00991 00992 00993 00994 00995 00996 00997 00998 00999 01000 01001 01002 01003 01004 01005 01006 01007 01008 01009 01010 01011 01012 01013 01014 01015 01016 01017 01018 01019 01020 01021 01022 01023 01024 01025 01026 01027 01028 01029 01030 01031 01032 01033 01034 01035 01036 01037 01038 01039 01040 01041 01042 01043 01044 01045 01046 01047 01048 01049 01050 01051 01052 01053 01054 01055 01056 01057 01058 01059 01060 01061 01062 01063 01064 01065 01066 01067 01068 01069 01070 01071 01072 01073 01074 01075 01076 01077 01078 01079 01080 01081 01082 01083 01084 01085 01086 01087 01088 01089 01090 01091 01092 01093 01094 01095 01096 01097 01098 01099 01100 01101 01102 01103 01104 01105 01106 01107 01108 01109 01110 01111 01112 01113 01114 01115 01116 01117 01118 01119 01120 01121 01122 01123 01124 01125 01126 01127 01128 01129 01130 01131 01132 01133 01134 01135 01136 01137 01138 01139 01140 01141 01142 01143 01144 01145 01146 01147 01148 01149 01150 01151 01152 01153 01154 01155 01156 01157 01158 01159 01160 01161 01162 01163 01164 01165 01166 01167 01168 01169 01170 01171 01172 01173 01174 01175 01176 01177 01178 01179 01180 01181 01182 01183 01184 01185 01186 01187 01188 01189 01190 01191 01192 01193 01194 01195 01196 01197 01198 01199 01200 01201 01202 01203 01204 01205 01206 01207 01208 01209 01210 01211 01212 01213 01214 01215 01216 01217 01218 01219 01220 01221 01222 01223 01224 01225 01226 01227 01228 01229 01230 01231 01232 01233 01234 01235 01236 01237 01238 01239 01240 01241 01242 01243 01244 01245 01246 01247 01248 01249 01250 01251 01252 01253 01254 01255 01256 01257 01258 01259 01260 01261 01262 01263 01264 01265 01266 01267 01268 01269 01270 01271 01272 01273 01274 01275 01276 01277 01278 01279 01280 01281 01282 01283 01284 01285 01286 01287 01288 01289 01290 01291 01292 01293 01294 01295 01296 01297 01298 01299 01300 01301 01302 01303 01304 01305 01306 01307 01308 01309 01310 01311 01312 01313 01314 01315 01316 01317 01318 01319 01320 01321 01322 01323 01324 01325 01326 01327 01328 01329 01330 01331 01332 01333 01334 01335 01336 01337 01338 01339 01340 01341 01342 01343 01344 01345 01346 01347 01348 01349 01350 01351 01352 01353 01354 01355 01356 01357 01358 01359 01360 01361 01362 01363 01364 01365 01366 01367 01368 01369 01370 01371 01372 01373 01374 01375 01376 01377 01378 01379 01380 01381 01382 01383 01384 01385 01386 01387 01388 01389 01390 01391 01392 01393 01394 01395 01396 01397 01398 01399 01400 01401 01402 01403 01404 01405 01406 01407 01408 01409 01410 01411 01412 01413 01414 01415 01416 01417 01418 01419 01420 01421 01422 01423 01424 01425 01426 01427 01428 01429 01430 01431 01432 01433 01434 01435 01436 01437 01438 01439 01440 01441 01442 01443 01444 01445 01446 01447 01448 01449 01450 01451 01452 01453 01454 01455 01456 01457 01458 01459 01460 01461 01462 01463 01464 01465 01466 01467 01468 01469 01470 01471 01472 01473 01474 01475 01476 01477 01478 01479 01480 01481 01482 01483 01484 01485 01486 01487 01488 01489 01490 01491 01492 01493 01494 01495 01496 01497 01498 01499 01500 01501 01502 01503 01504 01505 01506 01507 01508 01509 01510 01511 01512 01513 01514 01515 01516 01517 01518 01519 01520 01521 01522 01523 01524 01525 01526 01527 01528 01529 01530 01531 01532 01533 01534 01535 01536 01537 01538 01539 01540 01541 01542 01543 01544 01545 01546 01547 01548 01549 01550 01551 01552 01553 01554 01555 01556 01557 01558 01559 01560 01561 01562 01563 01564 01565 01566 01567 01568 01569 01570 01571 01572 01573 01574 01575 01576 01577 01578 01579 01580 01581 01582 01583 01584 01585 01586 01587 01588 01589 01590 01591 01592 01593 01594 01595 01596 01597 01598 01599 01600 01601 01602 01603 01604 01605 01606 01607 01608 01609 01610 01611 01612 01613 01614 01615 01616 01617 01618 01619 01620 01621 01622 01623 01624 01625 01626 01627 01628 01629 01630 01631 01632 01633 01634 01635 01636 01637 01638 01639 01640 01641 01642 01643 01644 01645 01646 01647 01648 01649 01650 01651 01652 01653 01654 01655 01656 01657 01658 01659 01660 01661 01662 01663 01664 01665 01666 01667 01668 01669 01670 01671 01672 01673 01674 01675 01676 01677 01678 01679 01680 01681 01682 01683 01684 01685 01686 01687 01688 01689 01690 01691 01692 01693 01694 01695 01696 01697 01698 01699 01700 01701 01702 01703 01704 01705 01706 01707 01708 01709 01710 01711 01712 01713 01714 01715 01716 01717 01718 01719 01720 01721 01722 01723 01724 01725 01726 01727 01728 01729 01730 01731 01732 01733 01734 01735 01736 01737 01738 01739 01740 01741 01742 01743 01744 01745 01746 01747 01748 01749 01750 01751 01752 01753 01754 01755 01756 01757 01758 01759 01760 01761 01762 01763 01764 01765 01766 01767 01768 01769 01770 01771 01772 01773 01774 01775 01776 01777 01778 01779 01780 01781 01782 01783 01784 01785 01786 01787 01788 01789 01790 01791 01792 01793 01794 01795 01796 01797 01798 01799 01800 01801 01802 01803 01804 01805 01806 01807 01808 01809 01810 01811 01812 01813 01814 01815 01816 01817 01818 01819 01820 01821 01822 01823 01824 01825 01826 01827 01828 01829 01830 01831 01832 01833 01834 01835 01836 01837 01838 01839 01840 01841 01842 01843 01844 01845 01846 01847 01848 01849 01850 01851 01852 01853 01854 01855 01856 01857 01858 01859 01860 01861 01862 01863 01864 01865 01866 01867 01868 01869 01870 01871 01872 01873 01874 01875 01876 01877 01878 01879 01880 01881 01882 01883 01884 01885 01886 01887 01888 01889 01890 01891 01892 01893 01894 01895 01896 01897 01898 01899 01900 01901 01902 01903 01904 01905 01906 01907 01908 01909 01910 01911 01912 01913 01914 01915 01916 01917 01918 01919 01920 01921 01922 01923 01924 01925 01926 01927 01928 01929 01930 01931 01932 01933 01934 01935 01936 01937 01938 01939 01940 01941 01942 01943 01944 01945 01946 01947 01948 01949 01950 01951 01952 01953 01954 01955 01956 01957 01958 01959 01960 01961 01962 01963 01964 01965 01966 01967 01968 01969 01970 01971 01972 01973 01974 01975 01976 01977 01978 01979 01980 01981 01982 01983 01984 01985 01986 01987 01988 01989 01990 01991 01992 01993 01994 01995 01996 01997 01998 01999 02000 02001 02002 02003 02004 02005 02006 02007 02008 02009 02010 02011 02012 02013 02014 02015 02016 02017 02018 02019 02020 02021 02022 02023 02024 02025 02026 02027 02028 02029 02030 02031 02032 02033 02034 02035 02036 02037 02038 02039 02040 02041 02042 02043 02044 02045 02046 02047 02048 02049 02050 02051 02052 02053 02054 02055 02056 02057 02058 02059 02060 02061 02062 02063 02064 02065 02066 02067 02068 02069 02070 02071 02072 02073 02074 02075 02076 02077 02078 02079 02080 02081 02082 02083 02084 02085 02086 02087 02088 02089 02090 02091 02092 02093 02094 02095 02096 02097 02098 02099 02100 02101 02102 02103 02104 02105 02106 02107 02108 02109 02110 02111 02112 02113 02114 02115 02116 02117 02118 02119 02120 02121 02122 02123 02124 02125 02126 02127 02128 02129 02130 02131 02132 02133 02134 02135 02136 02137 02138 02139 02140 02141 02142 02143 02144 02145 02146 02147 02148 02149 02150 02151 02152 02153 02154 02155 02156 02157 02158 02159 02160 02161 02162 02163 02164 02165 02166 02167 02168 02169 02170 02171 02172 02173 02174 02175 02176 02177 02178 02179 02180 02181 02182 02183 02184 02185 02186 02187 02188 02189 02190 02191 02192 02193 02194 02195 02196 02197 02198 02199 02200 02201 02202 02203 02204 02205 02206 02207 02208 02209 02210 02211 02212 02213 02214 02215 02216 02217 02218 02219 02220 02221 02222 02223 02224 02225 02226 02227 02228 02229 02230 02231 02232 02233 02234 02235 02236 02237 02238 02239 02240 02241 02242 02243 02244 02245 02246 02247 02248 02249 02250 02251 02252 02253 02254 02255 02256 02257 02258 02259 02260 02261 02262 02263 02264 02265 02266 02267 02268 02269 02270 02271 02272 02273 02274 02275 02276 02277 02278 02279 02280 02281 02282 02283 02284 02285 02286 02287 02288 02289 02290 02291 02292 02293 02294 02295 02296 02297 02298 02299 02300 02301 02302 02303 02304 02305 02306 02307 02308 02309 02310 02311 02312 02313 02314 02315 02316 02317 02318 02319 02320 02321 02322 02323 02324 02325 02326 02327 02328 02329 02330 02331 02332 02333 02334 02335 02336 02337 02338 02339 02340 02341 02342 02343 02344 02345 02346 02347 02348 02349 02350 02351 02352 02353 02354 02355 02356 02357 02358 02359 02360 02361 02362 02363 02364 02365 02366 02367 02368 02369 02370 02371 02372 02373 02374 02375 02376 02377 02378 02379 02380 02381 02382 02383 02384 02385 02386 02387 02388 02389 02390 02391 02392 02393 02394 02395 02396 02397 02398 02399 02400 02401 02402 02403 02404 02405 02406 02407 02408 02409 02410 02411 02412 02413 02414 02415 02416 02417 02418 02419 02420 02421 02422 02423 02424 02425 02426 02427 02428 02429 02430 02431 02432 02433 02434 02435 02436 02437 02438 02439 02440 02441 02442 02443 02444 02445 02446 02447 02448 02449 02450 02451 02452 02453 02454 02455 02456 02457 02458 02459 02460 02461 02462 02463 02464 02465 02466 02467 02468 02469 02470 02471 02472 02473 02474 02475 02476 02477 02478 02479 02480 02481 02482 02483 02484 02485 02486 02487 02488 02489 02490 02491 02492 02493 02494 02495 02496 02497 02498 02499 02500 02501 02502 02503 02504 02505 02506 02507 02508 02509 02510 02511 02512 02513 02514 02515 02516 02517 02518 02519 02520 02521 02522 02523 02524 02525 02526 02527 02528 02529 02530 02531 02532 02533 02534 02535 02536 02537 02538 02539 02540 02541 02542 02543 02544 02545 02546 02547 02548 02549 02550 02551 02552 02553 02554 02555 02556 02557 02558 02559 02560 02561 02562 02563 02564 02565 02566 02567 02568 02569 02570 02571 02572 02573 02574 02575 02576 02577 02578 02579 02580 02581 02582 02583 02584 02585 02586 02587 02588 02589 02590 02591 02592 02593 02594 02595 02596 02597 02598 02599 02600 02601 02602 02603 02604 02605 02606 02607 02608 02609 02610 02611 02612 02613 02614 02615 02616 |
class KRobot extends KVehicle config(USARBot) abstract; //////////////////////////////////////////////// // PHYSICAL ROBOT //////////////////////////////////////////////// /* // Wheel Properties var enum PowerTypes{Not_Powered, Left_Powered, Right_Powered}List1; var enum SteerTypes{Not_Steered, Front_Steered, Rear_Steered}List2; struct WheelData { var int Number; //Wheel Number. Note: this number needs to match the order in which the joints were declared in USARBot.ini, starting from 0. var PowerTypes PowerType; //Is the wheel not powered? Is the wheel powered by the left throttle? Is the wheel powered by the right throttle? //Note: the next two variables are not needed for skid-steer vehicles var SteerTypes SteerType; //Is the wheel steered? If so, is it steering using the front steering angle or the back steering angle? var float MaxSteerAngle; //Maximum steering angle for the wheel. }; var array<WheelData> Wheels; //Array to store the wheel data of all the wheels */ // Part Definiens struct JointPart { // Part var() name PartName; var() class<KActor> PartClass; var() vector DrawScale3D; // Joint var() class<KConstraint> JointClass; var() bool bSteeringLocked; var() bool bSuspensionLocked; var() float BrakeTorque; var() name Parent; var() vector ParentPos; //var() rotator ParentRot; var() vector ParentAxis; var() vector ParentAxis2; var() vector SelfPos; var() vector SelfAxis; var() vector SelfAxis2; }; var config array<JointPart> JointParts; // Mission Package Data Structure struct MisPkg { var() name PkgName; var() vector Location; var() class<MisPkgInfo> PkgClass; }; var config array<MisPkg> MisPkgs; // Joint Control struct JointControl { var byte state; // Control state: // 0: no commands; // 1: new command; // 2: finished; var float steer; // Steer angle var byte order; // Specify the followed value. var float value; // Control value: // order = 0 , value=absolute angle; // order = 1 , value=absolute speed; // order = 2 , value=absolute torque; // order = 10 , value=relative angle; // order = 11 , value=relative speed; // order = 12 , value=relative torque; var byte lastCommandId; // There are new commands if lastCommandId != RS_JointsCommandId //Variables used only by order = 0 control: var float angle; // the desired spining angle. used for order=0 control. var int startAng; // the start angle. used for compare spined angle. }; var array<JointControl> JointsControl; struct RobotSkin { var string Name; var texture Skin; var string Comment; }; var config array<RobotSkin> RobotSkins; //======================= // Networking RobotState //======================= // // Replication variables used to update Robot State on clients var KRBVec RS_ChassisPosition; var Quat RS_ChassisQuaternion; var KRBVec RS_ChassisLinVel; var KRBVec RS_ChassisAngVel; // dynamic array canot be replicated. So we must use static array here. // Here, to make the client and server have the same state, we directly // replicate the RigidBodyState. In the KCar class, it replicates the // RigidBodyState related to the chassis. I don't know why they use relative // state. I had tried to use relative state. But it involves vector and // quaternion calculation. We need to calculate the relative pos and relative // quat. For relative pos, it's just subtract part's (wheel's) pos from chassis // pos. For relative quat, we need to use the third axis, that's // Joints[i].KPriAxis1 Cross Joints[i].KSecAxis1), to calculate the relative // quat. However, I cannot figure out the correct calculating method for general // case, such as connect the y axis of the part to the x axis of the chassis // through a joint. ANYWAY, the simplest, most stable and straightforward method // is replicating all the (absolute) RigidBodyState. If the server is correct, // then the client should also be correct. The only weakness of this method is we // need to replicate more data. var KRBVec RS_PartsPos[32]; var Quat RS_PartsQuat[32]; var vector RS_PartsLinVel[32]; var vector RS_PartsAngVel[32]; var float RS_JointsSteer[32]; var byte RS_JointsOrder[32]; var float RS_JointsValue[32]; var byte RS_JointsCommandId[32]; // It denotes new replicated robot state. VehicleStateReceived will // load on client side these new params and set bNewRobotState to true. // Should be a boolean but it's a byte that increments at each replication, // otherwise replication mechanism would not work becasue bool var would be // always true on server (read the code for further details). // (using struct wuold be a possible solution to replication, but it's not necessary) var byte RS_RobotUpdateId; //Used to change the robot skin var string RS_skinName; var byte RS_skinUpdateId; // -- End Replication variables // if CacheRobotUpdateId on client is different from RS_RobotUpdateId received from server // then ther's a new robot state to be loaded. At this point CacheRobotUpdateId is set // equal to RS_RobotUpdateId and bNewRobotState is set to true. var byte CacheRobotUpdateId; var byte CacheSkinUpdateId; // New RB params were loaded from replication and we must notify // Karma to update RB state on client side var bool bNewRobotState; var bool bNewCommand; //only used on server in ProcessCarInput() var float NextNetUpdateTime; // Next time we should force an update of vehicles state. var float MaxNetUpdateInterval; // Parts that build a robot (every part has a part a parent and a joint) var array<KActor> Parts; var array<Actor> Parents; var array<KConstraint> Joints; //======================== // KCarWheelJoint settings //======================== // Steering var float SteerPropGap; var float SteerTorque; var float SteerSpeed; // KCarWheelSuspension setting var float SuspStiffness; var float SuspDamping; var float SuspHighLimit; var float SuspLowLimit; var float SuspRef; // The Max torque for all the joints var config float MaxTorque; var config float SafeForce; var config float ProtectTime; // KDHinge Joint settings var config float HingePropGap; // KCarWheelJoint defalut working torque var config float MotorTorque; var config float MotorSpeed; var float uuMotorSpeed; var config float maxSpinSpeed; //======================== // KTire settings //======================== var float TireRollFriction; var float TireLateralFriction; var float TireRollSlip; var float TireLateralSlip; var float TireMinSlip; var float TireSlipRate; var float TireSoftness; var float TireAdhesion; var float TireRestitution; //======================== // Robot parameters var config float Payload; var config float Weight; var KRigidBodyState ChassisState; var KRigidBodyState TeleportLocation; //!< Used to move the robot with MoveRobot() function. var config float ChassisMass; var config InterpCurve TorqueCurve; // Engine RPM in, Torque out. var float HitSoundThreshold; var float WheelRadius; var vector Dimensions; // Flip var config float FlipTorque; var config float FlipTime; var float FlipTimeLeft; //=============================== // Items mounted on the robot //=============================== // Item mount structure struct sItem { var class<Actor> ItemClass; var name Parent; var string ItemName; var vector Position; var vector Direction; var rotator uuDirection; }; // Sensors var config array<sItem> Sensors; var config float msgTimer; // Timer used for sending out sensor data var array<Sensor> SensorList; var array<byte> ProcessedSensors; // Effecters var config array<sItem> Effecters; var array<Effecter> EffecterList; // Battery var config int batteryLife; var int startTime; var int myLife; // Headlight var config sItem HeadLight; var USARHeadlight myHeadLight; var bool bHeadlightOn; var byte HeadlightItensity; // Camera var config array<sItem> Cameras; var array<RobotCamera> CamList; var RobotCamera myCamera; var int CameraZoom; var float PanSpeed, TiltSpeed; //========================= // Others //========================= // Variables used for programming var config bool bDebug; var int CurrentPart; var config bool bDisplayTeamBeacon; var float lastTime, previousTime; var vector lastLocation, previousLocation; var bool bRobotBuilt; var name fpsLogger; var config string ConverterClass; var USARConverter converter; var config bool bMountByUU; var config float logging_period; var bool bGroundTruth; var float old_time; var FileLog PosLog; var FileLog CollLog; var KSimParams oldKSP, newKSP; var name tmpName; // Used to convert string to name //var bool bstats; //used for bump/touch events. //var int bump_touch_cnt; // MultiView Addon var int ViewNum; //Viewport number (assigned by Register()) used by DrawHUD to render the scene var MultiView ViewManager; //the actual ViewManager actor (a bot) //############################################################################# // KROBOT CODE //############################################################################# replication { // We replicate the robot state. reliable if(Role == ROLE_Authority) RS_ChassisPosition, RS_ChassisQuaternion, RS_ChassisLinVel, RS_ChassisAngVel, RS_PartsPos, RS_PartsQuat, RS_PartsLinVel, RS_PartsAngVel,RS_RobotUpdateId; reliable if(Role == ROLE_Authority) RS_JointsSteer, RS_JointsOrder, RS_JointsValue, RS_JointsCommandId; reliable if(Role == ROLE_Authority) FlipTimeLeft, CameraZoom, bHeadlightOn; reliable if(Role == ROLE_Authority) RS_skinName, RS_skinUpdateId, ViewManager, ViewNum; } simulated event PreBeginPlay() { local class<USARConverter> cClass; Super.PreBeginPlay(); bNoTeamBeacon=!bDisplayTeamBeacon; cClass = class<USARConverter>(DynamicLoadObject(ConverterClass, class'Class')); converter = new cClass; ConvertParam(converter); if (MotorTorque>MaxTorque) MotorTorque = MaxTorque; //Adjust Karma params KGetSimParams(oldKSP); newKSP = oldKSP; newKSP.Epsilon = 0.03; newKSP.GammaPerSec = 0.5; // newKSP.ContactSoftness = 0.001; newKSP.PenetrationScale = 5; KSetSimParams(newKSP); } simulated function ConvertParam(USARConverter converter) { local int i; if (converter==None) { uuMotorSpeed = MotorSpeed; } else { uuMotorSpeed = converter.SpinSpeedToUU(MotorSpeed); } if (!bMountByUU && converter!=None) { for (i=0;i<JointParts.length;i++) { JointParts[i].ParentPos = converter.LengthVectorToUU(JointParts[i].ParentPos); JointParts[i].SelfPos = converter.LengthVectorToUU(JointParts[i].SelfPos); } if (HeadLight.ItemName!="") { HeadLight.Position = converter.LengthVectorToUU(HeadLight.Position); HeadLight.uuDirection = converter.RotatorToUU(HeadLight.Direction); } for (i=0;i<Cameras.length;i++) { Cameras[i].Position = converter.LengthVectorToUU(Cameras[i].Position); Cameras[i].uuDirection = converter.RotatorToUU(Cameras[i].Direction); } for (i=0;i<Sensors.length;i++) { Sensors[i].Position = converter.LengthVectorToUU(Sensors[i].Position); Sensors[i].uuDirection = converter.RotatorToUU(Sensors[i].Direction); } for (i=0;i<Effecters.length;i++) { Effecters[i].Position = converter.LengthVectorToUU(Effecters[i].Position); Effecters[i].uuDirection = converter.RotatorToUU(Effecters[i].Direction); } } else { if (HeadLight.ItemName!="") { HeadLight.uuDirection.Roll = int(HeadLight.Direction.X); HeadLight.uuDirection.Pitch = int(HeadLight.Direction.Y); HeadLight.uuDirection.Yaw = int(HeadLight.Direction.Z); } for (i=0;i<Cameras.length;i++) { Cameras[i].uuDirection.Roll = int(Cameras[i].Direction.X); Cameras[i].uuDirection.Pitch = int(Cameras[i].Direction.Y); Cameras[i].uuDirection.Yaw = int(Cameras[i].Direction.Z); } for (i=0;i<Sensors.length;i++) { Sensors[i].uuDirection.Roll = int(Sensors[i].Direction.X); Sensors[i].uuDirection.Pitch = int(Sensors[i].Direction.Y); Sensors[i].uuDirection.Yaw = int(Sensors[i].Direction.Z); } for (i=0;i<Effecters.length;i++) { Effecters[i].uuDirection.Roll = int(Effecters[i].Direction.X); Effecters[i].uuDirection.Pitch = int(Effecters[i].Direction.Y); Effecters[i].uuDirection.Yaw = int(Effecters[i].Direction.Z); } } } // Register to the game function Register() { local USARDeathMatch UsarGame; local int Index; UsarGame = USARDeathMatch(Level.Game); Index = UsarGame.Vehicles.length; UsarGame.Vehicles.Insert(Index,1); UsarGame.Vehicles[Index]=self; //bstats = UsarGame.bstats; old_time = startTime; if(myCamera != none) { foreach AllActors(class'MultiView', ViewManager) break; } if(ViewManager != None) ViewNum = ViewManager.RegisterView(); else ViewNum = -1; } // Unregister from the game function Unregister() { local USARDeathMatch UsarGame; local int i; UsarGame = USARDeathMatch(Level.Game); for (i=0;i<UsarGame.Vehicles.length;i++) { if (UsarGame.Vehicles[i]==self) { UsarGame.Vehicles.Remove(i,1); break; } } if(ViewManager != None) { ViewManager.DeleteView(ViewNum); } } // When new information is received, see if its new. If so, pass bits off the the wheels. // Each part will then update its rigid body position via the KUpdateState event. // JTODO: This is where clever unpacking would happen. simulated event VehicleStateReceived() { local KTire Tire; local KDPart Part; local int i; local bool UpdateParts; /* KGetRigidBodyState(ChassisState); log("State<<"@ChassisState.Position.X@ChassisState.Position.Y@ChassisState.Position.Z); log(" "@ChassisState.Quaternion.X@ChassisState.Quaternion.Y@ChassisState.Quaternion.Z@ChassisState.Quaternion.W); log(" "@ChassisState.LinVel.X@ChassisState.LinVel.Y@ChassisState.LinVel.Z); log(" "@ChassisState.AngVel.X@ChassisState.AngVel.Y@ChassisState.AngVel.Z@">>"); log("Receive<<"@RS_ChassisPosition.X@RS_ChassisPosition.Y@RS_ChassisPosition.Z); log(" "@RS_ChassisQuaternion.X@RS_ChassisQuaternion.Y@RS_ChassisQuaternion.Z); log(" "@RS_ChassisLinVel.X@RS_ChassisLinVel.Y@RS_ChassisLinVel.Z); log(" "@RS_ChassisAngVel.X@RS_ChassisAngVel.Y@RS_ChassisAngVel.Z@">>"); */ // Don't do anything if vehicle isn't started up. if(!bRobotBuilt) { if(Parts.length == 0) return; for (i=0; i<Parts.length; i++) if (Parts[i] == None) return; bRobotBuilt = true; } //Serves a skin update request if(cacheSkinUpdateId != RS_skinUpdateId) { SetSkin(RS_skinName); cacheSkinUpdateId = RS_skinUpdateId; } /////////////////////////// // Update root chassis info /////////////////////////// if (CacheRobotUpdateId != RS_RobotUpdateId) { ChassisState.Position = RS_ChassisPosition; ChassisState.Quaternion = RS_ChassisQuaternion; ChassisState.LinVel = RS_ChassisLinVel; ChassisState.AngVel = RS_ChassisAngVel; UpdateParts = true; CacheRobotUpdateId = RS_RobotUpdateId; bNewRobotState = true; } // Figure out new state of parts for (i=0;i<Parts.length;i++) { /////////////////////////// // Update Parts /////////////////////////// if (UpdateParts) { if (Parts[i].IsA('KTire')) { Tire = KTire(Parts[i]); Tire.KGetRigidBodyState(Tire.ReceiveState); Tire.ReceiveState.Position = RS_PartsPos[i]; Tire.ReceiveState.Quaternion = RS_PartsQuat[i]; Tire.ReceiveState.LinVel = KRBVecFromVector(RS_PartsLinVel[i]); Tire.ReceiveState.AngVel = KRBVecFromVector(RS_PartsAngVel[i]); Tire.bReceiveStateNew = true; } else if (Parts[i].IsA('KDPart')) { Part = KDPart(Parts[i]); Part.KGetRigidBodyState(Part.ReceiveState); Part.ReceiveState.Position = RS_PartsPos[i]; Part.ReceiveState.Quaternion = RS_PartsQuat[i]; Part.ReceiveState.LinVel = KRBVecFromVector(RS_PartsLinVel[i]); Part.ReceiveState.AngVel = KRBVecFromVector(RS_PartsAngVel[i]); Part.bReceiveStateNew = true; } } /////////////////////////// // Update Commands /////////////////////////// if (JointsControl[i].lastCommandId!=RS_JointsCommandId[i]) { JointsControl[i].steer = RS_JointsSteer[i]; JointsControl[i].order = RS_JointsOrder[i]; JointsControl[i].value = RS_JointsValue[i]; JointsControl[i].state = 1; JointsControl[i].lastCommandId = RS_JointsCommandId[i]; } } } // This only update the chassis. The parts update themselves. simulated event bool KUpdateState(out KRigidBodyState newState) { // This should never get called on the server - but just in case! if(Role == ROLE_Authority) { if(!bNewRobotState) return false; else { // bNewRobotState will be true on server only if we're trying // to teleport the robot from one location to another. newState = TeleportLocation; bNewRobotState = false; return true; } } // Apply received data as new position of car chassis. newState = ChassisState; bNewRobotState = false; return true; } // Pack current state of whole car into the state struct, to be sent to the client. // Should only get called on the server. function PackState() { local KRigidBodyState RBState; local int i; local bool UpdateParts; if(!KIsAwake() && !bNewCommand) return; // Never send updates if physics is at rest if(Level.TimeSeconds > NextNetUpdateTime) { /////////////////////////// // Pack Chassis state /////////////////////////// KGetRigidBodyState(RBState); RS_ChassisPosition = RBState.Position; RS_ChassisQuaternion = RBState.Quaternion; RS_ChassisLinVel = RBState.LinVel; RS_ChassisAngVel = RBState.AngVel; UpdateParts = true; RS_RobotUpdateId += 1; NextNetUpdateTime = Level.TimeSeconds + MaxNetUpdateInterval; } // Get each part's state. for (i=0;i<Parts.length;i++) { /////////////////////////// // Pack Parts State /////////////////////////// if(UpdateParts) { Parts[i].KGetRigidBodyState(RBState); RS_PartsPos[i] = RBState.Position; RS_PartsQuat[i] = RBState.Quaternion; RS_PartsLinVel[i] = KRBVecToVector(RBState.LinVel); RS_PartsAngVel[i] = KRBVecToVector(RBState.AngVel); } /////////////////////////// // Pack Commands State /////////////////////////// if (JointsControl[i].state==1) { RS_JointsCommandId[i]+=1; RS_JointsSteer[i] = JointsControl[i].steer; RS_JointsOrder[i] = JointsControl[i].order; RS_JointsValue[i] = JointsControl[i].value; } } } function RobotCamera GetCamera(String name) { local int i; for (i=0;i<CamList.length;i++) if (CamList[i].ItemName==name) return CamList[i]; return myCamera; } simulated function Actor FindPart(name PartName) { local int i; if (PartName == '' || PartName == 'None') return self; for (i=0;i<JointParts.length;i++) { if (JointParts[i].PartName == PartName) { return Parts[i]; } } return None; } simulated function int FindLinkParent(MisPkgInfo Package, int ParentLinkNumber) { local int i; for(i=0; i<Package.Links.length; i++) { if(Package.Links[i].LinkNumber == ParentLinkNumber) { return i; } } return -1; } simulated function MisPkgLinkInfo getMisPkgLinkInfo(int PartNumber, string MisPkgName) { local int i,j; local MisPkgInfo aMisPkg; if(MisPkgName == "") { for(i=0; i<MisPkgs.length; i++) { aMisPkg = New MisPkgs[i].PkgClass; for(j=0; j<aMisPkg.Links.Length; j++) { if(aMisPkg.Links[j].LinkNumber == PartNumber) { return New aMisPkg.Links[j].LinkClass; } } } } else { for(i=0; i<MisPkgs.Length; i++) { if(string(MisPkgs[i].PkgName) == MisPkgName) { aMisPkg = New MisPkgs[i].PkgClass; for(j=0; j<aMisPkg.Links.Length; j++) { if(aMisPkg.Links[j].LinkNumber == PartNumber) { return New aMisPkg.Links[j].LinkClass; } } break; } } } return None; } simulated function int FindMisPkgLinkIndex(Name LinkName) { local int i; for(i=0; i<Joints.Length; i++) { if(JointParts[i].PartName == LinkName) { return i; } } return -1; } simulated function name getMisPkgPartName_str(string PkgName, int LinkNumber) { tmpName = ''; if(LinkNumber >= 0) { SetPropertyText("tmpName", PkgName $ "_Link" $ string(LinkNumber)); } return tmpName; } simulated function name getMisPkgPartName(Name PkgName, int LinkNumber) { tmpName = ''; if(LinkNumber >= 0) { SetPropertyText("tmpName", string(PkgName) $ "_Link" $ string(LinkNumber)); } return tmpName; } simulated function int getLinkNumber(string strLink) { return int(Right(strLink, Len(strLink) - (InStr(strLink, "Link") + 4))); } simulated function string getMisPkgName(string strLink) { return Left(strLink, InStr(strLink, "_Link")); } simulated function PostNetBeginPlay() { local int i, j; local Actor Parent; local vector RotX, RotY, RotZ, offset; local MisPkgInfo aMisPkg; local MisPkgLinkInfo selfLink, parentLink; Super.PostNetBeginPlay(); // Turn the information about the mission packages into joint parts for(i=0; i<MisPkgs.length; i++) { aMisPkg = New MisPkgs[i].PkgClass; for(j=0; j<aMisPkg.Links.length; j++) { selfLink = New aMisPkg.Links[j].LinkClass; JointParts.Insert(JointParts.length, 1); // Make space in the dynamic array to add a part from the mission package JointParts[JointParts.length - 1].PartName = getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].LinkNumber); JointParts[JointParts.length - 1].PartClass = selfLink.ModelClass; JointParts[JointParts.length - 1].DrawScale3D = aMisPkg.Links[j].DrawScale3D; JointParts[JointParts.length - 1].bSteeringLocked = true; JointParts[JointParts.length - 1].bSuspensionLocked = true; JointParts[JointParts.length - 1].BrakeTorque = 0; JointParts[JointParts.length - 1].Parent = getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].ParentLinkNumber); if(Caps(selfLink.getMountPointJointType(aMisPkg.Links[j].SelfMount)) == "REVOLUTE") { JointParts[JointParts.length - 1].JointClass = class'USARBot.KDHinge'; if(j == 0) { JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(MisPkgs[i].Location); } else { parentLink = New aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].LinkClass; JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(parentLink.getMountPointLocation(aMisPkg.Links[j].ParentMount) * aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].DrawScale3D); } JointParts[JointParts.length - 1].ParentAxis = (Vect(0,0,-1) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1); JointParts[JointParts.length - 1].SelfAxis = JointParts[JointParts.length - 1].ParentAxis; JointParts[JointParts.length - 1].ParentAxis2 = (Vect(0,1,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1); JointParts[JointParts.length - 1].SelfAxis2 = JointParts[JointParts.length - 1].ParentAxis2; JointParts[JointParts.length - 1].SelfPos = converter.LengthVectorToUU(selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D); } else if(Caps(selfLink.getMountPointJointType(aMisPkg.Links[j].SelfMount)) == "PRISMATIC") { JointParts[JointParts.length - 1].JointClass = class'USARBot.KSlider'; if(j == 0) { JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(MisPkgs[i].Location - (selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D)); } else { parentLink = New aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].LinkClass; JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU((parentLink.getMountPointLocation(aMisPkg.Links[j].ParentMount) * aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].DrawScale3D) - (selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D)); } JointParts[JointParts.length - 1].ParentAxis = (Vect(0,1,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1); JointParts[JointParts.length - 1].SelfAxis = JointParts[JointParts.length - 1].ParentAxis; JointParts[JointParts.length - 1].ParentAxis2 = (Vect(1,0,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1); JointParts[JointParts.length - 1].SelfAxis2 = JointParts[JointParts.length - 1].ParentAxis2; JointParts[JointParts.length - 1].SelfPos = converter.LengthVectorToUU(-selfLink.MaxRange * (Vect(0,0,-1) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount)))); } } } //////////////////////////////// // Create physical robot //////////////////////////////// for (CurrentPart=0;CurrentPart<JointParts.length;CurrentPart++) { // Find parent Parent = FindPart(JointParts[CurrentPart].Parent); if (Parent==None) continue; Parents[CurrentPart] = Parent; if (bDebug) log("<"@Parent@Parent.Location@Parent.Rotation@">"); GetAxes(Parent.Rotation,RotX,RotY,RotZ); //Spawn Joint (any KConstraint class) Joints[CurrentPart] = spawn(JointParts[CurrentPart].JointClass,Parent); if (Joints[CurrentPart].IsA('KSlider')) { KSlider(Joints[CurrentPart]).init1(Parent,JointParts[CurrentPart].ParentPos,JointParts[CurrentPart].ParentAxis,JointParts[CurrentPart].ParentAxis2, JointParts[CurrentPart].SelfPos,JointParts[CurrentPart].SelfAxis,JointParts[CurrentPart].SelfAxis2); offset = JointParts[CurrentPart].ParentPos - JointParts[CurrentPart].SelfPos; Parts[CurrentPart] = spawn(JointParts[CurrentPart].PartClass, KSlider(Joints[CurrentPart]).Part2,, Parent.Location + offset.X*RotX + offset.Y*RotY + offset.Z*RotZ,Parent.Rotation); Parts[CurrentPart].SetDrawScale3D(JointParts[CurrentPart].DrawScale3D); log("Init"@Joints[CurrentPart]); KSlider(Joints[CurrentPart]).init2(JointParts[CurrentPart].ParentPos,JointParts[CurrentPart].ParentAxis,JointParts[CurrentPart].ParentAxis2, Parts[CurrentPart],JointParts[CurrentPart].SelfPos,JointParts[CurrentPart].SelfAxis,JointParts[CurrentPart].SelfAxis2); } else { //Spawn Part offset = JointParts[CurrentPart].ParentPos - JointParts[CurrentPart].SelfPos; Parts[CurrentPart] = spawn(JointParts[CurrentPart].PartClass, Parent,, Parent.Location + offset.X*RotX + offset.Y*RotY + offset.Z*RotZ,Parent.Rotation); Parts[CurrentPart].SetDrawScale3D(JointParts[CurrentPart].DrawScale3D); //Set primary constraint params Joints[CurrentPart].KConstraintActor1 = Parent; Joints[CurrentPart].KPos1 = JointParts[CurrentPart].ParentPos/50; Joints[CurrentPart].KPriAxis1 = JointParts[CurrentPart].ParentAxis; if (VSize(JointParts[CurrentPart].ParentAxis2)>0) Joints[CurrentPart].KSecAxis1 = JointParts[CurrentPart].ParentAxis2; //Set secondary constraint params Joints[CurrentPart].KConstraintActor2 = Parts[CurrentPart]; Joints[CurrentPart].KPos2 = JointParts[CurrentPart].SelfPos/50; Joints[CurrentPart].KPriAxis2 = JointParts[CurrentPart].SelfAxis; if (VSize(JointParts[CurrentPart].SelfAxis2)>0) Joints[CurrentPart].KSecAxis2 = JointParts[CurrentPart].SelfAxis2; Joints[CurrentPart].SetPhysics(PHYS_Karma); } if (ClassIsChildOf(JointParts[CurrentPart].PartClass,class'KTire') && Joints[CurrentPart].IsA('KCarWheelJoint')) { (KTire(Parts[CurrentPart])).WheelJoint = KCarWheelJoint(Joints[CurrentPart]); (KTire(Parts[CurrentPart])).WheelJoint.KUpdateConstraintParams(); if (Joints[CurrentPart].IsA('KSCarWheelJoint')) { KSCarWheelJoint(Joints[CurrentPart]).KForceThreshold = SafeForce; KSCarWheelJoint(Joints[CurrentPart]).StallTime = ProtectTime; } } else if (ClassIsChildOf(JointParts[CurrentPart].PartClass,class'USARBot.KDPart')) (KDPart(Parts[CurrentPart])).setJoint(Joints[CurrentPart]); if(Role != ROLE_Authority) KarmaParams(Parts[CurrentPart].KParams).bDestroyOnSimError = False; } if (bDebug) { //DumpPackages(); DumpJoints(); } // Initially make sure parameters are sync'ed with Karma KVehicleUpdateParams(); // For KImpact event KSetImpactThreshold(HitSoundThreshold); // If this is not 'authority' version - don't destroy it if there is a problem. // The network should sort things out. if(Role != ROLE_Authority) KarmaParams(KParams).bDestroyOnSimError = False; // init the array size JointsControl.length = JointParts.length; ///////////////////////////////// // Mount Items ///////////////////////////////// // Mount headlight if (HeadLight.ItemName!="") { Parent = FindPart(HeadLight.Parent); if (Parent!=None) { GetAxes(Parent.Rotation,RotX,RotY,RotZ); myHeadLight = USARHeadlight(spawn(HeadLight.ItemClass, Parent,, Parent.Location + HeadLight.Position.X * RotX + HeadLight.Position.Y * RotY + HeadLight.Position.Z * RotZ, )); myHeadlight.SetBase(Parent); myHeadlight.SetRelativeRotation(HeadLight.uuDirection); } } // Mount cameras for (i=0;i<Cameras.length;i++) { Parent = FindPart(Cameras[i].Parent); if (Parent==None) continue; GetAxes(Parent.Rotation,RotX,RotY,RotZ); CamList[i] = RobotCamera(spawn(Cameras[i].ItemClass, Parent,, Parent.Location + Cameras[i].Position.X * RotX + Cameras[i].Position.Y * RotY + Cameras[i].Position.Z * RotZ, )); CamList[i].init(Cameras[i].ItemName,Parent,Cameras[i].Position,Cameras[i].uuDirection,self,Cameras[i].Parent); } if (CamList.length>0) { myCamera = CamList[0]; CameraZoom = CamList[0].CameraFov; } // Mount sensors for (i=0;i<Sensors.length;i++) { Parent = FindPart(Sensors[i].Parent); if (Parent==None) continue; GetAxes(Parent.Rotation,RotX,RotY,RotZ); SensorList[i] = Sensor(spawn(Sensors[i].ItemClass, Parent,, Parent.Location + Sensors[i].Position.X * RotX + Sensors[i].Position.Y * RotY + Sensors[i].Position.Z * RotZ, )); SensorList[i].init(Sensors[i].ItemName,Parent,Sensors[i].Position,Sensors[i].uuDirection,self,Sensors[i].Parent); ProcessedSensors[i]=0; } // Mount Effecters for (i=0;i<Effecters.length;i++) { Parent = FindPart(Effecters[i].Parent); if (Parent==None) continue; GetAxes(Parent.Rotation,RotX,RotY,RotZ); EffecterList[i] = Effecter(spawn(Effecters[i].ItemClass, Parent,, Parent.Location + Effecters[i].Position.X * RotX + Effecters[i].Position.Y * RotY + Effecters[i].Position.Z * RotZ, )); EffecterList[i].init(Effecters[i].ItemName,Parent,Effecters[i].Position,Effecters[i].uuDirection,self,Effecters[i].Parent); } Register(); SetTimer(msgTimer,true); startTime = Level.TimeSeconds; lastTime = Level.TimeSeconds; lastLocation = Location; //If there's an FPSLogger triggers it fpsLogger = 'FPSLog'; TriggerEvent(fpsLogger, self, None); } simulated function SetSkin(string skinName) { local int i; local texture skinTexture; for(i = 0; i < RobotSkins.Length; i++) if(skinName ~= RobotSkins[i].Name) { skinTexture = RobotSkins[i].Skin; break; } if((i > 0) && (i == RobotSkins.Length)) skinTexture = RobotSkins[0].Skin; //i>0 assure [0] element existence if(skinTexture != none) { Skins[0] = skinTexture; for (i = 0; i < Parts.Length; i++) { Parts[i].Skins[0] = skinTexture; } } if(Role == ROLE_Authority) { RS_skinName = skinName; RS_skinUpdateId++; } } // dump joints function DumpJoints() { local int i; for (i=0;i<Joints.length;i++) log(i@"Name"@JointParts[i].PartName@"Part"@Parts[i]@"Joint"@Joints[i]); } simulated event Destroyed() { local int i; // Destory mounted items for (i=0;i<SensorList.length;i++) SensorList[i].Destroy(); for (i=0;i<EffecterList.length;i++) EffecterList[i].Destroy(); for (i=0;i<CamList.length;i++) CamList[i].Destroy(); if (myHeadlight!=None) myHeadlight.Destroy(); // Destory physical robot for (i=0;i<Parts.length;i++) { if (Parts[i]!=none) { Joints[i].Destroy(); Parts[i].Destroy(); } } Unregister(); converter = None; UntriggerEvent(fpsLogger, self, None); KSetSimParams(oldKSP); if (CollLog!=None) CollLog.CloseLog(); if (PosLog!=None) PosLog.CloseLog(); Super.Destroyed(); } // For drawing noise signal simulated function DrawHud(Canvas C) { if (myLife==batteryLife) { C.Reset(); C.Style = ERenderStyle.STY_Particle; C.SetPos(0,0); C.DrawTile(Material'XGameShaders.ScreenNoisePan', C.SizeX, C.SizeY, 0.0, 0.0, 128, 128); C.FontScaleX=4; C.FontScaleY=4; C.DrawColor.R = 255; C.DrawColor.G = 0; C.DrawColor.B = 0; C.DrawColor.A = 255; C.SetPos(C.SizeX/2-80, C.SizeY/2); C.DrawText("NO POWER!"); } } // Call this if you change any parameters (tire, suspension etc.) and they // will be passed down to each wheel/joint. simulated event KVehicleUpdateParams() { local KTire Part; local KCarWheelJoint WheelJ; local KDHinge HingeJ; local int i; local MisPkgLinkInfo aMisPkgLink; Super.KVehicleUpdateParams(); for (i=0;i<Parts.length;i++) { if (Joints[i].IsA('KCarWheelJoint')) { WheelJ=KCarWheelJoint(Joints[i]); WheelJ.bKSteeringLocked = JointParts[i].bSteeringLocked; WheelJ.KProportionalGap = SteerPropGap; WheelJ.KMaxSteerTorque = SteerTorque; WheelJ.KMaxSteerSpeed = SteerSpeed; WheelJ.KBraking = JointParts[i].BrakeTorque; if (JointParts[i].bSuspensionLocked) { WheelJ.KSuspHighLimit = 0.001; WheelJ.KSuspLowLimit = -0.001; WheelJ.KSuspStiffness = 200.0; WheelJ.KSuspDamping = 100.0; } else { WheelJ.KSuspHighLimit = SuspHighLimit; WheelJ.KSuspLowLimit = SuspLowLimit; WheelJ.KSuspStiffness = SuspStiffness; WheelJ.KSuspDamping = SuspDamping; } // Sync params with Karma. WheelJ.KUpdateConstraintParams(); } else if(Joints[i].IsA('KDHinge')) { HingeJ = KDHinge(Joints[i]); aMisPkgLink = getMisPkgLinkInfo(getLinkNumber(string(JointParts[i].PartName)), getMisPkgName(string(JointParts[i].PartName))); if(aMisPkgLink != None) { HingeJ.KMaxTorque = aMisPkgLink.MaxTorque; HingeJ.KDesiredAngVel = converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); } else { HingeJ.KMaxTorque = MotorTorque; HingeJ.KDesiredAngVel = uuMotorSpeed; } HingeJ.KProportionalGap = HingePropGap; HingeJ.KHingeType = HT_CONTROLLED; // Sync params with Karma. if (Joints[i].IsA('KSlider')) KSlider(Joints[i]).UpdateConstraint(); else HingeJ.KUpdateConstraintParams(); } if (Parts[i].IsA('KTire')) { Part=KTire(Parts[i]); Part.RollFriction = TireRollFriction; Part.LateralFriction = TireLateralFriction; Part.RollSlip = TireRollSlip; Part.LateralSlip = TireLateralSlip; Part.MinSlip = TireMinSlip; Part.SlipRate = TireSlipRate; Part.Softness = TireSoftness; Part.Adhesion = TireAdhesion; Part.Restitution = TireRestitution; } } KSetMass(ChassisMass); } // Possibly apply force to flip robot over. simulated event KApplyForce(out vector Force, out vector Torque) { local float torqueScale; local vector worldForward, worldUp, worldRight, torqueAxis; if(FlipTimeLeft == 0) return; worldForward = vect(-1, 0, 0) >> Rotation; worldUp = vect(0, 0, 1) >> Rotation; worldRight = vect(0, 1, 0) >> Rotation; torqueAxis = Normal(worldUp Cross vect(0, 0, 1)); // Torque scaled by how far over we are. // This will be between 0 and PI - so convert to between 0 and 1. torqueScale = Acos(worldUp Dot vect(0, 0, 1))/3.1416; Torque = FlipTorque * torqueScale * torqueAxis; } function StartFlip(Pawn Pusher) { //local vector toPusher, worldUp; // if we are already flipping the car - dont do it again! if(FlipTimeLeft > 0) return; FlipTimeLeft = FlipTime; // Start the flip on the server USARRemoteBot(Controller).Flip = false; } //given a name and return the correspond jointpart's id function int FindJointPartId(string jname) { local int i; for (i=0;i<JointParts.length;i++) if (string(JointParts[i].PartName) == jname) return i; return -1; } // Get all the children IDs of a part function array<int> FindChildren(int idx) { local array<int> res; local int i; local name myName,pName; //invalid idx is treated as the robot platform (hard mount). if (idx<0 || idx>=JointParts.length) myName='None'; //iterate JointParts to find all the children myName = JointParts[idx].PartName; for (i=0;i<JointParts.length;i++) { pName = JointParts[i].Parent; if (pName=='') pName='None'; if (i!=idx && pName==myName) { res.Insert(res.length,1); res[res.length-1] = i; } } return res; } // The relative location of the joint (mount) respect to the parent part function vector rLocJointParent(int idx) { local vector res, forward, right, upward, dif; local Actor parent; //check idx if (idx<0 || idx>=JointParts.length) { log("Invaild JointPart index in function rLocJointParent!"); return vect(0,0,0); } //find the parent's orientation parent = FindPart(JointParts[idx].Parent); if (parent==None) { log("Can't find the parent in function rLocJointParent!"); return vect(0,0,0); } if (parent.Rotation==rot(0,0,0)) { forward = vect(1,0,0); right = vect(0,1,0); upward = vect(0,0,1); } else GetAxes(parent.Rotation,forward,right,upward); //project to the parent's coordinate dif = Joints[idx].Location - parent.Location; res.X = dif Dot forward; res.Y = dif Dot right; res.Z = dif Dot upward; return res; } // The relative orientation of the joint (mount) respect to the parent part // Ref: http://people.csail.mit.edu/bkph/articles/Kinematics_Vicarm_WP_69.pdf function rotator rRotJointParent(int idx) { local rotator res; local vector pForward, pRight, pUpward; local vector jForward, jRight, jUpward; local Actor parent, joint; local float m00,m01,m02,m10,m11,m12,m20,m21,m22; //check idx if (idx<0 || idx>=JointParts.length) { log("Invaild JointPart index in function rLocJointParent!"); return rot(0,0,0); } //find the parent's orientation parent = FindPart(JointParts[idx].Parent); if (parent==None) { log("Can't find the parent in function rLocJointParent!"); return rot(0,0,0); } if (parent.Rotation==rot(0,0,0)) { pForward = vect(1,0,0); pRight = vect(0,1,0); pUpward = vect(0,0,1); } else GetAxes(parent.Rotation,pForward,pRight,pUpward); //find the joint's orientation joint = Joints[idx]; if (joint.Rotation==rot(0,0,0)) { jForward = vect(1,0,0); jRight = vect(0,1,0); jUpward = vect(0,0,1); } else GetAxes(joint.Rotation,jForward,jRight,jUpward); //calculate the rotation matrix m00 = jForward Dot pForward; m10 = jForward Dot pRight; m20 = jForward Dot pUpward; m01 = jRight Dot pForward; m11 = jRight Dot pRight; m21 = jRight Dot pUpward; m02 = jUpward Dot pForward; m12 = jUpward Dot pRight; m22 = jUpward Dot pUpward; //calculate the pitch, yaw and roll angles in UU which indicate we getting //part coordinate by rotating joint coordinate roll->pitch->yaw. res.Pitch = Atan(-m20,Sqrt((m00*m00+m10*m10+m21*m21+m22*m22)/2))*10430.3783505; if (Abs(res.Pitch-16384)<10) { // Can't uniquely determine yaw and roll. Here we set roll=0. res.Roll = 0; res.Yaw = -Atan(m01-m20,m11+m02)*10430.3783505; } else if (Abs(res.Pitch+16384)<10) { // Can't uniquely determine yaw and roll. Here we set roll=0. res.Roll = 0; res.Yaw = Atan(-m01-m20,m11-m02)*10430.3783505; } else { res.Yaw = Atan(m10,m00)*10430.3783505; res.Roll = Atan(m21,m22)*10430.3783505; } res.Yaw=-res.Yaw; return res; } // The relative location of the part respect to the joint (mount) function vector rLocPartJoint(int idx) { local vector res, forward, right, upward, dif; local Actor joint; //check idx if (idx<0 || idx>=JointParts.length) { log("Invaild JointPart index in function rLocJointParent!"); return vect(0,0,0); } //find the joint's orientation joint = Joints[idx]; if (joint.Rotation==rot(0,0,0)) { forward = vect(1,0,0); right = vect(0,1,0); upward = vect(0,0,1); } else GetAxes(joint.Rotation,forward,right,upward); //project to the joint's coordinate dif = Parts[idx].Location - joint.Location; res.X = dif Dot forward; res.Y = dif Dot right; res.Z = dif Dot upward; return res; } // The relative orientation of the part respect to the joint (mount) function rotator rRotPartJoint(int idx) { local rotator res; local vector pForward, pRight, pUpward; local vector jForward, jRight, jUpward; local Actor part, joint; local float m00,m01,m02,m10,m11,m12,m20,m21,m22; //check idx if (idx<0 || idx>=JointParts.length) { log("Invaild JointPart index in function rLocJointParent!"); return rot(0,0,0); } //find the part's orientation part = Parts[idx]; if (part.Rotation==rot(0,0,0)) { pForward = vect(1,0,0); pRight = vect(0,1,0); pUpward = vect(0,0,1); } else GetAxes(part.Rotation,pForward,pRight,pUpward); //find the joint's orientation which should be parent's orientation joint = Parents[idx]; if (joint==None || joint.Rotation==rot(0,0,0)) { jForward = vect(1,0,0); jRight = vect(0,1,0); jUpward = vect(0,0,1); } else GetAxes(joint.Rotation,jForward,jRight,jUpward); //calculate the rotation matrix m00 = jForward Dot pForward; m10 = jForward Dot pRight; m20 = jForward Dot pUpward; m01 = jRight Dot pForward; m11 = jRight Dot pRight; m21 = jRight Dot pUpward; m02 = jUpward Dot pForward; m12 = jUpward Dot pRight; m22 = jUpward Dot pUpward; //calculate the pitch, yaw and roll angles in UU which indicate we getting //part coordinate by rotating joint coordinate roll->pitch->yaw. res.Pitch = Atan(-m20,Sqrt((m00*m00+m10*m10+m21*m21+m22*m22)/2))*10430.3783505; if (Abs(res.Pitch-16384)<10) { // Can't uniquely determine yaw and roll. Here we set roll=0. res.Roll = 0; res.Yaw = -Atan(m01-m20,m11+m02)*10430.3783505; } else if (Abs(res.Pitch+16384)<10) { // Can't uniquely determine yaw and roll. Here we set roll=0. res.Roll = 0; res.Yaw = Atan(-m01-m20,m11-m02)*10430.3783505; } else { res.Yaw = Atan(m10,m00)*10430.3783505; res.Roll = Atan(m21,m22)*10430.3783505; } /* Debug:: log(JointParts[idx].PartName@pForward@pRight@pUpward@jForward@jRight@jUpward); log(m00@m01@m02); log(m10@m11@m12); log(m20@m21@m22); log(res); */ res.Yaw=-res.Yaw; return res; } simulated function int getJointAngle(KCarWheelJoint WheelJ) { local Quat curQ, relQ; local Vector axis11, axis12, axis21, axis22, newAxis11; local float difCos, difSign; local int curAng; curQ = WheelJ.KConstraintActor1.KGetRBQuaternion(); axis11 = QuatRotateVector(curQ,WheelJ.KPriAxis1); axis12 = QuatRotateVector(curQ,WheelJ.KSecAxis1); curQ = WheelJ.KConstraintActor2.KGetRBQuaternion(); axis21 = QuatRotateVector(curQ,WheelJ.KPriAxis2); axis22 = QuatRotateVector(curQ,WheelJ.KSecAxis2); relQ = QuatFindBetween(axis12,axis22); newAxis11 = QuatRotateVector(relQ,axis11); difCos = newAxis11 Dot axis21; if (difCos>1.0) difCos = 1.0; if (difCos<-1.0) difCos = -1.0; difSign = (newAxis11 Cross axis21) Dot axis22; if (difSign<0) difSign=-1.0; else difSign=1.0; curAng = difSign * ACos(difCos)*32768/PI; return curAng; } // Get the relative position between a part and its parent function vector getRelativePosition(vector ChildPosition, vector ParentPosition, rotator ParentOrientation) { local vector res, Forward, Right, Upward, Dif; // Find the parent's orientation if (ParentOrientation == Rot(0,0,0)) { Forward = vect(1,0,0); Right = vect(0,1,0); Upward = vect(0,0,-1); } else { Forward = (Vect(1,0,0) >> ParentOrientation); Right = (Vect(0,1,0) >> ParentOrientation); Upward = (Vect(0,0,-1) >> ParentOrientation); } // Project to the parent's coordinate dif = ChildPosition - ParentPosition; res.X = Dif Dot Forward; res.Y = Dif Dot Right; res.Z = Dif Dot Upward; return res; } // Get relative orientation between two rotators function rotator getRelativeOrientation(rotator firstRotator, rotator secondRotator) { local vector result; local vector firstForward, firstRight, firstUpward; local vector secondForward, secondRight, secondUpward; local float r00,r01,r02,r10,r11,r12,r20,r21,r22; // Find the second part's orientation in terms of vectors if (secondRotator == Rot(0,0,0)) { secondForward = vect(1,0,0); secondRight = vect(0,1,0); secondUpward = vect(0,0,-1); } else { secondForward = (Vect(1,0,0) >> secondRotator); secondRight = (Vect(0,1,0) >> secondRotator); secondUpward = (Vect(0,0,-1) >> secondRotator); } // Find the first part's orientation in terms of vectors if (firstRotator == Rot(0,0,0)) { firstForward = vect(1,0,0); firstRight = vect(0,1,0); firstUpward = vect(0,0,-1); } else { firstForward = (Vect(1,0,0) >> firstRotator); firstRight = (Vect(0,1,0) >> firstRotator); firstUpward = (Vect(0,0,-1) >> firstRotator); } // Calculate the Rotation Matrix r00 = secondForward Dot firstForward; r01 = secondForward Dot firstRight; r02 = secondForward Dot firstUpward; r10 = secondRight Dot firstForward; r11 = secondRight Dot firstRight; r12 = secondRight Dot firstUpward; r20 = secondUpward Dot firstForward; r21 = secondUpward Dot firstRight; r22 = secondUpward Dot firstUpward; // Calculate the X,Y,Z rotation angles, in radians result.Y = ASin(r02); if(result.Y < 1.5707963267948966192313216916398) { if(result.Y > -1.5707963267948966192313216916398) { result.X = ATan(-r12,r22); result.Z = ATan(-r01,r00); } else { // Not a unique solution result.X = -ATan(r10,r11); result.Z = 0; } } else { // Not a unique solution result.X = ATan(r10,r11); result.Z = 0; } result.X = -result.X; result.Y = -result.Y; result.Z = -result.Z; return Converter.RotatorToUU(result); } function ProcessCarInput() { local int i, j, selfJointIndex, parentJointIndex, LinkCount, ParentLink; local int JIdx, JScount, JVcount, JOcount; local string type, name, outstring, tmpstring; local vector tmpvect; local rotator tmprot; local MisPkgLinkInfo selfMisPkgLink, parentMisPkgLink; local MisPkgInfo aMisPkg; bNewCommand = false; // Set sensor/Effecters/cameras JIdx=-1; type = USARRemoteBot(Controller).SetType; name = USARRemoteBot(Controller).SetName; if (type!="" && Caps(type)!="JOINT") { outstring = "RES {Time "$Level.TimeSeconds$"} {Type "$type$"} {Name "$USARRemoteBot(Controller).SetName$"}"; for (i=0;i<EffecterList.length;i++) { if (EffecterList[i].isType(type) && EffecterList[i].isName(name)) { tmpstring = "{Status "$EffecterList[i].Set(USARRemoteBot(Controller).Opcode,USARRemoteBot(Controller).Params)$"}"; JIdx=i; break; } } if (i<EffecterList.length) USARRemoteBot(Controller).myConnection.SendLine(outstring@tmpstring); for (i=0;i<CamList.length;i++) { if (CamList[i].isType(type) && CamList[i].isName(name)) { tmpstring = "{Status "$CamList[i].Set(USARRemoteBot(Controller).Opcode,USARRemoteBot(Controller).Params)$"}"; if (i==0) USARRemoteBot(Controller).myCameraZoom = CamList[0].getFov(); JIdx=i; break; } } if (i<CamList.length) USARRemoteBot(Controller).myConnection.SendLine(outstring@tmpstring); for (i=0;i<SensorList.length;i++) { if (SensorList[i].isType(type) && SensorList[i].isName(name)) { tmpstring = "{Status "$SensorList[i].Set(USARRemoteBot(Controller).Opcode,USARRemoteBot(Controller).Params)$"}"; JIdx=i; break; } } if (i<SensorList.length) USARRemoteBot(Controller).myConnection.SendLine(outstring@tmpstring); if (JIdx==-1) USARRemoteBot(Controller).myConnection.SendLine(outstring@"{Status Failed}"); } // Return geo info JIdx=-1; type = USARRemoteBot(Controller).GeoType; name = USARRemoteBot(Controller).GeoName; if (type!="") { // Sensor GEO Message outstring=""; for (i=0;i<Sensors.length;i++) { if (SensorList[i].isType(type) && (name=="" || SensorList[i].isName(name))) { outstring = outstring@SensorList[i].GetGeoData(); JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine(SensorList[JIdx].GetGeoHead()$outstring); // Effecter GEO Message outstring=""; for (i=0;i<Effecters.length;i++) { if (EffecterList[i].isType(type) && (name=="" || EffecterList[i].isName(name))) { outstring = outstring@EffecterList[i].GetGeoData(); JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine(EffecterList[JIdx].GetGeoHead()$outstring); // Camera GEO Message outstring=""; for (i=0;i<Cameras.length;i++) { if (CamList[i].isType(type) && (name=="" || CamList[i].isName(name))) { outstring = outstring@CamList[i].GetGeoData(); JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine(CamList[JIdx].GetGeoHead()$outstring); // Mission Package GEO Message outstring=""; for (i=0;i<MisPkgs.length;i++) { if ((Caps(type) == "MISPKG") && ((name == "") || (Caps(name) == Caps(string(MisPkgs[i].PkgName))))) { outstring = outstring @ "{Name " $ MisPkgs[i].PkgName $ "}"; aMisPkg = New MisPkgs[i].PkgClass; LinkCount = 0; for(j=0; j<aMisPkg.Links.Length; j++) { selfMisPkgLink = New aMisPkg.Links[j].LinkClass; if(aMisPkg.Links[j].LinkNumber > 0) { selfJointIndex = FindMisPkgLinkIndex(getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].LinkNumber)); parentJointIndex = FindMisPkgLinkIndex(getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].ParentLinkNumber)); if(LinkCount == 0) { ParentLink = -1; // Since this is the first link, it is attached to the vehicle (note: the vehicle is defined with a "Link Number" of -1) tmpvect = getRelativePosition(Joints[selfJointIndex].Location, Location, Rotation); tmpvect = tmpvect / Converter.default.C_MeterToUU; tmprot = getRelativeOrientation(Rot(0,0,0), Converter.RotatorToUU(selfMisPkgLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))); } else { parentMisPkgLink = New aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].LinkClass; ParentLink = aMisPkg.Links[j].ParentLinkNumber; tmpvect = getRelativePosition(Joints[selfJointIndex].Location, Joints[parentJointIndex].Location, Converter.RotatorToUU(parentMisPkgLink.getMountPointOrientation(aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].SelfMount))); tmpvect = tmpvect / Converter.default.C_MeterToUU; tmprot = getRelativeOrientation(Converter.RotatorToUU(parentMisPkgLink.getMountPointOrientation(aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].SelfMount)), Converter.RotatorToUU(selfMisPkgLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))); } outstring = outstring @ selfMisPkgLink.GetGeoData(getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].LinkNumber), Converter.VectorString(tmpvect, 4), Converter.Str_RotatorFromUU(tmprot, 4), aMisPkg.Links[j].LinkNumber, ParentLink); LinkCount++; } } JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine("GEO {Type MisPkg}"$outstring); if (JIdx==-1) { if(type != "Robot") { if (name!="") USARRemoteBot(Controller).myConnection.SendLine("GEO {Type "$type$"} {Name "$name$"}"); else USARRemoteBot(Controller).myConnection.SendLine("GEO {Type "$type$"}"); } } } // Return CONF Information JIdx = -1; type = USARRemoteBot(Controller).ConfType; name = USARRemoteBot(Controller).ConfName; if (type!="") { // Sensor CONF Message outstring=""; for (i=0;i<Sensors.length;i++) { if (SensorList[i].isType(type) && (name=="" || SensorList[i].isName(name))) { outstring = outstring@SensorList[i].GetConfData(); JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine(SensorList[JIdx].GetConfHead()$outstring); // Camera CONF Message outstring=""; for (i=0;i<Cameras.length;i++) { if (CamList[i].isType(type) && (name=="" || CamList[i].isName(name))) { outstring = outstring@CamList[i].GetConfData(); JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine(CamList[JIdx].GetConfHead()$outstring); // Effecter CONF Message outstring=""; for (i=0;i<Effecters.length;i++) { if (EffecterList[i].isType(type) && (name=="" || EffecterList[i].isName(name))) { outstring = outstring@EffecterList[i].GetConfData(); JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine(EffecterList[JIdx].GetConfHead()$outstring); // Mission Package CONF Message outstring=""; for (i=0;i<MisPkgs.length;i++) { if ((Caps(type) == "MISPKG") && ((name == "") || (Caps(name) == Caps(string(MisPkgs[i].PkgName))))) { outstring = outstring @ "{Name " $ MisPkgs[i].PkgName $ "}"; aMisPkg = New MisPkgs[i].PkgClass; for(j=0; j<aMisPkg.Links.Length; j++) { if(aMisPkg.Links[j].LinkNumber > 0) { selfMisPkgLink = New aMisPkg.Links[j].LinkClass; outstring = outstring @ selfMisPkgLink.GetConfData(getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].LinkNumber), aMisPkg.Links[j].SelfMount, aMisPkg.Links[j].LinkNumber); } } JIdx = i; } } if (outstring!="") USARRemoteBot(Controller).myConnection.SendLine("CONF {Type MisPkg}"$outstring); if (JIdx==-1) { if(type != "Robot") { if (name!="") USARRemoteBot(Controller).myConnection.SendLine("CONF {Type "$type$"} {Name "$name$"}"); else USARRemoteBot(Controller).myConnection.SendLine("CONF {Type "$type$"}"); } } } // No command if (USARRemoteBot(Controller).JointControlIdx==0 && Caps(USARRemoteBot(Controller).SetType)!="JOINT") return; else bNewCommand = True; JScount = USARRemoteBot(Controller).JSteer.Length; JOcount = USARRemoteBot(Controller).JOrder.Length; JVcount = USARRemoteBot(Controller).JValue.Length; // Low level DRIVE commands for (i=0;i<USARRemoteBot(Controller).JointControlIdx;i++) { JIdx = FindJointPartId(USARRemoteBot(Controller).JName[i]); //Always valid access if (JIdx>=0) { JointsControl[JIdx].state = 1; // new command //We are accessing dynamic arrays so we must check their length if(i < JScount) JointsControl[JIdx].steer = USARRemoteBot(Controller).JSteer[i]; else JointsControl[JIdx].steer = 0; if(i < JOcount) JointsControl[JIdx].order = USARRemoteBot(Controller).JOrder[i]; else JointsControl[JIdx].order = 0; if(i < JVcount) JointsControl[JIdx].value = USARRemoteBot(Controller).JValue[i]; else JointsControl[JIdx].value = 0; if (JointsControl[JIdx].order==2 && JointsControl[JIdx].value>MaxTorque) JointsControl[JIdx].value = MaxTorque; } if (bDebug) log("Input <<"@USARRemoteBot(Controller).JointControlIdx @USARRemoteBot(Controller).JName[i] @USARRemoteBot(Controller).JSteer[i] @USARRemoteBot(Controller).JOrder[i] @USARRemoteBot(Controller).JValue[i] @JIdx@">>"); } if (Caps(USARRemoteBot(Controller).SetType)=="JOINT") { JIdx = FindJointPartId(USARRemoteBot(Controller).SetName); if (JIdx>=0) { JointsControl[JIdx].state = 1; if (USARRemoteBot(Controller).Opcode=="0" || caps(USARRemoteBot(Controller).Opcode)=="ANGLE") JointsControl[JIdx].order = 0; else if (USARRemoteBot(Controller).Opcode=="1" || caps(USARRemoteBot(Controller).Opcode)=="VELOCITY") JointsControl[JIdx].order = 1; else if (USARRemoteBot(Controller).Opcode=="2" || caps(USARRemoteBot(Controller).Opcode)=="TORQUE") JointsControl[JIdx].order = 2; else if (USARRemoteBot(Controller).Opcode=="10" || caps(USARRemoteBot(Controller).Opcode)=="RELANGLE") JointsControl[JIdx].order = 10; else if (USARRemoteBot(Controller).Opcode=="11" || caps(USARRemoteBot(Controller).Opcode)=="RELVELOCITY") JointsControl[JIdx].order = 11; else if (USARRemoteBot(Controller).Opcode=="12" || caps(USARRemoteBot(Controller).Opcode)=="RELTORQUE") JointsControl[JIdx].order = 12; i = InStr(USARRemoteBot(Controller).Params,","); if( i == -1 ) { JointsControl[JIdx].steer = 0; if (JointsControl[JIdx].order<2) JointsControl[JIdx].value = converter.AngleToUU(float(USARRemoteBot(Controller).Params)); else JointsControl[JIdx].value = float(USARRemoteBot(Controller).Params); } else { JointsControl[JIdx].steer = converter.AngleToUU(float(mid(USARRemoteBot(Controller).Params,i+1))); if (JointsControl[JIdx].order<2) JointsControl[JIdx].value = converter.AngleToUU(float(left(USARRemoteBot(Controller).Params,i))); else JointsControl[JIdx].value = float(left(USARRemoteBot(Controller).Params,i)); } if (JointsControl[JIdx].order==2 && JointsControl[JIdx].value>MaxTorque) JointsControl[JIdx].value = MaxTorque; } } } function ResetCarInput() { USARRemoteBot(Controller).SetType=""; USARRemoteBot(Controller).GeoType=""; USARRemoteBot(Controller).ConfType=""; USARRemoteBot(Controller).MPName=""; USARRemoteBot(Controller).JointControlIdx=0; } simulated event SetInitialState() { Super.SetInitialState(); Enable('Tick'); } // // I assume newPos was defined as "var vector newPos;" // function MoveRobot(vector newPos) { local vector diff, tmpVec; local int i; local KTire Tire; local KDPart Part; KGetRigidBodyState(TeleportLocation); diff = newPos - Location; TeleportLocation.Position = KRBVecFromVector(newPos); TeleportLocation.AngVel = KRBVecFromVector(vect(0,0,0)); TeleportLocation.LinVel = KRBVecFromVector(vect(0,0,0)); bNewRobotState = true; for (i=0; i<Parts.length; i++) { if (Parts[i].IsA('KTire')) { Tire = KTire(Parts[i]); Tire.KGetRigidBodyState(Tire.ReceiveState); tmpVec = Tire.Location + diff; Tire.ReceiveState.Position = KRBVecFromVector(tmpVec); Tire.ReceiveState.LinVel = KRBVecFromVector(vect(0,0,0)); Tire.ReceiveState.AngVel = KRBVecFromVector(vect(0,0,0)); Tire.bReceiveStateNew = true; } else if (Parts[i].IsA('KDPart')) { Part = KDPart(Parts[i]); Part.KGetRigidBodyState(Part.ReceiveState); tmpVec = Part.Location + diff; Part.ReceiveState.Position = KRBVecFromVector(tmpVec); Part.ReceiveState.LinVel = KRBVecFromVector(vect(0,0,0)); Part.ReceiveState.AngVel = KRBVecFromVector(vect(0,0,0)); Part.bReceiveStateNew = true; } } } simulated function Tick(float Delta) { local int i; local float spinAng, difAng, slowAng; local KCarWheelJoint WheelJ; local KDHinge HingeJ; local Tracing T; local vector loc; local float time; local MisPkgLinkInfo aMisPkgLink; Super.Tick(Delta); time = Level.TimeSeconds; loc = Location; //If we are flipping than wake up Karma if( FlipTimeLeft > 0 ) KWake(); // SERVER Only processing. if(Role == ROLE_Authority) { ProcessCarInput(); // Process input. ResetCarInput(); PackState(); // Pack updated car info into replication structure. // Create a trace, if needed. // (spawn will be replicated on the clients by the engine) if((USARRemoteBot(Controller).LeaveTrace) && (VSize(loc-previousLocation) > 7) && ((time - previousTime) >= USARRemoteBot(Controller).TraceInterval)) { previousTime = time; T = spawn(class'USARBot.Tracing'); T.Texture = USARRemoteBot(Controller).TraceTexture; previousLocation = T.Location; } } // Battery: If battery low then set torque to 0 (this will brake every joint, see later...) if (myLife>=batteryLife) { myLife=batteryLife; for (i=0;i<JointsControl.length;i++) { JointsControl[i].order=2; JointsControl[i].value=0; } } else myLife = Level.TimeSeconds - startTime; //Check every joint for new commands or for still executing ones. //Every command requires only one tick for execution at exception of //KDCarWheelJoint order = 0 that requires many ticks. for (i=0;i<JointsControl.length;i++) { if (JointsControl[i].state==0) continue; if (Joints[i].IsA('KCarWheelJoint')) { WheelJ = KCarWheelJoint(Joints[i]); //log(">>"@i@JointsControl[i].state@JointsControl[i].order@JointsControl[i].value@JointsControl[i].steer); //log(" "@WheelJ.KMotorTorque@WheelJ.KMaxSpeed@WheelJ.KBraking); // Drive /////////// // Brake if (JointsControl[i].order==3) { WheelJ.KBraking = JointsControl[i].value; WheelJ.KMotorTorque = 0.0; } // Torque else if (JointsControl[i].order==2) { WheelJ.KMotorTorque = JointsControl[i].value; WheelJ.KMaxSpeed = 1310700; if (JointsControl[i].value!=0) WheelJ.KBraking = 0.0; else WheelJ.KBraking = JointParts[i].BrakeTorque + 0.5; } // Speed else if (JointsControl[i].order==1) { WheelJ.KMaxSpeed = JointsControl[i].value; if (JointsControl[i].value!=0) { WheelJ.KBraking = 0.0; WheelJ.KMotorTorque = MotorTorque; } else { WheelJ.KBraking = JointParts[i].BrakeTorque + 0.5; WheelJ.KMotorTorque = 0.0; } } // Angle else if (JointsControl[i].order==0) { JointsControl[i].order=10; JointsControl[i].value=JointsControl[i].value-getJointAngle(WheelJ); } if (JointsControl[i].order==10 && JointsControl[i].value!=0.0) { spinAng = getJointAngle(WheelJ); slowAng = Delta*uuMotorSpeed*1.5; if (JointsControl[i].state == 1) { JointsControl[i].startAng = spinAng; JointsControl[i].angle = 0.0; difAng = 0.0; WheelJ.KBraking = 0.0; WheelJ.KMotorTorque = MotorTorque; if (JointsControl[i].value>0) { if (JointsControl[i].value<=slowAng) WheelJ.KMaxSpeed = 500; else WheelJ.KMaxSpeed = uuMotorSpeed; } else { if (JointsControl[i].value>=-slowAng) WheelJ.KMaxSpeed = -500; else WheelJ.KMaxSpeed = -uuMotorSpeed; } JointsControl[i].state = 254; // -2 } else { difAng = spinAng - JointsControl[i].startAng; if (difAng>32768) difAng -= 65535; else if (difAng<-32768) difAng += 65535; JointsControl[i].angle += difAng; JointsControl[i].startAng = spinAng; if (JointsControl[i].value>0 && JointsControl[i].angle>=JointsControl[i].value-slowAng) if ((JointsControl[i].value-JointsControl[i].angle)<3000*Delta) WheelJ.KMaxSpeed = 500; else WheelJ.KMaxSpeed = 1500; if (JointsControl[i].value<0 && JointsControl[i].angle<=JointsControl[i].value+slowAng) if ((JointsControl[i].value-JointsControl[i].angle)>-3000*Delta) WheelJ.KMaxSpeed = -500; else WheelJ.KMaxSpeed = -1500; if ( (JointsControl[i].value>0 && JointsControl[i].angle>=JointsControl[i].value) || (JointsControl[i].value<0 && JointsControl[i].angle<=JointsControl[i].value) ) { WheelJ.KMotorTorque = 0.0; WheelJ.KBraking = 1.0; WheelJ.KMaxSpeed = 0.0; JointsControl[i].value = 0.0; JointsControl[i].state = 0; } } //log("<<"@i@JointsControl[i].state@JointsControl[i].order@JointsControl[i].value); //log(" "@KCarWheelJoint(Joints[i]).KMotorTorque@KCarWheelJoint(Joints[i]).KMaxSpeed@KCarWheelJoint(Joints[i]).KBraking); //log("Order_0"@spinAng@JointsControl[i].startAng@"<-->"@difAng@JointsControl[i].angle@JointsControl[i].value@JointsControl[i].state@Parts[i].Rotation); if (bDebug) log("Order_0"@i@spinAng@JointsControl[i].startAng@"<-->"@difAng@JointsControl[i].angle@JointsControl[i].value@JointsControl[i].state); } // Steer if (JointsControl[i].steer!=65535) WheelJ.KSteerAngle = JointsControl[i].steer; if (JointsControl[i].order%10>0) JointsControl[i].state = 0; WheelJ.KUpdateConstraintParams(); if (bDebug) log("Tick <<"@i@WheelJ.KSteerAngle@WheelJ.KMotorTorque@WheelJ.KMaxSpeed@WheelJ.KBraking@">>"); } // End KCarWheelJoint else if(Joints[i].IsA('KDHinge')) { HingeJ = KDHinge(Joints[i]); aMisPkgLink = getMisPkgLinkInfo(getLinkNumber(string(JointParts[i].PartName)), getMisPkgName(string(JointParts[i].PartName))); HingeJ.KDesiredAngle = 0; // This is set to 0 to simplify the next relative/absolute ANGLE switch(). if(Joints[i].IsA('KSlider')) KSlider(Joints[i]).DesiredDistance = 0; switch(JointsControl[i].order) { case 10: // Drive: relative ANGLE if(Joints[i].IsA('KSlider')) KSlider(Joints[i]).DesiredDistance = KSlider(Joints[i]).getDistance(); else HingeJ.KDesiredAngle = HingeJ.KCurrentAngle; //This will transform the absolute angle in relative. case 0: // Drive: absolute ANGLE HingeJ.KHingeType = HT_Controlled; if(aMisPkgLink != None) // If the joint we are trying to rotate is part of a mission package { HingeJ.KMaxTorque = aMisPkgLink.MaxTorque; HingeJ.KDesiredAngVel = Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); if(Joints[i].IsA('KSlider')) { // by default, the value is transfered to angle in UU. Now we need to transfer it to length in UU. JointsControl[i].value = converter.LengthToUU(JointsControl[i].value*PI/32768); KSlider(Joints[i]).DesiredDistance += JointsControl[i].value; } else { //-- We make sure that the angle is valid if(aMisPkgLink.MinRange > aMisPkgLink.MaxRange) // If the minimum angle possible is bigger than the maximum angle possible, there is no constraint on the angle { HingeJ.KDesiredAngle -= JointsControl[i].value; } else // Otherwise, there might be a constraint on the angle, so we have to check for one { // If the desired angle is smaller than the minimum angle possible, we use the minimum angle possible if(JointsControl[i].value < Converter.AngleToUU(aMisPkgLink.MinRange)) HingeJ.KDesiredAngle -= Converter.AngleToUU(aMisPkgLink.MinRange); // If the desired angle is larger than the maximum angle possible, we use the maximum angle possible else if(JointsControl[i].value > Converter.AngleToUU(aMisPkgLink.MaxRange)) HingeJ.KDesiredAngle -= Converter.AngleToUU(aMisPkgLink.MaxRange); // Otherwise, we use the value received from the controller else HingeJ.KDesiredAngle -= JointsControl[i].value; } //-- } } else if(Joints[i].IsA('KSlider')) { // by default, the value is transfered to angle in UU. Now we need to transfer it to length in UU. JointsControl[i].value = converter.LengthToUU(JointsControl[i].value*PI/32768); KSlider(Joints[i]).DesiredDistance += JointsControl[i].value; HingeJ.KMaxTorque = MotorTorque; HingeJ.KDesiredAngVel = uuMotorSpeed; } else { HingeJ.KDesiredAngle -= JointsControl[i].value; HingeJ.KMaxTorque = MotorTorque; HingeJ.KDesiredAngVel = uuMotorSpeed; } HingeJ.Update(); break; case 1: // Drive: ANGLE SPEED if(aMisPkgLink != None) // If the joint we are trying to rotate is part of a mission package { if(aMisPkgLink.MinRange > aMisPkgLink.MaxRange) { HingeJ.KHingeType = HT_Motor; // Here, we make sure that the speed does go above (or below) the maximum (or minimum) speed if(JointsControl[i].value < -Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed)) HingeJ.KDesiredAngVel = Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); else if(JointsControl[i].value > Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed)) HingeJ.KDesiredAngVel = -Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); else HingeJ.KDesiredAngVel = -JointsControl[i].value; } else { // Since this link has an angle constraint, we have to control this joint (HT_Controlled) and limit its rotation HingeJ.KHingeType = HT_Controlled; // Here, we set the constraint, based on the mission package link's range if(JointsControl[i].value < 0) HingeJ.KDesiredAngle -= Converter.AngleToUU(aMisPkgLink.MinRange); else HingeJ.KDesiredAngle -= Converter.AngleToUU(aMisPkgLink.MaxRange); // Here, we make sure that the speed does go above (or below) the maximum (or minimum) speed if((JointsControl[i].value < -Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed)) || (JointsControl[i].value > Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed))) HingeJ.KDesiredAngVel = Converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); else HingeJ.KDesiredAngVel = Abs(JointsControl[i].value); } HingeJ.KMaxTorque = aMisPkgLink.MaxTorque; } else { HingeJ.KHingeType = HT_Motor; HingeJ.KMaxTorque = MotorTorque; HingeJ.KDesiredAngVel = -JointsControl[i].value; } HingeJ.Update(); break; case 2: // Drive: TORQUE if(aMisPkgLink != None) // If the joint we are trying to rotate is part of a mission package { if(aMisPkgLink.MinRange > aMisPkgLink.MaxRange) { HingeJ.KHingeType = HT_Motor; // Here, we make sure that the torque does go above (or below) the maximum (or minimum) torque if(JointsControl[i].value < -aMisPkgLink.MaxTorque) HingeJ.KMaxTorque = aMisPkgLink.MaxTorque; else if(JointsControl[i].value > aMisPkgLink.MaxTorque) HingeJ.KMaxTorque = -aMisPkgLink.MaxTorque; else HingeJ.KMaxTorque = -JointsControl[i].value; if(JointsControl[i].value > 0) HingeJ.KDesiredAngVel = converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); else if(JointsControl[i].value < 0) HingeJ.KDesiredAngVel = -converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); else HingeJ.KDesiredAngVel = 0; } else { // Since this link has an angle constraint, we have to control this joint (HT_Controlled) and limit its rotation HingeJ.KHingeType = HT_Controlled; // Here, we set the constraint, based on the mission package link's range if(JointsControl[i].value < 0) HingeJ.KDesiredAngle -= converter.AngleToUU(aMisPkgLink.MaxRange); else HingeJ.KDesiredAngle -= converter.AngleToUU(aMisPkgLink.MinRange); // Here, we make sure that the torque does go above (or below) the maximum (or minimum) torque if(JointsControl[i].value < -aMisPkgLink.MaxTorque) HingeJ.KMaxTorque = aMisPkgLink.MaxTorque; else if(JointsControl[i].value > aMisPkgLink.MaxTorque) HingeJ.KMaxTorque = -aMisPkgLink.MaxTorque; else HingeJ.KMaxTorque = -JointsControl[i].value; HingeJ.KDesiredAngVel = converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed); } } else { HingeJ.KHingeType = HT_Motor; HingeJ.KMaxTorque = -JointsControl[i].value; if(JointsControl[i].value > 0) HingeJ.KDesiredAngVel = 327680; //5 turns/sec else HingeJ.KDesiredAngVel = -327680; //5 turns/sec } HingeJ.Update(); break; } JointsControl[i].state = 0; } // End KDHinge } // End for // if there are new commands but Karma is on rest awake it if (bNewCommand && !KIsAwake()) KWake(); // other control commands from GameBot if (Role == ROLE_Authority) { bHeadlightOn=USARRemoteBot(Controller).Light; if (USARRemoteBot(Controller).Flip) StartFlip(None); if (USARRemoteBot(Controller).myCameraZoom>=0&&myCamera!=NONE) { CameraZoom = USARRemoteBot(Controller).myCameraZoom; if (CameraZoom==0) CameraZoom = myCamera.degCameraDefFov; // reset else if (CameraZoom<=myCamera.degCameraMinFov) CameraZoom = myCamera.degCameraMinFov; // low bound else if (CameraZoom>myCamera.degCameraMaxFov) CameraZoom = myCamera.degCameraMaxFov; // upper bound myCamera.setFov(CameraZoom); CamList[0].setFov(CameraZoom); USARRemoteBot(Controller).myCameraZoom = -1; } } // Projecting effect if(Level.NetMode != NM_DedicatedServer && myHeadlight!=None) { myHeadlight.DetachProjector(); if(bHeadlightOn) myHeadlight.AttachProjector(); } // Flipping if(FlipTimeLeft > 0) { FlipTimeLeft -= Delta; FlipTimeLeft = FMax(FlipTimeLeft, 0.0); // Make sure it doesn't go negative } // Logging of the position and pos // NOTE (marco.zaratti@gmail.com): // If you active these lines the AIBO replication will be very bad // in client-server simulation (at least on my PC). I don't know why, perhaps // it happens only on my PC. /* time_now = Level.TimeSeconds; if(time_now - old_time > logging_period) { //logging happens here // Time + Name + Position + Orientation time = Level.TimeSeconds; loc = Location; //fposlog(time@USARRemoteBot(Controller).RobotName@Converter.Str_LengthVectorFromUU(loc)@Converter.Str_RotatorFromUU(Rotation)); fposlog(time@USARRemoteBot(Controller).RobotName@Converter.LengthFromUU(loc.X)@Converter.LengthFromUU(loc.Y)@Converter.LengthFromUU(loc.Z)@Converter.AngleFromUU(Rotation.Roll)@Converter.AngleFromUU(Rotation.Pitch)@Converter.AngleFromUU(Rotation.Yaw)); old_time = time_now; } */ //Synchronizes MultiView camera coordinates SyncMultiView(); return; } simulated function SyncMultiView() { if(ViewManager != none) { ViewManager.UpdateView(ViewNum, myCamera.Location, myCamera.Rotation, CameraZoom); } } function timer() { local string outstring; local int i,j; //local vector loc,vel; local float time; time = Level.TimeSeconds; /* // Robot State Message if (bGroundTruth) { loc = Location; vel = (loc-lastLocation)/(time-lastTime); outstring = "STA {Time "$time$"}"$ " {Location "$Converter.Str_LengthVectorFromUU(loc)$"}"$ " {Orientation "$Converter.Str_RotatorFromUU(Rotation)$"}"$ " {Velocity "$Converter.Str_VelocityVectorFromUU(vel)$"}"$ //" {CameraFov "$Converter.Str_AngleFromDeg(CameraZoom)$"}"$ " {LightToggle "$bHeadlightOn$"}"$ " {LightIntensity "$HeadlightItensity$"}"$ " {Battery "$(batteryLife-myLife)$"}"$ " {View "$ViewNum$"}"; lastTime = time; lastLocation = loc; } else { outstring = "STA {Time "$time$"}"$ " {Location 0,0,0}"$ " {Orientation 0,0,0}"$ " {Velocity 0,0,0}"$ //" {CameraFov "$Converter.Str_AngleFromDeg(CameraZoom)$"}"$ " {LightToggle "$bHeadlightOn$"}"$ " {LightIntensity "$HeadlightItensity$"}"$ " {Battery "$(batteryLife-myLife)$"}"$ " {View "$ViewNum$"}"; } USARRemoteBot(Controller).myConnection.SendLine(outstring);*/ // Sensor State Message outstring = ""; for (i=0;i<SensorList.length;i++) { if (ProcessedSensors[i]==0) { if (SensorList[i].bUseGroup) outstring = getGroupData(SensorList[i].ItemType); else outstring = SensorList[i].GetData(); if (outstring != "") USARRemoteBot(Controller).myConnection.SendLine(SensorList[i].GetHead()@outstring); } } for (i=0;i<SensorList.length;i++) ProcessedSensors[i] = 0; // Mission Package State Message for (i=0;i<MisPkgs.length;i++) { outstring = "{Time " $ Level.TimeSeconds $ "} {Name " $ MisPkgs[i].PkgName $ "}"; for(j=0; j<JointParts.Length; j++) { if((getLinkNumber(string(JointParts[j].PartName)) > 0) && (getMisPkgName(string(JointParts[j].PartName)) == string(MisPkgs[i].PkgName)) && (getMisPkgLinkInfo(getLinkNumber(string(JointParts[j].PartName)), string(MisPkgs[i].PkgName)) != None)) { outstring = outstring @ "{Link" $ getLinkNumber(string(JointParts[j].PartName)); if (Joints[j].IsA('KSlider')) outstring = outstring @ Converter.Str_LengthFromUU(KSlider(Joints[j]).getDistance()) $ "," $ -KSlider(Joints[j]).KMaxTorque $ "}"; else if(Joints[j].IsA('KDHinge')) outstring = outstring @ Converter.Str_AngleFromUU(-KHinge(Joints[j]).KCurrentAngle) $ "," $ -KHinge(Joints[j]).KMaxTorque $ "}"; } } USARRemoteBot(Controller).myConnection.SendLine("MISSTA"@outstring); } } function String getGroupData(String type) { local String outstring; local int i; outstring = ""; for (i=0;i<SensorList.length;i++) { if (SensorList[i].ItemType == type) { if (outstring=="") outstring = SensorList[i].GetData(); else outstring = outstring@SensorList[i].GetData(); ProcessedSensors[i] = 1; } } return outstring; } /* function flog(string x) { local string filename; filename = USARRemoteBot(Controller).RobotName$"-collisions"; if(CollLog == None) { CollLog = spawn(class'FileLog'); if(CollLog != None) { CollLog.OpenLog(filename); CollLog.Logf(x); } else { log(x); } } else { CollLog.Logf(x); } } */ function fposlog(string x) { local string filename; filename = USARRemoteBot(Controller).RobotName$"-positions"; //UsarGame = USARDeathMatch(Level.Game); if(PosLog == None) { PosLog = spawn(class'FileLog'); if(PosLog != None) { PosLog.OpenLog(filename); PosLog.Logf(x); } else { log(x); } } else { PosLog.Logf(x); } } /* function Touch( actor Other ) { bump_touch_cnt++; if(bstats) { flog("was touched by"@Other@"at"@Level.TimeSeconds@bump_touch_cnt@"times"); Log("KRobot: was touched by"@Other@"at"@Level.TimeSeconds@bump_touch_cnt@"times"); } } function Bump( actor Other ) { bump_touch_cnt++; if(bstats) { flog(bump_touch_cnt@"I was bumped by"@Other@"at"@Level.TimeSeconds); Log(bump_touch_cnt@"Krobot: I was bumped by"@Other@"at"@Level.TimeSeconds); } }*/ //********************************************************************************************************************* // Function which updates the spin speed of the wheel number given by the first parameter. // Please note that the spinSpeed is in Unreal Units. //********************************************************************************************************************* function setSpinSpeed(int wheelNumber, float spinSpeed) { JointsControl[wheelNumber].state = 1; JointsControl[wheelNumber].order = 1; JointsControl[wheelNumber].value = spinSpeed; } //********************************************************************************************************************* // Function which updates the steer angle of the wheel number given by the first parameter. // Please note that the steerAngle is in Unreal Units. //********************************************************************************************************************* function setAngle(int jointIndex, float angle) { JointsControl[jointIndex].state = 1; if(Joints[jointIndex].IsA('KCarWheelJoint')) { JointsControl[jointIndex].order = 1; JointsControl[jointIndex].steer = angle; } else if(Joints[jointIndex].IsA('KDHinge')) { JointsControl[jointIndex].order = 0; JointsControl[jointIndex].value = angle; } } /* function string getRobotConf() { local int i,j; local float currentMax1, currentMax2; local string tmpStr; // This is all the information that we need to send out local string confType; local string confName; local string confMass; local string confDimensions; local string confCOG; local string confMaxSpeed; local string confMaxTorque; local string confSteeringType; local string confWheelRadius; local string confMaxWheelSeparation; local string confMaxFrontSteer; local string confMaxRearSteer; confType = "Robot"; Divide(string(self.class), ".", tmpStr, confName); confMass = converter.FloatString(Weight); confDimensions = converter.FloatString(Dimensions.X) $ "," $ converter.FloatString(Dimensions.Y) $ "," $ converter.FloatString(Dimensions.Z); confCOG = converter.Str_LengthFromUU(KarmaParamsRBFull(KParams).KCOMOffset.X * 50) $ "," $ converter.Str_LengthFromUU(KarmaParamsRBFull(KParams).KCOMOffset.Y * 50) $ "," $ converter.Str_LengthFromUU(KarmaParamsRBFull(KParams).KCOMOffset.Z * 50); confMaxSpeed = converter.FloatString(maxSpinSpeed); confMaxTorque = converter.FloatString(MaxTorque); if(ClassIsChildOf(self.Class,class'AckermanSteeredRobot')) confSteeringType = "AckermanSteered"; else if(ClassIsChildOf(self.Class,class'SkidSteeredRobot')) confSteeringType = "SkidSteered"; else if(ClassIsChildOf(self.Class,class'UnderwaterRobot')) confSteeringType = "Nautic"; else if(ClassIsChildOf(self.Class,class'HelicopterRobot')) confSteeringType = "Aerial"; else confSteeringType = "Unknown"; confWheelRadius = converter.FloatString(WheelRadius); for(i=0; i<JointParts.Length; i++) if(JointParts[i].JointClass==class'KCarWheelJoint') for(j=0; j<JointParts.Length; j++) if(JointParts[j].JointClass==class'KCarWheelJoint') if(((Parts[i].Location >> Rotation).Y - (Parts[j].Location >> Rotation).Y) > currentMax1) currentMax1 = ((Parts[i].Location >> Rotation).Y - (Parts[j].Location >> Rotation).Y); confMaxWheelSeparation = converter.Str_LengthFromUU(currentMax1); currentMax1 = 1000000; currentMax2 = 1000000; for(i=0; i<Wheels.Length; i++) { if(Wheels[i].SteerType == Front_Steered) { if(Wheels[i].MaxSteerAngle < currentMax1) currentMax1 = Wheels[i].MaxSteerAngle; } else if(Wheels[i].SteerType == Rear_Steered) { if(Wheels[i].MaxSteerAngle < currentMax2) currentMax2 = Wheels[i].MaxSteerAngle; } } if(currentMax1 == 1000000) currentMax1 = 0; if(currentMax2 == 1000000) currentMax2 = 0; confMaxFrontSteer = converter.FloatString(currentMax1); confMaxRearSteer = converter.FloatString(currentMax2); return "CONF {Type " $ confType $ "} {Name " $ confName $ "} {Mass " $ confMass $ "} {Dimensions " $ confDimensions $ "} {COG " $ confCOG $ "} " $ "{MaxSpeed " $ confMaxSpeed $ "} {MaxTorque " $ confMaxTorque $ "} {SteeringType " $ confSteeringType $ "} {WheelRadius " $ confWheelRadius $ "} " $ "{MaxWheelSeparation " $ confMaxWheelSeparation $ "} {MaxFrontSteer " $ confMaxFrontSteer $ "} {MaxRearSteer " $ confMaxRearSteer $ "}"; }*/ defaultproperties { //Scaled with 4.762 at Mon Sep 25 14:21:50 EDT 2006 bDebug=false ConverterClass="USARBot.USARConverter" bMountByUU=false AmbientGlow=48 bSpecialHUD=True bGroundTruth=True //Set the following 2 variables to true if you want shadow //from the chassis of the robot: bVehicleShadows=False bDrawVehicleShadow=False MaxTorque=60.0 SafeForce=1000 ProtectTime=1.0 MotorTorque=20.0 MotorSpeed=0.1745 // rad per second HingePropGap=364.0 //uu SteerPropGap=1000.000000 SteerTorque=1000.000000 SteerSpeed=15000.000000 // in UU SuspStiffness=150.000000 SuspDamping=15.000000 SuspHighLimit=1.000000 SuspLowLimit=-1.000000 TireRollFriction=15.000000 TireLateralFriction=15.00000 TireRollSlip=0.060000 TireLateralSlip=0.060000 TireMinSlip=0.001000 TireSlipRate=0.000500 TireSoftness=0.000000 TireAdhesion=0.000000 TireRestitution=0.000000 bBlockActors=true bCollideActors=True CollisionRadius=25 CollisionHeight=10 ChassisMass=1.000000 FlipTorque=350.000000 FlipTime=3.000000 MaxNetUpdateInterval=0.05 HitSoundThreshold=30.000000 batteryLife=3600 msgTimer=0.200000 logging_period=1 DrawType=DT_StaticMesh StaticMesh=StaticMesh'USARSim_VehicleParts_Meshes.Test.TestBody' DrawScale=4.762 Begin Object Class=KarmaParamsRBFull Name=KParams0 KStartEnabled=True bHighDetailOnly=False bClientOnly=False bKDoubleTickRate=True KInertiaTensor(0)=0.4 KInertiaTensor(3)=0.4 KInertiaTensor(5)=0.4 KMaxAngularSpeed=100 KMaxSpeed=25000 KLinearDamping=0.0 KAngularDamping=0.0 KFriction=0.5 Name="KParams0" End Object KParams=KarmaParamsRBFull'USARBot.KRobot.KParams0' } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |