1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
main.cpp File Reference

This file contains the main code for the robot's operation. More...

#include "main.h"
#include "electronic/controller.h"
#include "globals.h"
#include "pros/misc.h"
#include "robot/drivetrain.h"
#include "robot/ladybrown.h"
#include "screen/selector.h"
#include "screen/status.h"

Go to the source code of this file.

Classes

struct  RobotSubsystems
 Structure that holds instances of all robot subsystems. More...
 
struct  RobotScreen
 
struct  Electronics
 

Functions

void initialize ()
 
void disabled ()
 
void competition_initialize ()
 
void autonomous ()
 
void opcontrol ()
 

Variables

struct RobotSubsystems subsystem
 
struct RobotScreen screen
 
struct Electronics electronic
 

Detailed Description

This file contains the main code for the robot's operation.

Definition in file main.cpp.

Function Documentation

◆ autonomous()

void autonomous ( )

6 Runs the user autonomous code. This function will be started in its own task with the default priority and stack size whenever the robot is enabled via the Field Management System or the VEX Competition Switch in the autonomous mode. Alternatively, this function may be called in initialize or opcontrol for non-competition testing purposes.

If the robot is disabled or communications is lost, the autonomous task will be stopped. Re-enabling the robot will restart the task, not re-start it from where it left off.

Definition at line 111 of file main.cpp.

111 {
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}
struct RobotSubsystems subsystem
struct Electronics electronic

References electronic, and subsystem.

Referenced by opcontrol().

◆ competition_initialize()

void competition_initialize ( )

Runs after initialize(), and before autonomous when connected to the Field Management System or the VEX Competition Switch. This is intended for competition-specific initialization routines, such as an autonomous selector on the LCD.

This task will exit when the robot is enabled and autonomous or opcontrol starts.<asd></asd>

Definition at line 97 of file main.cpp.

97{}

◆ disabled()

void disabled ( )

Runs while the robot is in the disabled state of Field Management System or the VEX Competition Switch, following either autonomous or opcontrol. When the robot is enabled, this task will exit.

Definition at line 86 of file main.cpp.

86{}

◆ initialize()

void initialize ( )

Runs initialization code. This occurs as soon as the program is started.

All other competition modes are blocked by initialize; it is recommended to keep execution time for this mode under a few seconds.

Definition at line 57 of file main.cpp.

57 {
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}
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

References Robot::Globals::chassis(), electronic, Robot::Globals::horizontal_sensor, and Robot::Globals::lateral_sensor.

◆ opcontrol()

void opcontrol ( )

Runs the operator control code. This function will be started in its own task with the default priority and stack size whenever the robot is enabled via the Field Management System or the VEX Competition Switch in the operator control mode.

If no competition control is connected, this function will run immediately following initialize().

If the robot is disabled or communications is lost, the operator control task will be stopped. Re-enabling the robot will restart the task, not resume it from where it left off.

Definition at line 143 of file main.cpp.

143 {
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}
static bool isReversed
Definition drivetrain.h:82
void autonomous()
Definition main.cpp:111
pros::Controller controller(pros::E_CONTROLLER_MASTER)

References autonomous(), Robot::Globals::controller(), electronic, Robot::Drivetrain::isReversed, and subsystem.

Variable Documentation

◆ electronic

struct Electronics electronic

Referenced by autonomous(), initialize(), and opcontrol().

◆ screen

struct RobotScreen screen

◆ subsystem

struct RobotSubsystems subsystem

Referenced by autonomous(), and opcontrol().