Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11834


Ignore:
Timestamp:
Mar 29, 2018, 12:15:19 PM (6 years ago)
Author:
dreherm
Message:

Update for ghost controller and ghost class

Location:
code/branches/3DPacman_FS18/src/modules/3DPacman
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc

    r11832 r11834  
    5050        this->localLinearAcceleration_.setValue(0, 0, 0);
    5151        this->localAngularAcceleration_.setValue(0, 0, 0);
    52         this->primaryThrust_  = 100;
    53         this->auxiliaryThrust_ = 100;
    54         this->rotationThrust_ = 10;
    5552
    5653        this->setCollisionType(CollisionType::Dynamic);
     54
     55        Vector3 resetposition = new Vector3(0,0,0); //Set Default start position
     56
    5757    }
    5858
     
    7878
    7979        XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
    80         // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort.
    81         // Variables can be added by the following command
    82         // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode);
    83         // Also make sure that you also create the get- and set-functions in AutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there.
     80        XMLPortParam(PacmanGhost, "auxilliaryThrust", setAuxillaryThrust, getAuxillaryThrust, xmlelement, mode);
     81        XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
     82        XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode);
    8483    }
    8584
  • code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.h

    r11832 r11834  
    5555            virtual void rotatePitch(const Vector2& value);
    5656            virtual void rotateRoll(const Vector2& value);
    57 
     57           
     58            virtual void resetGhost();
    5859            /**
    5960            @brief Moves the Drone in the Front/Back-direction by the specifed amount.
     
    100101            inline void setPrimaryThrust( float thrust )
    101102                { this->primaryThrust_ = thrust; }
    102             //TODO: Place your set-functions here.
    103             // Hint: auxiliary thrust, rotation thrust.
    104            
     103            inline void setAuxillaryThrust( float thrust )
     104                { this->auxillaryThrust_ = thrust; }
     105            inline void setRotationThrust( float thrust )
     106                { this->rotationThrust_ = thrust; }
     107
     108            inline void setResetPosition(Vector3 rpos)
     109                { this->resetposition = rpos; }   
     110     
    105111            /**
    106112            @brief Gets the primary thrust to the input amount.
     
    109115            inline float getPrimaryThrust()
    110116                { return this->primaryThrust_; }
    111             //TODO: Place your get-functions here.
     117            inline float getAuxillaryThrust()
     118                { return this->auxillaryThrust_; }
     119            inline float getRotationThrust()
     120                { return this->rotationThrust_; }
     121           
     122            inline Vector3 getResetPosition()
     123                { return this->resetposition; }       
     124
     125
    112126
    113127        private:
     
    119133            float auxiliaryThrust_; //!< The amount of auxiliary thrust. Used for all other movements (except for rotations).
    120134            float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.s
     135            Vector3 resetposition; //Start position for Ghost
    121136       
    122137    };
  • code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc

    r11832 r11834  
    4343        The context of this object.
    4444    */
    45     PacmanGhostRed::PacmanGhostController(Context* context) : Controller(context)
     45    PacmanGhostController::PacmanGhostController(Context* context) : Controller(context)
    4646    {
    4747        RegisterObject(PacmanGhostController);
     48
     49        PacmanGhost* myGhost = nullptr;
     50        this->actuelposition = myGhost.getPosition();
     51
    4852        bool ismoving = false;
    49         float reltarget_x;
    50         float reltarget_z; 
    51         Vector3& actuelposition;     
     53        this->target_x = actuelposition.x;
     54        this->target_z = actuelposition.z;     
     55    }
     56
     57    void PacmanGhostController::setGhost(PacmanGhost ghost){
     58        this->myGhost = ghost;
    5259    }
    5360
     
    6168    }
    6269
     70
     71    static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)];
    6372    /**
    6473    @brief
     
    7786        PacmanGhost* myDrone = *it;
    7887
    79         if (myGhost != nullptr)
     88        if (this->myGhost != nullptr)
    8089        {
    8190
    82             actuelposition = myGhost.getPosition();
     91            this->actuelposition = this->myGhost.getPosition();
    8392
    84             if(actuelposition.x = reltarget_x && actuelposition.z = reltarget_z){
    85                     ismoving = false;
     93            if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){
     94                    this->ismoving = false;
    8695            }
    8796
    88 
    89 
    90             if(ismoving){
    91                 moveRightLeft();
    92                 moveFrontBack();
     97        if(this->ismoving){
     98            if(!((this->actuelposition.z-target_z)<0.1))
     99                moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100);
     100            if(!((this->actuelposition.x-target_x)<0.1))
     101              moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small
     102        }
     103       
     104        else{ //Check on which position ghost is
     105            if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){
     106                this->target_x = possibleposition[1].x;
     107                this->target_z = possibleposition[1].z;
     108                this->ismoving = true;
    93109            }
    94        
     110            else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){
     111                this->target_x = 0
     112                this->target_z = 
     113                this->ismoving = true;
     114            }
    95115            else{
    96 
    97                 //hashtable
    98 
    99                 int random = rand();
    100 
    101                 switch(actuelposition) {
    102                     case 1: if(random % 4 == 0){
    103                             reltarget_x = 250;
    104                             reltarget_z = 0;
    105                             }
    106                             else if(random % 4 == 1){
    107                             reltarget_x = 0;
    108                             reltarget_z = 250;
    109                             }
    110                             else if(random % 4 == 2){
    111                             reltarget_x = 0;
    112                             reltarget_z = -250;
    113                             }
    114                             else if(random % 4 == 3){
    115                             reltarget_x = -250;
    116                             reltarget_z = 0;
    117                             }
    118                             moving = true;
    119                     case 2:
    120                 }
    121             }
    122 
     116            }     
     117            } //End of Position table
    123118
    124119        }
    125120    }
     121
    126122}
Note: See TracChangeset for help on using the changeset viewer.