1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "main.h"
2#include "lemlib/api.hpp" // IWYU pragma: keep
3#include "lemlib/chassis/chassis.hpp"
4#include "lemlib/chassis/trackingWheel.hpp"
5#include "liblvgl/llemu.hpp"
6#include "pros/misc.h"
7
8
9pros::Controller controller(CONTROLLER_MASTER);
10
11pros::MotorGroup rightMotors({-11,2,1});
12pros::MotorGroup leftMotors({-16,14,-13});
13
14lemlib::Drivetrain drivetrain(&leftMotors, &rightMotors, 10, 3.25, 450, 2);
15
16pros::IMU imu(3);
17
18pros::Rotation horizontal_tracking_sensor(12);
19pros::Rotation vertical_tracking_sensor(15);
20
21lemlib::TrackingWheel horizontal_tracking_wheel(&horizontal_tracking_sensor, 3.75, 9/2.54, 1);
22lemlib::TrackingWheel vertical_tracking_wheel(&vertical_tracking_sensor, 3.75, 7/100/2.54,1);
23lemlib::OdomSensors sensors(&vertical_tracking_wheel, nullptr, &horizontal_tracking_wheel, nullptr, &imu);
24
25// lateral PID controller
26lemlib::ControllerSettings lateral_controller(10, // proportional gain (kP)
27 0, // integral gain (kI)
28 3, // derivative gain (kD)
29 3, // anti windup
30 1, // small error range, in inches
31 100, // small error range timeout, in milliseconds
32 3, // large error range, in inches
33 500, // large error range timeout, in milliseconds
34 20 // maximum acceleration (slew)
35);
36
37// angular PID controller
38lemlib::ControllerSettings angular_controller(2, // proportional gain (kP)
39 0, // integral gain (kI)
40 10, // derivative gain (kD)
41 3, // anti windup
42 1, // small error range, in degrees
43 100, // small error range timeout, in milliseconds
44 3, // large error range, in degrees
45 500, // large error range timeout, in milliseconds
46 0 // maximum acceleration (slew)
47);
48
49lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors);
50
51
58void initialize() {
59 pros::lcd::initialize(); // initialize brain screen
60 chassis.calibrate(); // calibrate sensors
61 // print position to brain screen
62 pros::Task screen_task([&]() {
63 while (true) {
64 // print robot location to the brain screen
65 pros::lcd::print(0, "X: %f", chassis.getPose().x); // x
66 pros::lcd::print(1, "Y: %f", chassis.getPose().y); // y
67 pros::lcd::print(2, "Theta: %f", chassis.getPose().theta); // heading
68 // delay to save resources
69 pros::delay(20);
70 }
71 });
72}
73
80void disabled() {}
81
92
104void autonomous() {}
105
119
120
121
122void opcontrol() {
123 while (true)
124 {
125 int rightControl = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
126 int leftControl = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
127
128 chassis.tank(leftControl, rightControl, false);
129
130 pros::delay(20);
131 }
132}
pros::MotorGroup rightMotors({-11, 2, 1})
void initialize()
Definition main.cpp:58
pros::Controller controller(CONTROLLER_MASTER)
void autonomous()
Definition main.cpp:104
void disabled()
Definition main.cpp:80
lemlib::OdomSensors sensors & vertical_tracking_wheel
Definition main.cpp:23
lemlib::TrackingWheel horizontal_tracking_wheel & horizontal_tracking_sensor
Definition main.cpp:21
void competition_initialize()
Definition main.cpp:91
lemlib::Drivetrain drivetrain & leftMotors
Definition main.cpp:14
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors)
lemlib::ControllerSettings angular_controller(2, 0, 10, 3, 1, 100, 3, 500, 0)
void opcontrol()
Definition main.cpp:122
pros::IMU imu(3)
lemlib::TrackingWheel vertical_tracking_wheel & vertical_tracking_sensor
Definition main.cpp:22
lemlib::ControllerSettings lateral_controller(10, 0, 3, 3, 1, 100, 3, 500, 20)