1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "main.h"
2#include "electronic/controller.h"
3#include "electronic/distance.h"
4#include "globals.h"
5#include "lemlib/chassis/chassis.hpp"
6#include "liblvgl/llemu.hpp"
7#include "pros/misc.h"
8#include "pros/misc.hpp"
9#include "pros/motors.hpp"
10#include "pros/rtos.hpp"
11#include "robot/auton.h"
12#include "robot/drivetrain.h"
13#include "robot/ladybrown.h"
14#include "screen/selector.h"
15#include "screen/status.h"
16#include <string>
17#include <cmath>
18
19using namespace Robot;
20using namespace Robot::Globals;
21/*
22 ____ .____________ ____________ ___
23/_ || ____/_ |/ _____/\ \/ /
24 | ||____ \ | / __ \ \ /
25 | |/ \| \ |__\ \ / \
26 |___/______ /|___|\_____ //___/\ \
27 \/ \/ \_/
28
29*/
30
35
47
49 Robot::selector_screen selector;
50 Robot::status_screen status;
52
54 Robot::Controller controllers;
55 Robot::DistanceSensor distance_sensor;
57
64
65void initialize() {
66 chassis.calibrate();
67
68 chassis.setPose(0, 0, 0);
69 pros::rtos::Task MotorNotification(electronic.controllers.notify_motor_disconnect);
70
71 pros::lcd::initialize();
72 pros::Task screen_task([&]() {
73 while (true) {
74 // print robot location to the brain screen
75 pros::lcd::print(0, "X: %f", chassis.getPose().x); // x
76 pros::lcd::print(1, "Y: %f", chassis.getPose().y); // y
77 pros::lcd::print(2, "Theta: %f", chassis.getPose().theta); // heading
78 // delay to save resources
79 pros::lcd::print(3, "Lateral Sensor: %i", lateral_sensor.get_position());
80 pros::lcd::print(4, "Horizontal Sensor: %i", horizontal_sensor.get_position());
81 pros::lcd::print(5, "Lady Brown Sensor: %i", LadyBrownRotation.get_position());
82 pros::lcd::print(6, "Autonomous: %s", subsystem.autonomous.autonName);
83 pros::lcd::print(7, "Distance Position: %i", distance_sensor.get_distance());
84
85 pros::delay(20);
86 }
87 });
88
89 //@TODO: Put the following into a seperate class.
90 // pros::Task screen_task([&]() {
91 // lv_obj_t *chart = lv_chart_create(lv_scr_act());
92 // lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
93 // lv_chart_set_point_count(chart, 460);
94 // lv_obj_set_size(chart, 460, 220);
95 // lv_obj_center(chart);
96 // lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, -15250, -14750);
97 // lv_chart_set_zoom_y(chart, 600);
98 // lv_chart_set_zoom_x(chart, 1000);
99 // lv_obj_set_style_size(chart, 0, LV_PART_INDICATOR);
100 // lv_chart_series_t *s1 = lv_chart_add_series(chart, lv_color_white(), LV_CHART_AXIS_PRIMARY_Y);
101 // lv_chart_series_t *s2 = lv_chart_add_series(chart, lv_color_hex(0xFFFF0000), LV_CHART_AXIS_SECONDARY_X);
102
103 // lv_obj_t * label = lv_label_create(lv_scr_act());
104 // lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xffffff), LV_PART_MAIN);
105 // lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
106 // lv_obj_set_style_text_font(label, &lv_font_montserrat_20, 0);
107
108 // while (true) {
109 // lv_chart_set_next_value(chart, s1, subsystem.ladybrown.get_target());
110 // lv_chart_set_next_value(chart, s2, LadyBrownRotation.get_position());
111 // if (pros::millis() >= 5000) {
112 // std::string angle = std::to_string(LadyBrownRotation.get_position());
113 // lv_label_set_text(label, angle.c_str());
114 // break;
115 // }
116 // pros::delay(10);
117 // }
118 // });
119
120 pros::rtos::Task Task(electronic.controllers.notify_motor_disconnect);
121}
122
128
129void disabled() {}
130
141 screen.selector.selector();
142
143}
144
156
159 subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch, subsystem.sweeper, electronic.distance_sensor,
160 subsystem.ladybrown);
161}
162
176void opcontrol() {
177
178 while (true) {
179
180 // Calls to event handling functions.
181 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_UP)) {
182 autonomous();
183 }
184 // Toggles the drivetrain orientation - can be forward or backward
185 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_RIGHT)) {
186 std::string name = subsystem.drivetrain.toggleDrive();
187 // Output the current drive mode to the controller screen
188 controller.print(0, 0, name.c_str());
189 }
190 // Checks for drivetrain reversal - Changes conditions in a value handler function in the drivetrain class
191 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_DOWN)) {
192 // isReversed is static, it is changed for the global state.
194
195 // Output the current drive mode to the controller screen
196 controller.print(0, 0, "reversal: %d", Drivetrain::isReversed);
197 }
198
199 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) {
200 pros::Task move([&]() { subsystem.ladybrown.MoveToPoint(LadyBrown::ATTACK_STATE); }, "LadyBrownMove");
201 }
202
203 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_X)) {
204 IntakeMotor.move_velocity(600);
205 }
206
207
208
209 subsystem.drivetrain.run();
210 subsystem.latch.run();
211 subsystem.sweeper.run();
212 subsystem.ladybrown.run();
213
214 // Intake controller - uses R1 to pull in and L1 to push out, and stops if nothing pressed
215 subsystem.intake.run();
216
217 // Handles partner controller keypresses to rumble the primary controller
218 electronic.controllers.notifier();
219
220 // DOES NOT SWITCH CONTROL - Checks for a key press to trigger controller switch
221 electronic.controllers.switchControl();
222
223 pros::delay(10); // Small delay to reduce CPU usage
224 }
225}
The Autonomous class contains classes and functions related to the robot's autonomous behavior.
Definition auton.h:16
static AUTON_ROUTINE auton
Sets the number of the autonomous program to use.
Definition auton.h:28
Represents the drivetrain of the robot.
Definition drivetrain.h:26
static bool isReversed
Definition drivetrain.h:82
The Intake class represents a robot intake system.
Definition intake.h:8
The LadyBrown class represents the robot lady brown subsystem.
Definition ladybrown.h:9
The Latch class represents a latching mechanism.
Definition latch.h:8
The Latch class represents a latching mechanism.
Definition sweeper.h:8
Contains the declaration of the Drivetrain class.
void initialize()
Definition main.cpp:65
struct RobotSubsystems subsystem
void autonomous()
Definition main.cpp:157
void disabled()
Definition main.cpp:129
void competition_initialize()
Definition main.cpp:140
struct Electronics electronic
struct RobotScreen screen
void opcontrol()
Definition main.cpp:176
pros::Motor IntakeMotor(-9, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees)
lemlib::TrackingWheel horizontal_tracking_wheel & horizontal_sensor
Definition globals.cpp:65
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::Rotation LadyBrownRotation(8)
lemlib::TrackingWheel vertical_tracking_wheel & lateral_sensor
Definition globals.cpp:66
pros::Controller controller(pros::E_CONTROLLER_MASTER)
pros::Distance distance_sensor(10)
Definition auton.h:10
Robot::Controller controllers
Definition main.cpp:54
Robot::DistanceSensor distance_sensor
Definition main.cpp:55
Robot::status_screen status
Definition main.cpp:50
Robot::selector_screen selector
Definition main.cpp:49
Structure that holds instances of all robot subsystems.
Definition main.cpp:39
Robot::Intake intake
Definition main.cpp:42
Robot::Autonomous autonomous
Definition main.cpp:40
Robot::Sweeper sweeper
Definition main.cpp:45
Robot::Drivetrain drivetrain
Definition main.cpp:41
Robot::Latch latch
Definition main.cpp:43
Robot::LadyBrown ladybrown
Definition main.cpp:44