1516b Over Under 2.0
Codebase for 1516b over under season
Loading...
Searching...
No Matches
Robot::Puncher Class Reference

Represents a Puncher mechanism for a robot. More...

#include <puncher.h>

Public Member Functions

void run (int autonVal)
 Runs the puncher based on the given autonomous value.
 
void setDistancePuncher (bool punch)
 Sets the distancePuncher variable based on the punch parameter.
 
void PuncherSwitch ()
 Toggles whether the distance sensor is activated or not and prints it out.
 

Private Member Functions

int toShoot ()
 Checks if the distance sensor is connected and whether to shoot.
 

Private Attributes

bool distancePuncher
 Determines whether to use the distance sensor or not.
 

Detailed Description

Represents a Puncher mechanism for a robot.

The Puncher class provides functionality to control a puncher mechanism on a robot. It allows running the puncher based on an autonomous value, setting the distancePuncher variable, toggling the distance sensor activation, and checking whether to shoot or not.

Definition at line 12 of file puncher.h.

Member Function Documentation

◆ PuncherSwitch()

void Puncher::PuncherSwitch ( )

Toggles whether the distance sensor is activated or not and prints it out.

This function toggles the distance sensor activation by flipping the value of the distancePuncher variable. It then prints out the current state of the distancePuncher variable.

Definition at line 55 of file puncher.cpp.

55 {
56
57 if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_LEFT)) {
58
59 // Toggles the puncher distance sensor
61
62
63 // Prints the state of the puncher distance sensor to the brain(as a boolean)
64 if (distancePuncher == true) {
65 controller.print(0, 0, "Puncher: True");
66 }
67 else {
68 controller.print(0, 0, "Puncher: False");
69 }
70
71
72 }
73
74
75
76}
bool distancePuncher
Determines whether to use the distance sensor or not.
Definition puncher.h:61
void setDistancePuncher(bool punch)
Sets the distancePuncher variable based on the punch parameter.
Definition puncher.cpp:10
pros::Controller controller

References Robot::Globals::controller, distancePuncher, and setDistancePuncher().

Referenced by Robot::Utility::toggleSubsystemOptions().

◆ run()

void Puncher::run ( int autonVal)

Runs the puncher based on the given autonomous value.

This function executes the puncher mechanism based on the provided autonomous value. It contains conditionals that determine the behavior of the puncher.

Note
Make sure to have the Puncher object initialized before calling this function.
Parameters
autonValThe autonomous value to determine the puncher behavior.

Definition at line 15 of file puncher.cpp.

15 {
16
17 // Manual Puncher Control
18 if (Puncher::toShoot() == 2 || distancePuncher == false) {
19 if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) {
20 punchers.move(127);
21 }
22 else {
23 punchers.brake();
24 }
25 }
26
27 // Auton Puncher Control using the distance sensor
28 if (distancePuncher == true && autonVal == 3) {
29 if (Puncher::toShoot() == 0) {
30 punchers.move_absolute(30, 95);
31 }
32 else {
33 punchers.brake();
34 }
35 }
36
37
38}
int toShoot()
Checks if the distance sensor is connected and whether to shoot.
Definition puncher.cpp:40
pros::Motor_Group punchers

References Robot::Globals::controller, distancePuncher, Robot::Globals::punchers, and toShoot().

Referenced by Robot::Autonomous::Auton3(), and opcontrol().

◆ setDistancePuncher()

void Puncher::setDistancePuncher ( bool punch)

Sets the distancePuncher variable based on the punch parameter.

This function sets the distancePuncher variable based on the provided punch parameter. The distancePuncher variable determines the behavior of the puncher mechanism.

Parameters
punchThe value to set the distancePuncher variable to.

Definition at line 10 of file puncher.cpp.

10 {
11 distancePuncher = punch;
12}

References distancePuncher.

Referenced by PuncherSwitch().

◆ toShoot()

int Puncher::toShoot ( )
private

Checks if the distance sensor is connected and whether to shoot.

This function checks if the distance sensor is connected and retrieves the distance from the triball. It uses the distance to determine whether to shoot or not.

Returns
The value returned of whether to shoot or not.

Definition at line 40 of file puncher.cpp.

40 {
41 if (pros::c::registry_get_plugged_type(13) != pros::c::E_DEVICE_DISTANCE) {
42 distancePuncher = false;
43 return 2;
44 }
45 if (distance.get() <= 12 && distancePuncher == true) {
46 return 1;
47 }
48 if (distance.get() > 12 && distancePuncher == true) {
49 return 0;
50 }
51 return 2;
52}
pros::Distance distance

References Robot::Globals::distance, and distancePuncher.

Referenced by run().

Member Data Documentation

◆ distancePuncher

bool Robot::Puncher::distancePuncher
private

Determines whether to use the distance sensor or not.

The distancePuncher variable decides whether to use the distance sensor or not. If distancePuncher is true, the distance sensor is used. If it is false, the distance sensor is not used.

Definition at line 61 of file puncher.h.

Referenced by PuncherSwitch(), run(), setDistancePuncher(), and toShoot().


The documentation for this class was generated from the following files: