1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
main.cpp File Reference
#include "main.h"
#include "globals.h"
#include "liblvgl/core/lv_obj_pos.h"
#include "pros/misc.h"
#include "auton/autonRoutines.h"
#include "auton/autonFunctions.h"
#include "robodash/views/selector.hpp"
#include "distanceReset.h"
#include "colorSort.h"
#include "warnings.h"
#include <string>
#include "MCL.h"
#include "visionAlignment.h"
#include "ramsete.h"

Go to the source code of this file.

Functions

void alliance_btn_event_handler (lv_event_t *e)
 
void create_alliance_selector ()
 
rd::Selector selector ({ {"Right", right_auton}, {"Left", left_auton}, {"Carry", carry_auton}, {"Elim", elim_auton}, {"AWP", awp_auton}, {"Skills", skills_auton} })
 
void initialize ()
 
void disabled ()
 
void competition_initialize ()
 
void autonomous ()
 
void opcontrol ()
 

Variables

rd::Console console
 

Function Documentation

◆ alliance_btn_event_handler()

void alliance_btn_event_handler ( lv_event_t * e)

Definition at line 16 of file main.cpp.

16 {
17 lv_event_code_t code = lv_event_get_code(e);
18 lv_obj_t * btn = lv_event_get_target(e);
19 lv_obj_t * label = lv_obj_get_child(btn, 0);
20
21 if(code == LV_EVENT_CLICKED) {
22 if(allianceColor == RED) {
23 allianceColor = Color::BLUE;
24 lv_obj_set_style_bg_color(btn, lv_palette_main(LV_PALETTE_BLUE), 0);
25 lv_label_set_text(label, "BLUE");
26 } else {
27 allianceColor = Color::RED;
28 lv_obj_set_style_bg_color(btn, lv_palette_main(LV_PALETTE_RED), 0);
29 lv_label_set_text(label, "RED");
30 }
31
32
33 std::cout << "Alliance switched to: " << (allianceColor == Color::RED ? "Red" : "Blue") << std::endl;
34 }
35}
Color allianceColor
Definition globals.cpp:93

References allianceColor.

Referenced by create_alliance_selector().

◆ autonomous()

void autonomous ( )

Definition at line 115 of file main.cpp.

115 {
116 //selector.run_auton();
117 //skills_auton();
118 //awp_auton();
119 elim_auton();
120}
void elim_auton()

References elim_auton().

◆ competition_initialize()

void competition_initialize ( )

Definition at line 112 of file main.cpp.

112 {
113}

◆ create_alliance_selector()

void create_alliance_selector ( )

Definition at line 37 of file main.cpp.

37 {
38 lv_obj_t * btn = lv_btn_create(lv_layer_top());
39 lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10);
40 lv_obj_set_size(btn, 80, 40);
41 lv_obj_set_style_bg_color(btn, lv_palette_main(LV_PALETTE_RED), 0);
42 lv_obj_t * label = lv_label_create(btn);
43 lv_label_set_text(label, "RED");
44 lv_obj_center(label);
45 lv_obj_add_event_cb(btn, alliance_btn_event_handler, LV_EVENT_ALL, NULL);
46}
void alliance_btn_event_handler(lv_event_t *e)
Definition main.cpp:16

References alliance_btn_event_handler().

Referenced by initialize().

◆ disabled()

void disabled ( )

Definition at line 108 of file main.cpp.

108 {
109 selector.focus();
110}
rd::Selector selector({ {"Right", right_auton}, {"Left", left_auton}, {"Carry", carry_auton}, {"Elim", elim_auton}, {"AWP", awp_auton}, {"Skills", skills_auton} })

References selector().

◆ initialize()

void initialize ( )

Definition at line 60 of file main.cpp.

60 {
61 chassis.calibrate();
65 color_sensor.set_led_pwm(100);
66 /*
67 chassis.setPose(-63.5, -18.5, 180);
68 MCL::StartMCL(-63.5, -18.5, 180);
69 pros::Task mclTask(MCL::MonteCarlo);
70 */
71
72 /*
73 chassis.setPose(-48.5, -54.56, 270);
74 console.focus();
75
76 */
79 selector.focus();
80 pros::Task screen_task([&]() {
81 lemlib::Pose pose{0,0,0};
82 while (true) {
83 console.clear();
84 pose = chassis.getPose();
85
86
87 //distancePose dpose = distanceReset(false);
88 console.printf("X: %f\n", pose.x);
89 console.printf("Y: %f\n", pose.y);
90 console.printf("Theta: %f\n", pose.theta);
91
92 /*
93 console.printf("D X: %f\n", dpose.x);
94 console.printf("D Y: %f\n", dpose.y);
95 console.printf("Using X: %d\n", dpose.using_odom_x);
96 console.printf("Using Y: %d\n", dpose.using_odom_y);
97 */
98
99
100 //console.printf("X MCL: %f\n", MCL::X);
101 //console.printf("Y MCL: %f\n", MCL::Y);
102
103 pros::delay(100);
104 }
105 });
106}
pros::Optical color_sensor(5)
lemlib::Chassis chassis
void create_alliance_selector()
Definition main.cpp:37
rd::Console console
Definition main.cpp:58
void calibrate_vision()
void distance_sensor_disconnect_warning()
Definition warnings.cpp:95
void motor_disconnect_warning()
Definition warnings.cpp:50
void temp_warning()
Definition warnings.cpp:4

References calibrate_vision(), chassis, color_sensor(), console, create_alliance_selector(), distance_sensor_disconnect_warning(), motor_disconnect_warning(), selector(), and temp_warning().

◆ opcontrol()

void opcontrol ( )

Definition at line 140 of file main.cpp.

140 {
141 std::cout << allianceColor << std::endl;
142 bool trapDoor_commanded = false;
143 while(true)
144 {
145 int throttle = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
146 int steer = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
147
148 if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_L2))
149 {
150 midgoal_first = true;
151 }
152
153 if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_R1))
154 {
155 intake();
156 }
157 else if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_R2))
158 {
159 outtake();
160 }
161 else if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_L1))
162 {
164 }
165 else if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_L2))
166 {
168 }
169 else if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_UP))
170 {
172 }
173 else if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_DOWN))
174 {
175 if(descore.is_extended())
176 descore.retract();
177 }
178 else if(controller.get_digital(pros::E_CONTROLLER_DIGITAL_UP))
179 {
180 throttle = 0;
181 steer = 0;
182 leftMotors.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
183 rightMotors.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
184 leftMotors.brake();
185 rightMotors.brake();
186 }
187 else if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_X))
188 {
189 if(!trapDoor_commanded)
190 {
191 trapDoor_commanded = true;
192 trapDoor.extend();
193 }
194 else {
195 trapDoor_commanded = false;
196 }
197 }
198 else if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_B))
199 {
200 matchload.toggle();
201 }
202 else if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_RIGHT))
203 {
205 controller.rumble(".");
206 }
207 else if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A))
208 {
209 alignToGoal(1);
210 }
211 else
212 {
213 resting_state(trapDoor_commanded);
214 midgoal_first = false;
215 }
216
217 if(throttle < 5)
218 chassis.arcade(throttle, steer, false);
219 else
220 chassis.curvature(throttle, steer, false);
221 pros::delay(10);
222 }
223}
void outtake(int power=12000)
void intake(int power=12000)
void intake_to_basket()
void score_longgoal(int power=12000, Color allianceColor=Color::RED)
void score_midgoal(int power=12000)
void resting_state(bool trapDoor_commanded=false)
pros::adi::Pneumatics trapDoor('A', false)
bool color_sort_enable
Definition globals.cpp:94
pros::adi::Pneumatics descore('D', false)
bool midgoal_first
Definition globals.cpp:95
pros::adi::Pneumatics matchload('B', false)
pros::MotorGroup rightMotors
pros::MotorGroup leftMotors
Definition globals.cpp:20
pros::Controller controller
bool alignToGoal(int SIG_NUM)

References alignToGoal(), allianceColor, chassis, color_sort_enable, controller, descore(), intake(), intake_to_basket(), leftMotors, matchload(), midgoal_first, outtake(), resting_state(), rightMotors, score_longgoal(), score_midgoal(), and trapDoor().

◆ selector()

rd::Selector selector ( { {"Right", right_auton}, {"Left", left_auton}, {"Carry", carry_auton}, {"Elim", elim_auton}, {"AWP", awp_auton}, {"Skills", skills_auton} } )

Variable Documentation

◆ console

rd::Console console

Definition at line 58 of file main.cpp.

Referenced by initialize().