First I added comments to all the new systems.

Second I finished all the color sorter code, like finishing the function to call when you want to look for a color.
Next we had the scotts county competition so I made custom auton routes for us to run at the competition. These will be changed later.
This commit is contained in:
Carter committed 2026-11-17 07:36:58 -05:00
1 parent c9f7db1011
commit 3bbad07dea
8 files changed
+671 -64

No files matched your search

+55 -36
View File
@@ -4,45 +4,64 @@ using namespace ez;
ColorSensors::ColorSensors() {}
void ColorSensors::color_sorter(const OpticalSensors& c_sensor, control_period period, wanted_color selected_color, bool looped) {
/**
* Coler sorter function, allows you to take the value of a sensor
* and complete a task based on the selected color.
*/
void ColorSensors::color_sorter(pros::Optical* c_sensor, control_period period, wanted_color selected_color, int led_brightness, bool looped) {
// Sets the sensors leds to a certain brightness
c_sensor->set_led_pwm(led_brightness);
colorSensorTwo.set_led_pwm(led_brightness);
// loop that makes sure sensor values are always being updated and the function doesn't exit till a result is reached
while (looped == true) {
// Gets the current color of the selected sensors
double main_hue = c_sensor->get_hue();
double backup_hue = colorSensorTwo.get_hue();
// Makes a bool value to turn true when it sees blue
bool main_is_blue = (main_hue >= 160 && main_hue <= 280);
bool backup_is_blue = (backup_hue >= 160 && backup_hue <= 280);
// Makes a bool value to turn true when is ses red
bool main_is_red = (main_hue <= 20 || main_hue >= 340);
bool backup_is_red = (backup_hue <= 20 || backup_hue >= 340);
// A switch to easily check what color we want to look for
switch (selected_color)
{
case wanted_color::blue:
// If both sensors see the same color exit the loop and stop doing the code
if (main_is_blue == true && backup_is_blue == true) {
roller.move(0);
looped = false;
}
else {
// Code to run when the sensors don't see the right color
roller.move(60);
}
break;
case wanted_color::red:
// If both sensors see the same color exit the loop and stop doing the code
if (main_is_red == true && backup_is_red == true) {
roller.move(0);
looped = false;
}
else {
// Code to run when the sensors don't see the right color
roller.move(65);
}
break;
default:
break;
}
pros::delay(100); // Delay to allow the cpu to catch up
}
}
/*
void Opticalcarter::color_sorter(control_period period, wanted_color selected_color, bool looped) {
switch (selected_color)
{
case wanted_color::blue:
while (looped == true) {
pros::delay(100);
while (!colorSensorOne.get_hue() >= 160 && !colorSensorOne.get_hue() <=280 && !colorSensorTwo.get_hue() >= 160 && !colorSensorTwo.get_hue() <=280) {
roller.move(127);
if (colorSensorOne.get_hue() >= 160 && colorSensorOne.get_hue() <=280 && colorSensorTwo.get_hue() >= 160 && colorSensorTwo.get_hue() <=280) {
roller.move(0);
looped = false;
}
}
}
break;
case wanted_color::red:
while (looped == true) {
pros::delay(100);
while (!colorSensorOne.get_hue() <= 20 || !colorSensorOne.get_hue() >=340 && !colorSensorTwo.get_hue() <= 20 || !colorSensorTwo.get_hue() >=340) {
roller.move(127);
if (colorSensorOne.get_hue() <= 20 || colorSensorOne.get_hue() >=340 && colorSensorTwo.get_hue() <= 20 || colorSensorTwo.get_hue() >=340) {
roller.move(0);
looped = false;
}
}
}
break;
default:
break;
}
}*/
/*while (looped == true) {
if (sensorNum == 1 && period == auton) {
pros::delay(100);
+530
View File
@@ -11,6 +11,9 @@ const int DRIVE_SPEED = 110;
const int TURN_SPEED = 90;
const int SWING_SPEED = 110;
//Default Objects
ColorSensors sorter;
///
// Constants
///
@@ -52,7 +55,534 @@ void default_constants() {
///
// Custom auton routes
//
void quick_right_blue() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -59.3_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
}
void quick_right_red() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -59.6_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
}
void blue_left_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::LEFT_SWING, 60_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::LEFT_SWING, 20_deg, SWING_SPEED, -0);
chassis.pid_wait();
claw.move(-127);
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_drive_set(18_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::LEFT_SWING, 40_deg, 60, 7);
chassis.pid_wait();
lift.move(100);
pros::delay(200);
lift.move(0);
pros::delay(300);
chassis.pid_turn_set(-112.4_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(30_in, DRIVE_SPEED);
chassis.pid_wait();
lift.move(100);
pros::delay(900);
lift.move(0);
chassis.pid_drive_set(5_in, 70);
chassis.pid_wait();
pros::delay(200);
lift.move(-50);
pros::delay(100);
claw.move(127);
pros::delay(500);
lift.move(0);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait();
}
void blue_right_4pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -59.3_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -20_deg, SWING_SPEED, -0);
chassis.pid_wait();
claw.move(-127);
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_drive_set(18_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -40_deg, 60, 7);
chassis.pid_wait();
lift.move(100);
pros::delay(1000);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -210_deg, SWING_SPEED, -20);
chassis.pid_wait_quick_chain();
chassis.pid_turn_set(-215_deg, SWING_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(10_in, 100);
chassis.pid_wait();
pros::delay(200);
lift.move(-50);
pros::delay(100);
claw.move(127);
pros::delay(500);
lift.move(0);
chassis.pid_drive_set(-3_in, 80);
chassis.pid_wait_quick_chain();
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -134_deg, SWING_SPEED, -30);
chassis.pid_wait();
claw.move(-127);
chassis.pid_drive_set(12_in, 100);
chassis.pid_wait();
lift.move(80);
pros::delay(350);
lift.move(0);
claw.move(0);
pros::delay(150);
chassis.pid_swing_set(ez::RIGHT_SWING, -280_deg, SWING_SPEED, 0);
}
void blue_right_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -59.5_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -20_deg, SWING_SPEED, -0);
chassis.pid_wait();
claw.move(-127);
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_drive_set(18_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -40_deg, 60, 9);
chassis.pid_wait();
lift.move(100);
pros::delay(200);
lift.move(0);
pros::delay(300);
chassis.pid_turn_set(112.4_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(31_in, DRIVE_SPEED);
chassis.pid_wait();
lift.move(100);
pros::delay(900);
lift.move(0);
chassis.pid_drive_set(5_in, 70);
chassis.pid_wait();
pros::delay(200);
lift.move(-50);
pros::delay(100);
claw.move(127);
pros::delay(500);
lift.move(0);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait();
}
void red_left_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::LEFT_SWING, 60_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::LEFT_SWING, 20_deg, SWING_SPEED, -0);
chassis.pid_wait();
claw.move(-127);
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_drive_set(18_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::LEFT_SWING, 40_deg, 60, 8);
chassis.pid_wait();
lift.move(100);
pros::delay(200);
lift.move(0);
pros::delay(300);
chassis.pid_turn_set(-112.4_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(30_in, DRIVE_SPEED);
chassis.pid_wait();
lift.move(100);
pros::delay(900);
lift.move(0);
chassis.pid_drive_set(5_in, 70);
chassis.pid_wait();
pros::delay(200);
lift.move(-50);
pros::delay(100);
claw.move(127);
pros::delay(500);
lift.move(0);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait();
}
void red_right_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -59.3_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -20_deg, SWING_SPEED, -0);
chassis.pid_wait();
claw.move(-127);
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_drive_set(18_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -40_deg, 60, 8);
chassis.pid_wait();
lift.move(100);
pros::delay(200);
lift.move(0);
pros::delay(300);
chassis.pid_turn_set(112.4_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(30_in, DRIVE_SPEED);
chassis.pid_wait();
lift.move(100);
pros::delay(900);
lift.move(0);
chassis.pid_drive_set(5_in, 70);
chassis.pid_wait();
pros::delay(200);
lift.move(-50);
pros::delay(100);
claw.move(127);
pros::delay(500);
lift.move(0);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait();
}
void red_right_4pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true);
lift.move(80);
pros::delay(420);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -59.3_deg, SWING_SPEED, -7);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(15.7_in, 100, true);
chassis.pid_wait_until(9_in);
chassis.pid_speed_max_set(30);
chassis.pid_wait();
pros::delay(200);
lift.move(-30);
pros::delay(110);
lift.move(0);
claw.move(90);
lift.move(-30);
pros::delay(100);
lift.move(0);
pros::delay(500);
chassis.pid_drive_set(-3_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -20_deg, SWING_SPEED, -0);
chassis.pid_wait();
claw.move(-127);
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_drive_set(18_in, 100);
chassis.pid_wait_quick_chain();
chassis.pid_swing_set(ez::RIGHT_SWING, -40_deg, 60, 7);
chassis.pid_wait();
lift.move(100);
pros::delay(1000);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -210_deg, SWING_SPEED, -20);
chassis.pid_wait_quick_chain();
chassis.pid_turn_set(-215_deg, SWING_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_drive_set(10_in, 100);
chassis.pid_wait();
pros::delay(200);
lift.move(-50);
pros::delay(100);
claw.move(127);
pros::delay(500);
lift.move(0);
chassis.pid_drive_set(-3_in, 80);
chassis.pid_wait_quick_chain();
lift.move(-80);
pros::delay(200);
lift.move(0);
chassis.pid_swing_set(ez::RIGHT_SWING, -134_deg, SWING_SPEED, -30);
chassis.pid_wait();
claw.move(-127);
chassis.pid_drive_set(12_in, 100);
chassis.pid_wait();
lift.move(80);
pros::delay(350);
lift.move(0);
claw.move(0);
pros::delay(150);
chassis.pid_swing_set(ez::RIGHT_SWING, -280_deg, SWING_SPEED, 0);
}
void blue_wp() {
}
void red_wp() {
}
void skills() {
}
void Test() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true);
}
///
// Drive Example
+24 -2
View File
@@ -9,7 +9,7 @@ ez::Drive chassis(
6, // IMU Port
3.25, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!)
360.0); // Wheel RPM = cartridge * (motor gear / wheel gear)
450.0); // Wheel RPM = cartridge * (motor gear / wheel gear)
// Uncomment the trackers you're using here!
// - `8` and `9` are smart ports (making these negative will reverse the sensor)
@@ -24,6 +24,20 @@ Pneumatics pistonControl;
Mechanisms motorControl;
//ArmMech armObj;
/**
* This is creating and initializing and instance of the Optical sensors structure
*
* Finds the memory location of the two color sensors, which then the "mySensors" container
* gives to the pointers. So now the pointers have somewhere to point to in memory.
*/
namespace ez {
// Initializes the mySensors variable
OpticalSensors mySensors = {
// This is where color sensors go.
&colorSensorOne,
&colorSensorTwo
};
}
// Lift constructor
/*LiftMech liftObj(
@@ -96,7 +110,15 @@ void initialize() {
// Autonomous Selector using LLEMU
ez::as::auton_selector.autons_add({
//Custom autonomouse routes go here.
{"Quick right blue\n\n1 pins on 1 goals", quick_right_blue},
{"Quick right red\n\n1 pins on 1 goals", quick_right_red},
{"Blue Left\n\n3 pins on 2 goals", blue_left_3pin},
{"Blue Right\n\n4 pins on 2 goals", blue_right_4pin},
{"Blue Right\n\n3 pins on 2 goals", blue_right_3pin},
{"Red Left\n\n3 pins on 2 goals", red_left_3pin},
{"Red Right\n\n3 pins on 2 goals", red_right_3pin},
{"Red Right\n\n4 pins on 2 goals", red_right_4pin},
{"Test\n\nTest testing", Test},
/*{"Drive\n\nDrive forward and come back", drive_example},
{"Turn\n\nTurn 3 times.", turn_example},