Getting motor name and port number?


#1

Hi, I am trying to create a function that will print out information about a motor to the brain screen. I would like to simply call the function with a single


vex::motor

object and have it get the name (the one defined in robot-config.h) and which port it is plugged into. Is there any way to do this?


#2

There’s no way to get the name of the motor, and the index is protected.

However you can make a derived class of


vex::motor

to get the port


class Motor : public vex::motor{
    public:
        int32_t getPort(){
            //add one becasue index is zero based
            return this->_index+1;
        }
};


#3

if youre looking for the port the motor is in, my method was unplugging it from the brain, then seeing which motor light turned off. for example, if my puncher is in port 20, and i unplug 20 and my puncher turns off, i know that port 20 is my puncher motor


#4

Or, you could check the motor screen on your brain and in the code itself.