Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛[BUG] - motor .get_direction() does not work #695

Open
ssejrog opened this issue Sep 5, 2024 · 3 comments
Open

🐛[BUG] - motor .get_direction() does not work #695

ssejrog opened this issue Sep 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ssejrog
Copy link
Contributor

ssejrog commented Sep 5, 2024

Describe the bug
This outputs 2147483647

To Reproduce
Steps to reproduce the behavior:
The example project uses motor = 127 instead of motor.move(), so with that this is the example code.

void opcontrol() {
  pros::MotorGroup mg({1, 3});
  pros::Controller master(E_CONTROLLER_MASTER);
  while (true) {
    mg.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));
    // Print the motor direction for the motor at index 1. (port 3)
    std::cout << "Motor Direction: " << mg.get_direction();
    pros::delay(2);
  }
}

Expected behavior
Because the motor isn't reversed, I should see 1.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS, Windows, Linux]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@ssejrog ssejrog added the bug Something isn't working label Sep 5, 2024
@WillXuCodes
Copy link
Member

are the motors plugged in

@ssejrog
Copy link
Contributor Author

ssejrog commented Sep 5, 2024

are the motors plugged in

it turns out I was confusing two issues-

I'm having a constructor take a motor group instead of a vector of ints. I was trying to check the direction of the motors so I could copy/paste it to the "motor groups" that are used internally in the code. This didn't work, and then the example code didn't work (when I don't have motors in port 1 or 3), and I made this issue.

I've done more testing now and it seems like something still isn't quite right.

No matter what I do with the directions of 11 and 15, the only thing I see printed is 0. I tried{11, 15}, {-11, 15}, {-11, -15}, {11, -15}.

pros::MotorGroup mg({11, 15});
int dir = mg.get_direction();
using namespace pros;
void opcontrol() {
  std::cout << "Motor Direction: " << dir << "\n";
  printf("\n\n");
  pros::Controller master(E_CONTROLLER_MASTER);

  while (true) {
    mg.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));
    dir = mg.get_direction();
    std::cout << "Motor Direction: " << dir << "\n";
    pros::delay(2);
  }
}

This is also true of 11 and -11 with a motor and not a motor group, only 0 is printed.

pros::Motor mg(11);
int dir = mg.get_direction();
using namespace pros;
void opcontrol() {
  std::cout << "Motor Direction: " << dir << "\n";
  printf("\n\n");
  pros::Controller master(E_CONTROLLER_MASTER);

  while (true) {
    mg.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));
    // Print the motor direction for the motor at index 1. (port 3)
    dir = mg.get_direction();
    std::cout << "Motor Direction: " << dir << "\n";
    pros::delay(2);
  }
}

and it is also true of the C functions, only 0 is printed.

void opcontrol() {
  while (true) {
    pros::c::motor_move(-11, pros::c::controller_get_analog(pros::E_CONTROLLER_MASTER, pros::E_CONTROLLER_ANALOG_LEFT_Y));
    printf("Motor Direction: %d\n", pros::c::motor_get_direction(11));
    pros::delay(2);
  }
}

In all of these examples, I confirmed the motors were moving with the joystick. Sorry for not being as thorough initially!

@thiccaxe
Copy link

thiccaxe commented Oct 7, 2024

We can't reproduce this. "2147483647" is when the motor is not plugged in, which you seem to have resolved. But if the motor is moving, it should output -1 or 1. Are you running the latest version of the kernel?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants