1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
Robot::LadyBrown Class Reference

The LadyBrown class represents the robot lady brown subsystem. More...

#include <ladybrown.h>

Public Types

enum  LADYBROWN_STATE { BASE_STATE = 1 , LOAD_STATE = 2 , ATTACK_STATE = 3 , SIZECHECK_STATE = 4 }
 

Public Member Functions

void run (bool async=true, int timeout=1000)
 
void MoveToPoint (LadyBrown::LADYBROWN_STATE state, int max_error=150, int timeout=1000)
 
 LadyBrown ()
 
int get_target ()
 

Private Attributes

lemlib::PID MoveToPointPID
 
lemlib::PID ActiveBrakePID
 
int brake_target
 
int target
 
bool isPIDRunning
 
bool manualControl
 

Static Private Attributes

static LADYBROWN_STATE current_state = LadyBrown::BASE_STATE
 

Detailed Description

The LadyBrown class represents the robot lady brown subsystem.

Definition at line 9 of file ladybrown.h.

Member Enumeration Documentation

◆ LADYBROWN_STATE

Enumerator
BASE_STATE 
LOAD_STATE 
ATTACK_STATE 
SIZECHECK_STATE 

Definition at line 12 of file ladybrown.h.

Constructor & Destructor Documentation

◆ LadyBrown()

LadyBrown::LadyBrown ( )

Definition at line 15 of file ladybrown.cpp.

15 : MoveToPointPID(2, 0, 0, 2, false), ActiveBrakePID(0.8, 0, 1, 6, true) {
16 LadyBrownRotation.set_position(0);
17 bool manualControl = false;
18 LadyBrownMotor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
19}
lemlib::PID ActiveBrakePID
Definition ladybrown.h:25
lemlib::PID MoveToPointPID
Definition ladybrown.h:23
pros::Motor LadyBrownMotor(-10, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees)
pros::Rotation LadyBrownRotation(9)

References ActiveBrakePID, Robot::Globals::LadyBrownMotor(), Robot::Globals::LadyBrownRotation(), manualControl, and MoveToPointPID.

Member Function Documentation

◆ get_target()

int LadyBrown::get_target ( )

Definition at line 81 of file ladybrown.cpp.

81{ return target; }

References target.

◆ MoveToPoint()

void LadyBrown::MoveToPoint ( LadyBrown::LADYBROWN_STATE state,
int max_error = 150,
int timeout = 1000 )

Definition at line 83 of file ladybrown.cpp.

83 {
84
85 std::cout << "state: " << current_state << std::endl;
86 constexpr double base_location = 30;
87 constexpr double load_location = -1900;
88 constexpr double attack_location = -15500;
89
90 int target;
91
92 std::cout << "state: " << state << std::endl;
93 std::cout << "pid: " << isPIDRunning << std::endl;
94
95 if (!isPIDRunning) {
96
97 std::cout << "inner pid: " << isPIDRunning << std::endl;
99
100 switch (state) {
102 target = base_location;
103 break;
105 target = load_location;
106 break;
108 target = attack_location;
109 break;
111 target = -12550;
112 break;
113 }
114
115 std::cout << "target: " << target << std::endl;
116
117 MoveToPointPID.reset();
118
119 lemlib::Timer timer(timeout);
120
121 while (LadyBrown::isPIDRunning == true) {
122 double error = target - LadyBrownRotation.get_position();
123 double motor_voltage = MoveToPointPID.update(error);
124
125 // motor_voltage = lemlib::slew(motor_voltage, LadyBrownMotor.get_voltage(), 1500);
126
127 if (std::abs(error) < max_error || timer.isDone()) {
128 LadyBrownMotor.brake();
131 break;
132 }
133
134 LadyBrownMotor.move_voltage(motor_voltage);
136
138 return;
139 }
140
141 pros::delay(20);
142 }
143 }
144}
static LADYBROWN_STATE current_state
Definition ladybrown.h:29

References ATTACK_STATE, BASE_STATE, current_state, isPIDRunning, Robot::Globals::LadyBrownMotor(), Robot::Globals::LadyBrownRotation(), LOAD_STATE, MoveToPointPID, SIZECHECK_STATE, and target.

Referenced by run().

◆ run()

void LadyBrown::run ( bool async = true,
int timeout = 1000 )

Definition at line 22 of file ladybrown.cpp.

22 {
23 LADYBROWN_STATE move_to;
24
25 if (!isPIDRunning) {
26
27 if (controller.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) {
29 LadyBrownMotor.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
30
31 //delay to exit the previous PID inside this control flow
32 pros::delay(50);
33 manualControl = true;
34 LadyBrownMotor.move_velocity(-200);
35
36 if (LadyBrownRotation.get_position() > -10000) {
37 LadyBrown::brake_target = LadyBrownRotation.get_position() - 4500;
38 } else {
39 LadyBrown::brake_target = LadyBrownRotation.get_position() - 2300;
40 }
41
42 }
43 else {
44 if (!manualControl) {
45 LadyBrownMotor.move_velocity(0);
46 } else {
47 LadyBrownMotor.move_voltage(ActiveBrakePID.update(LadyBrown::brake_target - LadyBrownRotation.get_position()));
48 }
49 }
50 }
51
52 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_L2)) {
54 LadyBrownMotor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
55 manualControl = false;
56 //delay to exit the previous PID inside this control flow
57 pros::delay(50);
58
60 move_to = LOAD_STATE;
61 } else {
62 move_to = BASE_STATE;
63 }
64
65 std::cout << "Moving to: " << move_to << std::endl;
66 std::cout << "current state: " << current_state << std::endl;
67
68
69 if (!async) {
70 MoveToPoint(move_to);
71 } else {
72 pros::Task move([move_to, this]() { MoveToPoint(move_to); }, "LadyBrownMove");
73 }
74
75 if (!isPIDRunning) {
76 current_state = move_to;
77 }
78 }
79}
void MoveToPoint(LadyBrown::LADYBROWN_STATE state, int max_error=150, int timeout=1000)
Definition ladybrown.cpp:83
pros::Controller controller(pros::E_CONTROLLER_MASTER)

References ActiveBrakePID, BASE_STATE, brake_target, Robot::Globals::controller(), current_state, isPIDRunning, Robot::Globals::LadyBrownMotor(), Robot::Globals::LadyBrownRotation(), LOAD_STATE, manualControl, and MoveToPoint().

Member Data Documentation

◆ ActiveBrakePID

lemlib::PID Robot::LadyBrown::ActiveBrakePID
private

Definition at line 25 of file ladybrown.h.

Referenced by LadyBrown(), and run().

◆ brake_target

int Robot::LadyBrown::brake_target
private

Definition at line 27 of file ladybrown.h.

Referenced by run().

◆ current_state

LadyBrown::LADYBROWN_STATE LadyBrown::current_state = LadyBrown::BASE_STATE
staticprivate

Definition at line 29 of file ladybrown.h.

Referenced by MoveToPoint(), and run().

◆ isPIDRunning

bool Robot::LadyBrown::isPIDRunning
private

Definition at line 33 of file ladybrown.h.

Referenced by MoveToPoint(), and run().

◆ manualControl

bool Robot::LadyBrown::manualControl
private

Definition at line 35 of file ladybrown.h.

Referenced by LadyBrown(), and run().

◆ MoveToPointPID

lemlib::PID Robot::LadyBrown::MoveToPointPID
private

Definition at line 23 of file ladybrown.h.

Referenced by LadyBrown(), and MoveToPoint().

◆ target

int Robot::LadyBrown::target
private

Definition at line 31 of file ladybrown.h.

Referenced by get_target(), and MoveToPoint().


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