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

✨ PROS 3.8: Add "at()" Method To Motor Groups #496

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

AlexHunton2
Copy link

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.

@Richard-Stump Richard-Stump changed the title .at() method for motor groups ✨ PROS 3.8: Add "at()" Method To Motor Groups Jan 25, 2023
@AlexHunton2
Copy link
Author

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);
}

@noam987 noam987 merged commit ccf4fef into develop Jan 27, 2023
@noam987 noam987 deleted the at_method_motor_groups branch January 27, 2023 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants