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 "globals.h"
4#include "pros/misc.h"
5#include "robot/drivetrain.h"
6#include "robot/ladybrown.h"
7#include "screen/selector.h"
8#include "screen/status.h"
9
10using namespace Robot;
11using namespace Robot::Globals;
12/*
13 ____ .____________ ____________ ___
14/_ || ____/_ |/ _____/\ \/ /
15 | ||____ \ | / __ \ \ /
16 | |/ \| \ |__\ \ / \
17 |___/______ /|___|\_____ //___/\ \
18 \/ \/ \_/
19
20*/
21
26
39
41 Robot::selector_screen selector;
42 Robot::status_screen status;
44
46 Robot::Controller controllers;
47 Robot::DistanceSensor distance_sensor;
49
56
57void initialize() {
58 chassis.calibrate();
59
60 chassis.setPose(0, 0, 0);
61 pros::rtos::Task MotorNotification(electronic.controllers.notify_motor_disconnect);
62
63 // pros::rtos::Task LadyBrownNotification(subsystem.ladybrown.edge_check);
64 // screen.selector.selector();
65 pros::lcd::initialize();
66 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 }
77 });
78}
79
85
86void disabled() {}
87
98
110
112
113 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 // });
126
127 subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch, electronic.distance_sensor);
128}
129
143void opcontrol() {
144
145 while (true) {
146
147 // Calls to event handling functions.
148 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_DOWN)) {
149 autonomous();
150 }
151 // Toggles the drivetrain orientation - can be forward or backward
152 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_UP)) {
153 std::string name = subsystem.drivetrain.toggleDrive();
154 // Output the current drive mode to the controller screen
155 controller.print(0, 0, name.c_str());
156 }
157 // Checks for drivetrain reversal - Changes conditions in a value handler function in the drivetrain class
158 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_RIGHT)) {
159 // isReversed is static, it is changed for the global state.
161
162 // Output the current drive mode to the controller screen
163 controller.print(0, 0, "reversal: %d", Drivetrain::isReversed);
164 }
165
166 subsystem.drivetrain.run();
167 subsystem.latch.run();
168 subsystem.sweeper.run();
169 subsystem.hang.run();
170 subsystem.ladybrown.run();
171
172 // Intake controller - uses R1 to pull in and L1 to push out, and stops if nothing pressed
173 subsystem.intake.run();
174
175 // Handles partner controller keypresses to rumble the primary controller
176 electronic.controllers.notifier();
177
178 // DOES NOT SWITCH CONTROL - Checks for a key press to trigger controller switch
179 electronic.controllers.switchControl();
180
181 pros::delay(10); // Small delay to reduce CPU usage
182 }
183}
The Autonomous class contains classes and functions related to the robot's autonomous behavior.
Definition auton.h:14
Represents the drivetrain of the robot.
Definition drivetrain.h:26
static bool isReversed
Definition drivetrain.h:82
The Hang class represents a Hanging mechanism.
Definition hang.h:8
The Intake class represents a robot intake system.
Definition intake.h:8
The Intake class represents a robot intake system.
Definition ladybrown.h:8
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:57
struct RobotSubsystems subsystem
void autonomous()
Definition main.cpp:111
void disabled()
Definition main.cpp:86
void competition_initialize()
Definition main.cpp:97
struct Electronics electronic
struct RobotScreen screen
void opcontrol()
Definition main.cpp:143
lemlib::TrackingWheel horizontal_tracking_wheel & horizontal_sensor
Definition globals.cpp:64
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
lemlib::TrackingWheel vertical_tracking_wheel & lateral_sensor
Definition globals.cpp:65
pros::Controller controller(pros::E_CONTROLLER_MASTER)
Definition auton.h:8
Robot::Controller controllers
Definition main.cpp:46
Robot::DistanceSensor distance_sensor
Definition main.cpp:47
Robot::status_screen status
Definition main.cpp:42
Robot::selector_screen selector
Definition main.cpp:41
Structure that holds instances of all robot subsystems.
Definition main.cpp:30
Robot::Intake intake
Definition main.cpp:33
Robot::Autonomous autonomous
Definition main.cpp:31
Robot::Hang hang
Definition main.cpp:36
Robot::Sweeper sweeper
Definition main.cpp:37
Robot::Drivetrain drivetrain
Definition main.cpp:32
Robot::Latch latch
Definition main.cpp:34
Robot::LadyBrown ladybrown
Definition main.cpp:35