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
10
using namespace
Robot
;
11
using namespace
Robot::Globals
;
12
/*
13
____ .____________ ____________ ___
14
/_ || ____/_ |/ _____/\ \/ /
15
| ||____ \ | / __ \ \ /
16
| |/ \| \ |__\ \ / \
17
|___/______ /|___|\_____ //___/\ \
18
\/ \/ \_/
19
20
*/
21
26
30
struct
RobotSubsystems
{
31
Robot::Autonomous
autonomous
;
32
Robot::Drivetrain
drivetrain
;
33
Robot::Intake
intake
;
34
Robot::Latch
latch
;
35
Robot::LadyBrown
ladybrown
;
36
Robot::Hang
hang
;
37
Robot::Sweeper
sweeper
;
38
}
subsystem
;
39
40
struct
RobotScreen
{
41
Robot::selector_screen
selector
;
42
Robot::status_screen
status
;
43
}
screen
;
44
45
struct
Electronics
{
46
Robot::Controller
controllers
;
47
Robot::DistanceSensor
distance_sensor
;
48
}
electronic
;
49
56
57
void
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
86
void
disabled
() {}
87
97
void
competition_initialize
() {}
98
110
111
void
autonomous
() {
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
143
void
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.
160
Drivetrain::isReversed
= !
Drivetrain::isReversed
;
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
}
Robot::Autonomous
The Autonomous class contains classes and functions related to the robot's autonomous behavior.
Definition
auton.h:14
Robot::Drivetrain
Represents the drivetrain of the robot.
Definition
drivetrain.h:26
Robot::Drivetrain::isReversed
static bool isReversed
Definition
drivetrain.h:82
Robot::Hang
The Hang class represents a Hanging mechanism.
Definition
hang.h:8
Robot::Intake
The Intake class represents a robot intake system.
Definition
intake.h:8
Robot::LadyBrown
The Intake class represents a robot intake system.
Definition
ladybrown.h:8
Robot::Latch
The Latch class represents a latching mechanism.
Definition
latch.h:8
Robot::Sweeper
The Latch class represents a latching mechanism.
Definition
sweeper.h:8
drivetrain.h
Contains the declaration of the Drivetrain class.
ladybrown.h
initialize
void initialize()
Definition
main.cpp:57
subsystem
struct RobotSubsystems subsystem
autonomous
void autonomous()
Definition
main.cpp:111
disabled
void disabled()
Definition
main.cpp:86
competition_initialize
void competition_initialize()
Definition
main.cpp:97
electronic
struct Electronics electronic
screen
struct RobotScreen screen
opcontrol
void opcontrol()
Definition
main.cpp:143
Robot::Globals
Definition
globals.cpp:20
Robot::Globals::horizontal_sensor
lemlib::TrackingWheel horizontal_tracking_wheel & horizontal_sensor
Definition
globals.cpp:64
Robot::Globals::chassis
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
Robot::Globals::lateral_sensor
lemlib::TrackingWheel vertical_tracking_wheel & lateral_sensor
Definition
globals.cpp:65
Robot::Globals::controller
pros::Controller controller(pros::E_CONTROLLER_MASTER)
Robot
Definition
auton.h:8
Electronics
Definition
main.cpp:45
Electronics::controllers
Robot::Controller controllers
Definition
main.cpp:46
Electronics::distance_sensor
Robot::DistanceSensor distance_sensor
Definition
main.cpp:47
RobotScreen
Definition
main.cpp:40
RobotScreen::status
Robot::status_screen status
Definition
main.cpp:42
RobotScreen::selector
Robot::selector_screen selector
Definition
main.cpp:41
RobotSubsystems
Structure that holds instances of all robot subsystems.
Definition
main.cpp:30
RobotSubsystems::intake
Robot::Intake intake
Definition
main.cpp:33
RobotSubsystems::autonomous
Robot::Autonomous autonomous
Definition
main.cpp:31
RobotSubsystems::hang
Robot::Hang hang
Definition
main.cpp:36
RobotSubsystems::sweeper
Robot::Sweeper sweeper
Definition
main.cpp:37
RobotSubsystems::drivetrain
Robot::Drivetrain drivetrain
Definition
main.cpp:32
RobotSubsystems::latch
Robot::Latch latch
Definition
main.cpp:34
RobotSubsystems::ladybrown
Robot::LadyBrown ladybrown
Definition
main.cpp:35
src
main.cpp
Generated on Sat Jan 11 2025 13:28:26 for 1516X High Stakes by
1.13.1