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 }
 

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
 
int target
 
bool isPIDRunning
 

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 

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) {
16 LadyBrownRotation.set_position(0);
17 LadyBrownMotor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
18}
lemlib::PID MoveToPointPID
Definition ladybrown.h:23
pros::Rotation LadyBrownRotation(8)
pros::Motor LadyBrownMotor(-3, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees)

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

Member Function Documentation

◆ get_target()

int LadyBrown::get_target ( )

Definition at line 70 of file ladybrown.cpp.

70{ return target; }

References target.

◆ MoveToPoint()

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

Definition at line 72 of file ladybrown.cpp.

72 {
73
74 std::cout << "state: " << current_state << std::endl;
75 constexpr double base_location = 30;
76 constexpr double load_location = -2550;
77 constexpr double attack_location = -15500;
78
79 int target;
80
81 std::cout << "state: " << state << std::endl;
82 std::cout << "pid: " << isPIDRunning << std::endl;
83
84 if (!isPIDRunning) {
85
86 std::cout << "inner pid: " << isPIDRunning << std::endl;
88
89 switch (state) {
91 target = base_location;
92 break;
94 target = load_location;
95 break;
97 target = attack_location;
98 break;
99 }
100
101 std::cout << "target: " << target << std::endl;
102
103 MoveToPointPID.reset();
104
105 lemlib::Timer timer(timeout);
106
107 while (true) {
108 double error = target - LadyBrownRotation.get_position();
109 double motor_voltage = MoveToPointPID.update(error);
110
111 // motor_voltage = lemlib::slew(motor_voltage, LadyBrownMotor.get_voltage(), 1500);
112
113 if (std::abs(error) < max_error || timer.isDone()) {
114 LadyBrownMotor.brake();
117 break;
118 }
119
120 LadyBrownMotor.move_voltage(motor_voltage);
122 pros::delay(20);
123 }
124 }
125}
static LADYBROWN_STATE current_state
Definition ladybrown.h:25

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

Referenced by Robot::Autonomous::BluePos(), Robot::Autonomous::RedPos(), run(), and Robot::Autonomous::Skills().

◆ run()

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

Definition at line 20 of file ladybrown.cpp.

20 {
21 LADYBROWN_STATE move_to;
22
23 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_R2)) {
25 move_to = LOAD_STATE;
26 } else if (current_state == LOAD_STATE) {
27 move_to = ATTACK_STATE;
28 } else {
29 move_to = BASE_STATE;
30 }
31 std::cout << "Moving to: " << move_to << std::endl;
32 std::cout << "current state: " << current_state << std::endl;
33
34 if (!async) {
35 MoveToPoint(move_to);
36 } else {
37
38 pros::Task move([move_to, this]() { MoveToPoint(move_to); });
39 }
40
41 if (!isPIDRunning) {
42 current_state = move_to;
43 }
44
45 } else if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_L2)) {
46
48 move_to = LOAD_STATE;
49 } else if (current_state == LOAD_STATE) {
50 move_to = BASE_STATE;
51 } else {
52 return;
53 }
54
55 std::cout << "Moving to: " << move_to << std::endl;
56 std::cout << "current state: " << current_state << std::endl;
57
58 if (!async) {
59 MoveToPoint(move_to);
60 } else {
61 pros::Task move([move_to, this]() { MoveToPoint(move_to); }, "LadyBrownMove");
62 }
63
64 if (!isPIDRunning) {
65 current_state = move_to;
66 }
67 }
68}
void MoveToPoint(LadyBrown::LADYBROWN_STATE state, int max_error=150, int timeout=1000)
Definition ladybrown.cpp:72
pros::Controller controller(pros::E_CONTROLLER_MASTER)

References ATTACK_STATE, BASE_STATE, Robot::Globals::controller(), current_state, isPIDRunning, LOAD_STATE, and MoveToPoint().

Member Data Documentation

◆ current_state

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

Definition at line 25 of file ladybrown.h.

Referenced by MoveToPoint(), and run().

◆ isPIDRunning

bool Robot::LadyBrown::isPIDRunning
private

Definition at line 29 of file ladybrown.h.

Referenced by MoveToPoint(), 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 27 of file ladybrown.h.

Referenced by get_target(), and MoveToPoint().


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