purduesigbots / pros

Source code for PROS kernel: open source C/C++ development for the VEX V5 microcontroller
https://pros.cs.purdue.edu
Other
267 stars 76 forks source link

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

Open ssejrog opened 2 months ago

ssejrog commented 2 months ago

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):

Additional context Add any other context about the problem here.

WillXuCodes commented 2 months ago

are the motors plugged in

ssejrog commented 2 months ago

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 commented 1 month ago

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?