Comparing Objects in VexCode

I’m new to vexcode, coming from java, and I’m having trouble comparing objects (specifically motor groups). if (mGroupA == mGroupB) won’t work for obvious reasons, so my train of thought was to maybe create an equals method to compare the two. This being said, I’m relatively new to c++, and couldn’t decipher any clear primitives I could use for comparison in the motor_group definition. I was wondering if anyone could either
a. Point out the comparable primitives(if they aren’t private),
b. Provide an easier way to compare objects,
c. Tell me altering the source code is the best option, or
d. Tell me to give up and do things the harder way

P.S. this is my first post, so apologies if it sounds convoluted.

What are you trying to accomplish by comparing motor group objects?

Answering this question should help the community come up with suggestions.

I’m using a motor group parameter for a method (as well as other parameters), and based upon which motor group comes into the method, I will then run those motors at full speed. This would not be an issue if the method only ran the motors, but I also want to check if the motors are already running and in which direction using motor group specific variables that I activate whenever I run that motor group. This way I do not call the spin motors function on motors that are already spinning.

I can easily find a convoluted way around this issue, but being able to compare objects would simplify this method and methods for the future.

It sounds like you definitely want to use pointers. You can see some examples of pointer usage here and here.

As for checking whether motors are already running and their direction, take a look at the API reference.

Yeah, passing pointers to the motor_group would do the trick, even easier would be to pass them by reference. Then you can compare the address of the motor_group parameter with the address of your globally-declared motor_group objects to see which one got passed to the function.

Here’s some example code that does this with ints:

#include <iostream>
using std::cout;
using std::endl;

//global int objects
int a = 10;
int b = 20;

//ampersand after type means "pass by reference"
void test(int& foo){
    //test to see if the int passed by reference is either of the globals
    if (&foo == &a){
        cout << "called test with a" << endl;
    else if (&foo == &b){
        cout << "called test with b" << endl;
        cout << "called test with something else" << endl;

int main(){
    //call the test function with both the globals

The expected output of this program is:


Not sure if it affects what you are trying to do, but queries about the status of a motor_group return the status of the first motor in the group, not an average of all the motors in the group.

1 Like

yea, that’s mostly true, a very few things will return average or totals, for example, current( amp ) would return total current (at least in the latest sdk, it has changed from the original release). Most things like velocity are not particularly helpful if the motors are not mechanically coupled in some way.