1516b Over Under 2.0
Codebase for 1516b over under season
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "main.h"
2#include <ostream>
3
4#include "api.h"
5#include "pros/apix.h"
6#include "pros/serial.h"
7
8using namespace Robot;
9using namespace Robot::Globals;
10/*
11 ( ( ( ( (
12 )\ (() )\ )\ (_)
13 ((_) ((_) ((_) ((_) (_))
14 (/ | | __| (/ | (/ / | |()
15 | | |__ \ | | / _ \ | _ \
16 |_| |___/ |_| \___/ |____/
17
18*/
19
20
21/**
22 * @file main.cpp
23 * @brief This file contains the main code for the robot's operation.
24 */
25
26
27namespace Robot {
28/**
29 * @brief Structure that holds instances of all robot subsystems.
30 */
37} subsystem;
38}
39
40/**
41 * A callback function for LLEMU's center button.
42 *
43 * When this callback is fired, it will toggle line 2 of the LCD text between
44 * "I was pressed!" and nothing.
45 */
46
47
48void toggles() {
50}
51/**
52 * Runs initialization code. This occurs as soon as the program is started.
53 *
54 * All other competition modes are blocked by initialize; it is recommended
55 * to keep execution time for this mode under a few seconds.
56 */
57
58
59void initialize() {
60
61 pros::lcd::initialize();
62 pros::Task toggler(toggles);
63
64 if (pros::c::registry_get_plugged_type(13) == pros::c::E_DEVICE_IMU) {
65 chassis.calibrate();
66 chassis.setPose(0, 0, 90); // X: 0, Y: 0, Heading: 0
67 // Setting an example start location for the robot so it is all relatativistic
68 pros::Task screenTask(Robot::Utility::displayLocation);
69 }
70 else {
71 pros::Task screenTask(Robot::Utility::displayMotorVel);
72 }
73
74}
75
76/**
77 * Runs while the robot is in the disabled state of Field Management System or
78 * the VEX Competition Switch, following either autonomous or opcontrol. When
79 * the robot is enabled, this task will exit.
80 */
81
82
83
84void disabled() {}
85
86/**
87 * Runs after initialize(), and before autonomous when connected to the Field
88 * Management System or the VEX Competition Switch. This is intended for
89 * competition-specific initialization routines, such as an autonomous selector
90 * on the LCD.
91 *
92 * This task will exit when the robot is enabled and autonomous or opcontrol
93 * starts.<asd></asd>
94 */
96 // Allows the user to select the autonomous routine, drive control type as well as whether the distance puncher is enabled.
97 // The user can select the auton routine by pressing the right buttons on the controller.
98 // The user can select the drive control type by pressing the down button on the controller.
99 // The user can select the distance puncher by pressing the left button on the controller.
100 // The state of each subsystem is displayed on the controller screen.
101
102
103}
104
105
106
107
108
109
110/**
111 * Runs the user autonomous code. This function will be started in its own task
112 * with the default priority and stack size whenever the robot is enabled via
113 * the Field Management System or the VEX Competition Switch in the autonomous
114 * mode. Alternatively, this function may be called in initialize or opcontrol
115 * for non-competition testing purposes.
116 *
117 * If the robot is disabled or communications is lost, the autonomous task
118 * will be stopped. Re-enabling the robot will restart the task, not re-start it
119 * from where it left off.
120 */
122
123 subsystem.autonomous.AutoDrive(subsystem.puncher, true);
124
125
126
127}
128
129
130
131/**
132 * Runs the operator control code. This function will be started in its own task
133 * with the default priority and stack size whenever the robot is enabled via
134 * the Field Management System or the VEX Competition Switch in the operator
135 * control mode.
136 *
137 * If no competition control is connected, this function will run immediately
138 * following initialize().
139 *
140 * If the robot is disabled or communications is lost, the
141 * operator control task will be stopped. Re-enabling the robot will restart the
142 * task, not resume it from where it left off.
143 */
144void opcontrol() {
145
146
147 while (true) {
148 subsystem.drivetrain.run();
149
150
151
152 subsystem.puncher.run(0);
153
154
155
156
157 // Catapult controller, uses the X button holded down to push the elevation up.
158 subsystem.intake.run();
159
160 // Intake controller, moves the left and right intakes and stops them if nothing is pressed.
161
162
163 subsystem.wings.run();
164
165
166
167
168
169
170
171
172 pros::delay(2); // Small delay to reduce CPU usage
173 }
174
175
176}
The Autonomous class contains classes and functions related to the robot's autonomous behavior.
Definition auton.h:11
void AutoDrive(Puncher &puncher, bool autono)
Drives the robot autonomously.
Definition auton.cpp:60
Represents the drivetrain of the robot.
Definition drivetrain.h:23
void run()
Runs the drivetrain.
The Intake class represents a robot intake system.
Definition intake.h:8
void run()
Runs the main function of the intake system.
Definition intake.cpp:7
Represents a Puncher mechanism for a robot.
Definition puncher.h:12
void run(int autonVal)
Runs the puncher based on the given autonomous value.
Definition puncher.cpp:15
The Wings class represents the wings of a robot.
Definition wings.h:11
void run()
Runs the wings.
Definition wings.cpp:7
void initialize()
Definition main.cpp:59
void autonomous()
Definition main.cpp:121
void disabled()
Definition main.cpp:84
void competition_initialize()
Definition main.cpp:95
void opcontrol()
Definition main.cpp:144
void toggles()
Definition main.cpp:48
Contains global variables and type definitions for the Robot namespace.
Definition globals.cpp:18
lemlib::Chassis chassis
Contains utility functions for controlling the screen and toggling subsystems.
Definition utility.h:13
void displayLocation()
Displays current position of the robot.
Definition utility.cpp:42
void toggleSubsystemOptions(Autonomous &auton, Drivetrain &drive, Puncher &punch)
Toggles subsystems, drive mode auton routine, and puncher.
Definition utility.cpp:10
void displayMotorVel()
Displays current velocity of the robot.
Definition utility.cpp:28
Contains all objects generated by the 1516B team - Contains all of the subsystems,...
Definition globals.cpp:17
Structure that holds instances of all robot subsystems.
Definition main.cpp:31
Robot::Puncher puncher
Definition main.cpp:35
Robot::Drivetrain drivetrain
Definition main.cpp:33
Robot::Autonomous autonomous
Definition main.cpp:32
Robot::Wings wings
Definition main.cpp:34
Robot::Intake intake
Definition main.cpp:36