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 "electronic/distance.h"
#include "globals.h"
#include "lemlib/chassis/chassis.hpp"
#include "liblvgl/llemu.hpp"
#include "pros/misc.h"
#include "pros/misc.hpp"
#include "pros/motors.hpp"
#include "pros/rtos.hpp"
#include "robot/auton.h"
#include "robot/drivetrain.h"
#include "robot/ladybrown.h"
#include "screen/selector.h"
#include "screen/status.h"
#include <string>
#include <cmath>

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 157 of file main.cpp.

157 {
159 subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch, subsystem.sweeper, electronic.distance_sensor,
160 subsystem.ladybrown);
161}
static AUTON_ROUTINE auton
Sets the number of the autonomous program to use.
Definition auton.h:28
struct RobotSubsystems subsystem
struct Electronics electronic

References Robot::Autonomous::auton, Robot::Autonomous::BLUE_POS_LATE_RUSH, 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 140 of file main.cpp.

140 {
141 screen.selector.selector();
142
143}
struct RobotScreen screen

References screen.

◆ 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 129 of file main.cpp.

129{}

◆ 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 65 of file main.cpp.

65 {
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}
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::Distance distance_sensor(10)

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

◆ 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 176 of file main.cpp.

176 {
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}
static bool isReversed
Definition drivetrain.h:82
void autonomous()
Definition main.cpp:157
pros::Motor IntakeMotor(-9, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees)
pros::Controller controller(pros::E_CONTROLLER_MASTER)

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

Variable Documentation

◆ electronic

struct Electronics electronic

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

◆ screen

struct RobotScreen screen

Referenced by competition_initialize().

◆ subsystem

struct RobotSubsystems subsystem

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