Weird pros problem

This is our ez template code we got from the ez pto tutorial

( PTO Tutorial | EZ Template)

we configured the ports and button stuff and for our op control, we just put

intakecontrol();

pros::Motor& intake_l = chassis.left_motors[-4];
pros::Motor& indexer = chassis.right_motors[14];
pros::ADIDigitalOut transmission ('A');
bool pto_intake_enabled = false;

void pto_intake(bool toggle) {
  pto_intake_enabled = toggle;
  chassis.pto_toggle({intake_l, indexer}, toggle);
  transmission.set_value(toggle);
  if (toggle) {
    intake_l.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
    indexer.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
  }
}

void set_intake(int input) {
  if (!pto_intake_enabled) return;
  intake_l = input;
  indexer = input;
}

int button_lock = 0;
void intake_control() {
  if (master.get_digital(DIGITAL_L1) && button_lock == 0) {
    pto_intake(!pto_intake_enabled);
    button_lock = 1;
  } else if (!master.get_digital(DIGITAL_L2)) {
    button_lock = 0;
  }

  if (master.get_digital(DIGITAL_X))
    set_intake(-100);
  else if (master.get_digital(DIGITAL_B))
    set_intake(100);
  else
    set_intake(0);
}


when i press button L1 to enable the pto, it gives this weird output and the robot stops driving

In your first lines of code, within the square brackets you input the ports instead of the index. The motors are stored in a vector, so the number you put in the square brackets is the place in the vector the motor is.

If your drive constructure looks like this

Drive chassis (
  // Left Chassis Ports (negative port will reverse it!)
  //   the first port is the sensored port (when trackers are not used!)
  {1, 2, -4}

  // Right Chassis Ports (negative port will reverse it!)
  //   the first port is the sensored port (when trackers are not used!)
  ,{5, 14, 6}

  // IMU Port
  ,7

  // Wheel Diameter (Remember, 4" wheels are actually 4.125!)
  ,4.125

  // Cartridge RPM
  ,600

  // External Gear Ratio (MUST BE DECIMAL)
  // eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 2.333.
  // eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 0.6.
  ,2.333
);

Then the index for your intake motor is chassis.left_motors[2] and for the indexer is chassis.right_motors[1]. These start counting from 0.


The second issue is the tutorial is wrong on something that we haven’t fixed yet. Instead of creating the motors with

pros::Motor& intake_l = chassis.left_motors[2];
pros::Motor& indexer = chassis.right_motors[1];

and using intake_l and indexer throughout the code, call chassis.left_motors[2] and chassis.right_motors[1] directly.


The tutorial fails at making both of these things more clear, this is one of the most common questions I get about the pto stuff. Thanks for reminding me about this as 3.0 is coming out at some point, we’ll make sure this is fixed with that release. Let me know if this fixed the problem!

4 Likes

yo thanks so much that worked

1 Like