Closed AlexHunton2 closed 1 year ago
Tested and works with the following code:
pros::Controller master(pros::E_CONTROLLER_MASTER);
pros::Motor left_mtr(1);
pros::Motor right_mtr(2);
std::shared_ptr<pros::Motor_Group> motor_group = std::make_shared<pros::MotorGroup>(({left_mtr, right_mtr}));
while (true) {
pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,
(pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,
(pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0);
int left = master.get_analog(ANALOG_LEFT_Y);
int right = master.get_analog(ANALOG_RIGHT_Y);
motor_group.at(0) = left;
motor_group.at(1) = right;
pros::delay(20);
}
Summary:
Adds the at() operator to the Motor_Groups. Throws an error if the bozo attempts to go out of ranges.
Motivation:
Issues with smart pointers make the process of using the [] operator a headache. This method should offer a simple solution while being similar to C++ syntax.
References (optional):
494
Test Plan:
Will test on simple program that controls multiple motors and I will check if I can use them when using a smart pointer. Will post here with update on proper test.