Esempio n. 1
0
        public ChLinkEngine()
        {
            mot_rot              = 0;
            mot_rot_dt           = 0;
            mot_rot_dtdt         = 0;
            mot_rerot            = 0;
            mot_rerot_dt         = 0;
            mot_rerot_dtdt       = 0;
            mot_torque           = 0;
            mot_retorque         = 0;
            last_r3mot_rot       = 0;
            last_r3mot_rot_dt    = 0;
            last_r3relm_rot      = ChQuaternion.QUNIT;
            last_r3relm_rot_dt   = ChQuaternion.QNULL;
            last_r3time          = 0;
            keyed_polar_rotation = ChQuaternion.QNULL;
            impose_reducer       = false;
            mot_tau              = 1;
            mot_eta              = 1;
            mot_inertia          = 0;
            torque_react2        = 0;
            eng_mode             = eCh_eng_mode.ENG_MODE_ROTATION;
            learn     = false;
            rot_funct = new ChFunction_Const(0);
            spe_funct = new ChFunction_Const(0);
            tor_funct = new ChFunction_Const(0);
            torque_w  = new ChFunction_Const(1);

            rot_funct_x = new ChFunction_Const(0);
            rot_funct_y = new ChFunction_Const(0);

            // Mask: initialize our LinkMaskLF (lock formulation mask)
            // to E3 only.
            ChLinkMaskLF masklf = new ChLinkMaskLF();

            mask = masklf;
            ((ChLinkMaskLF)mask).SetLockMask(true, false, false, false, false, false, true);
            ChangedLinkMask();

            // Mask: initialize remaining LinkMaskLF (lock formulation mask) for the engine.
            // All shaft modes at least are setting the lock on E3 (z-rotation) coordinate.
            Set_shaft_mode(eCh_shaft_mode.ENG_SHAFT_LOCK);
        }
Esempio n. 2
0
        public void Set_eng_mode(eCh_eng_mode mset)
        {
            if (Get_learn())
            {
                Set_learn(false);  // reset learn state when changing mode
            }
            if (eng_mode != mset)
            {
                eng_mode = mset;

                switch (eng_mode)
                {
                case eCh_eng_mode.ENG_MODE_ROTATION:
                case eCh_eng_mode.ENG_MODE_SPEED:
                case eCh_eng_mode.ENG_MODE_KEY_ROTATION:
                    ((ChLinkMaskLF)mask).Constr_E3().SetMode(eChConstraintMode.CONSTRAINT_LOCK);
                    break;

                case eCh_eng_mode.ENG_MODE_KEY_POLAR:
                    ((ChLinkMaskLF)mask).Constr_E1().SetMode(eChConstraintMode.CONSTRAINT_LOCK);
                    ((ChLinkMaskLF)mask).Constr_E2().SetMode(eChConstraintMode.CONSTRAINT_LOCK);
                    ((ChLinkMaskLF)mask).Constr_E3().SetMode(eChConstraintMode.CONSTRAINT_LOCK);
                    break;

                case eCh_eng_mode.ENG_MODE_TORQUE:
                    ((ChLinkMaskLF)mask).Constr_E3().SetMode(eChConstraintMode.CONSTRAINT_FREE);
                    break;

                case eCh_eng_mode.ENG_MODE_TO_POWERTRAIN_SHAFT:
                    ((ChLinkMaskLF)mask).Constr_E3().SetMode(eChConstraintMode.CONSTRAINT_FREE);
                    innerconstraint1 = gameObject.AddComponent <ChShaftsBody>();
                    innerconstraint2 = gameObject.AddComponent <ChShaftsBody>();
                    innershaft1      = gameObject.AddComponent <ChShaft>();
                    innershaft2      = gameObject.AddComponent <ChShaft>();
                    SetUpMarkers(marker1, marker2);      // to initialize innerconstraint1 innerconstraint2
                    break;
                }

                ChangedLinkMask();  // update all from new mask
            }

            if (eng_mode == eCh_eng_mode.ENG_MODE_KEY_ROTATION && rot_funct.Get_Type() != ChFunction.FunctionType.FUNCT_CONST)
            {
                rot_funct = new ChFunction_Const();
            }

            if (eng_mode == eCh_eng_mode.ENG_MODE_KEY_POLAR)
            {
                if (rot_funct.Get_Type() != ChFunction.FunctionType.FUNCT_CONST)
                {
                    rot_funct = new ChFunction_Const();
                }
                if (rot_funct_x.Get_Type() != ChFunction.FunctionType.FUNCT_CONST)
                {
                    rot_funct_x = new ChFunction_Const();
                }
                if (rot_funct_y.Get_Type() != ChFunction.FunctionType.FUNCT_CONST)
                {
                    rot_funct_y = new ChFunction_Const();
                }
            }
        }