Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 5e0f51b

Browse files
authored
Merge pull request #68 from calhighrobotics/feature/issue-49/lady-brown
feature/issue 49/lady brown
2 parents acfd590 + 094515e commit 5e0f51b

File tree

7 files changed

+182
-114
lines changed

7 files changed

+182
-114
lines changed

include/globals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "api.h"
44
#include "lemlib/api.hpp"
55
#include "pros/vision.hpp"
6+
#include "robot/ladybrown.h"
67

78
// The following files are imported in order to provide type definitions into
89
// the compiler that allows for the objecys to
@@ -71,6 +72,9 @@ extern pros::vision_signature_s_t BLUE_DARK_SIG;
7172
extern pros::Distance distance_sensor;
7273
extern pros::Rotation lateral_sensor;
7374
extern pros::Rotation horizontal_sensor;
75+
76+
extern pros::Rotation LadyBrownRotation;
77+
7478
// forward/backward PID
7579
extern lemlib::ControllerSettings lateral_controller;
7680

include/robot/auton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22
#include <string>
33

4+
#include "electronic/distance.h"
45
#include "robot/intake.h"
56
#include "robot/latch.h"
6-
#include "electronic/distance.h"
77

88
namespace Robot {
99
/**

include/robot/ladybrown.h

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
11
#pragma once
22

3+
#include "lemlib/pid.hpp"
34
namespace Robot {
45

56
/**
6-
* @brief The Intake class represents a robot intake system.
7+
* @brief The LadyBrown class represents the robot lady brown subsystem.
78
*/
89
class LadyBrown {
910
public:
10-
/**
11-
* @brief Runs the main function of the intake system.
12-
*
13-
* Takes optional user input to control the direction of the intake system in
14-
* autonomous.
15-
*/
16-
void run();
11+
// The ENUM associates with each location of the rotation sensor for the LadyBrown to move.
12+
enum LADYBROWN_STATE { BASE_STATE = 1, LOAD_STATE = 2, ATTACK_STATE = 3};
1713

18-
static void edge_check(void *param);
14+
void run(bool async = true, int timeout = 1000);
1915

20-
static bool needs_warning;
21-
22-
/**
23-
* @brief Checks whether the intake should stop to skip the ring depending on color.
24-
* It is the embodiment of vision sensor usage in this codebase.
25-
*/
26-
void checkStop();
16+
void MoveToPoint(LadyBrown::LADYBROWN_STATE state, int max_error = 200, int timeout = 1000);
2717

2818
LadyBrown();
2919

30-
LadyBrown(double kP, double kI, double kD);
20+
int get_target();
21+
22+
private:
23+
lemlib::PID MoveToPointPID;
3124

32-
double pid_update();
25+
static LADYBROWN_STATE current_state;
3326

34-
/**
35-
* @brief Toggles intake elevation.
36-
*/
37-
void toggle();
27+
int target;
3828

39-
private:
40-
double kP;
41-
double kI;
42-
double kD;
43-
44-
/**
45-
* @brief blue is false, red is true.
46-
*/
47-
bool alliance_color;
29+
bool isPIDRunning;
30+
4831
};
4932
} // namespace Robot

src/electronics/distance.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
#include "electronic/distance.h"
12
#include "globals.h"
23
#include "pros/misc.h"
3-
#include "electronic/distance.h"
44

55
using namespace Robot;
66
using namespace Robot::Globals;
77

8-
98
DistanceSensor::DistanceSensor() { ; }
109

11-
int DistanceSensor::get_distance() {
12-
return distance_sensor.get();
13-
}
10+
int DistanceSensor::get_distance() { return distance_sensor.get(); }

src/globals.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ pros::Motor LeftMid(20, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degree
3030
pros::Motor RightMid(-11, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
3131
pros::Motor IntakeMotor(-1, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
3232
pros::Motor HookMotor(-2, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
33-
pros::Motor LadyBrownMotor(3, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
33+
pros::Motor LadyBrownMotor(-3, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
3434

3535
pros::adi::Pneumatics LatchControl('A', false);
3636
pros::adi::Pneumatics HangControl('C', false);
3737
pros::adi::Pneumatics SweeperControl('B', false);
3838

39-
4039
pros::Distance distance_sensor(10);
4140
pros::Rotation lateral_sensor(16);
4241
pros::Rotation horizontal_sensor(17);
4342

43+
pros::Rotation LadyBrownRotation(8);
44+
4445
pros::Imu inertial_sensor(14);
4546

4647
// Vision sensor configuration
@@ -123,4 +124,4 @@ lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sens
123124

124125
} // namespace Globals
125126

126-
} // namespace Robot
127+
} // namespace Robot

src/main.cpp

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,52 @@ void initialize() {
6464
// screen.selector.selector();
6565
pros::lcd::initialize();
6666
pros::Task screen_task([&]() {
67-
while (true) {
68-
// print robot location to the brain screen
69-
pros::lcd::print(0, "X: %f", chassis.getPose().x); // x
70-
pros::lcd::print(1, "Y: %f", chassis.getPose().y); // y
71-
pros::lcd::print(2, "Theta: %f", chassis.getPose().theta); // heading
72-
// delay to save resources
73-
pros::lcd::print(3, "Rotation Sensor: %i", lateral_sensor.get_position());
74-
pros::lcd::print(4, "Rotation Sensor: %i", horizontal_sensor.get_position());
75-
pros::delay(20);
76-
}
67+
while (true) {
68+
// print robot location to the brain screen
69+
pros::lcd::print(0, "X: %f", chassis.getPose().x); // x
70+
pros::lcd::print(1, "Y: %f", chassis.getPose().y); // y
71+
pros::lcd::print(2, "Theta: %f", chassis.getPose().theta); // heading
72+
// delay to save resources
73+
pros::lcd::print(3, "Lateral Sensor: %i", lateral_sensor.get_position());
74+
pros::lcd::print(4, "Horizontal Sensor: %i", horizontal_sensor.get_position());
75+
pros::lcd::print(5, "Lady Brown Sensor: %i", LadyBrownRotation.get_position());
76+
pros::lcd::print(6, "Lady Brown Target: %i", subsystem.ladybrown.get_target());
77+
78+
79+
pros::delay(20);
80+
}
7781
});
82+
// pros::Task screen_task([&]() {
83+
// lv_obj_t *chart = lv_chart_create(lv_scr_act());
84+
// lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
85+
// lv_chart_set_point_count(chart, 460);
86+
// lv_obj_set_size(chart, 460, 220);
87+
// lv_obj_center(chart);
88+
// lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, -15250, -14750);
89+
// lv_chart_set_zoom_y(chart, 600);
90+
// lv_chart_set_zoom_x(chart, 1000);
91+
// lv_obj_set_style_size(chart, 0, LV_PART_INDICATOR);
92+
// lv_chart_series_t *s1 = lv_chart_add_series(chart, lv_color_white(), LV_CHART_AXIS_PRIMARY_Y);
93+
// lv_chart_series_t *s2 = lv_chart_add_series(chart, lv_color_hex(0xFFFF0000), LV_CHART_AXIS_SECONDARY_X);
94+
95+
// lv_obj_t * label = lv_label_create(lv_scr_act());
96+
// lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xffffff), LV_PART_MAIN);
97+
// lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
98+
// lv_obj_set_style_text_font(label, &lv_font_montserrat_20, 0);
99+
100+
// while (true) {
101+
// lv_chart_set_next_value(chart, s1, subsystem.ladybrown.get_target());
102+
// lv_chart_set_next_value(chart, s2, LadyBrownRotation.get_position());
103+
// if (pros::millis() >= 5000) {
104+
// std::string angle = std::to_string(LadyBrownRotation.get_position());
105+
// lv_label_set_text(label, angle.c_str());
106+
// break;
107+
// }
108+
// pros::delay(10);
109+
// }
110+
// });
111+
112+
pros::rtos::Task Task(electronic.controllers.notify_motor_disconnect);
78113
}
79114

80115
/**
@@ -111,18 +146,6 @@ void competition_initialize() {}
111146
void autonomous() {
112147

113148
pros::lcd::initialize();
114-
// pros::Task screen_task([&]() {
115-
// while (true) {
116-
// // print robot location to the brain screen
117-
// pros::lcd::print(0, "X: %f", chassis.getPose().x); // x
118-
// pros::lcd::print(1, "Y: %f", chassis.getPose().y); // y
119-
// pros::lcd::print(2, "Theta: %f", chassis.getPose().theta); // heading
120-
// // delay to save resources
121-
// pros::lcd::print(3, "Rotation Sensor: %i", lateral_sensor.get_position());
122-
// pros::lcd::print(4, "Rotation Sensor: %i", horizontal_sensor.get_position());
123-
// pros::delay(20);
124-
// }
125-
// });
126149

127150
subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch, electronic.distance_sensor);
128151
}
@@ -146,7 +169,8 @@ void opcontrol() {
146169

147170
// Calls to event handling functions.
148171
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_DOWN)) {
149-
autonomous();
172+
// autonomous();
173+
subsystem.ladybrown.MoveToPoint(LadyBrown::ATTACK_STATE);
150174
}
151175
// Toggles the drivetrain orientation - can be forward or backward
152176
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_UP)) {

0 commit comments

Comments
 (0)