Compare commits

...
4 Commits
Author SHA1 Message Date
Carter Essen 62670f8c80 I started work working on the color display function to show the color the sensor is seeing on the brain. 2026-11-23 12:12:38 -05:00
Carter Essen 83ac6ad184 Changed a few variable nemes in the lift rotation file.
I also changed the lift reset function and the auton lift control to instead of looking at the array they will just set the lift target to the specified value.
2026-11-22 20:31:41 -05:00
Carter Essen ecebf87643 Merge branch 'main' of http://192.168.162.99:3000/carter/VEX-OverRide 2026-11-22 20:11:02 -05:00
Carter Essen d9db3ee688 IDK 2026-11-22 20:07:03 -05:00
6 changed files with 111 additions and 113 deletions

No files matched your search

+3 -2
View File
@@ -55,10 +55,11 @@ namespace ez {
* \param looped * \param looped
* do we want to continusly check for that color * do we want to continusly check for that color
*/ */
void color_sorter(pros::Optical* c_sensor, control_period period, wanted_color selected_color, int led_brightness, bool looped); void color_sorter(pros::Optical* c_sensor, wanted_color selected_color, int led_brightness, bool looped);
void DisplayColor(); void DisplayColor(pros::Optical* cSensor, int portNum, int sensorCount);
}; };
/** /**
* Declares a variable that can be used anywhere to access information * Declares a variable that can be used anywhere to access information
* from inside the structure. * from inside the structure.
@@ -82,7 +82,6 @@ namespace ez{
float liftKP; float liftKP;
public: public:
int liftHeight; // Current height of the lift in centdegrees
int currLiftState; int currLiftState;
int liftTarget; int liftTarget;
float liftError; float liftError;
@@ -92,7 +91,7 @@ namespace ez{
LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates); // Constructor to initialze array and amount of values in array. LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates); // Constructor to initialze array and amount of values in array.
void lift_driver_control(enum ControllerR, enum ButtonsR); void lift_driver_control(enum ControllerR, enum ButtonsR);
void lift_auton_control(int pickState); void lift_auton_control(long pickedHeight);
void cycle_states(); void cycle_states();
void reset_state(); void reset_state();
void lift_control(); // Computes the velocity for the lift to move at. void lift_control(); // Computes the velocity for the lift to move at.
+69 -3
View File
@@ -1,4 +1,5 @@
#include "main.h" #include "main.h"
#include "pros/screen.h"
using namespace ez; using namespace ez;
@@ -8,7 +9,7 @@ ColorSensors::ColorSensors() {}
* Coler sorter function, allows you to take the value of a sensor * Coler sorter function, allows you to take the value of a sensor
* and complete a task based on the selected color. * 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) { void ColorSensors::color_sorter(pros::Optical* c_sensor, wanted_color selected_color, int led_brightness, bool looped) {
// Sets the sensors leds to a certain brightness // Sets the sensors leds to a certain brightness
c_sensor->set_led_pwm(led_brightness); c_sensor->set_led_pwm(led_brightness);
colorSensorTwo.set_led_pwm(led_brightness); colorSensorTwo.set_led_pwm(led_brightness);
@@ -41,7 +42,6 @@ void ColorSensors::color_sorter(pros::Optical* c_sensor, control_period period,
roller.move(60); roller.move(60);
} }
break; break;
case wanted_color::red: case wanted_color::red:
// If both sensors see the same color exit the loop and stop doing the code // If both sensors see the same color exit the loop and stop doing the code
if (main_is_red == true && backup_is_red == true) { if (main_is_red == true && backup_is_red == true) {
@@ -53,7 +53,6 @@ void ColorSensors::color_sorter(pros::Optical* c_sensor, control_period period,
roller.move(65); roller.move(65);
} }
break; break;
default: default:
break; break;
} }
@@ -62,6 +61,73 @@ void ColorSensors::color_sorter(pros::Optical* c_sensor, control_period period,
} }
void ColorSensors::DisplayColor(pros::Optical* cSensor, int portNum, int sensorCount) {
double mainHue = cSensor->get_hue();
bool isRed = (mainHue <= 20 || mainHue >= 340);
bool isBlue = (mainHue >= 160 && mainHue <= 280);
switch (sensorCount)
{
case 1:
if (isRed == true) {
pros::screen::print(TEXT_SMALL, 20, 30, "Sensor on port " + sensorCount);
}
else if (isBlue == true) {
}
break;
case 2:
if (isRed == true) {
}
else if (isBlue == true) {
}
break;
case 3:
if (isRed == true) {
}
else if (isBlue == true) {
}
break;
case 4:
if (isRed == true) {
}
else if (isBlue == true) {
}
break;
case 5:
if (isRed == true) {
}
else if (isBlue == true) {
}
break;
case 6:
if (isRed == true) {
}
else if (isBlue == true) {
}
break;
default:
break;
}
}
/*while (looped == true) { /*while (looped == true) {
if (sensorNum == 1 && period == auton) { if (sensorNum == 1 && period == auton) {
pros::delay(100); pros::delay(100);
@@ -4,11 +4,10 @@
using namespace ez; using namespace ez;
LiftMech::LiftMech() { LiftMech::LiftMech() {
liftHeight = 0;
liftError = 0; liftError = 0;
liftVelocity = 0; liftVelocity = 0;
liftStates = {0, 0, 0, 0}; liftStates = {0, 0};
} }
LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) { LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) {
liftStates = _liftStates; liftStates = _liftStates;
@@ -17,6 +16,11 @@ LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) {
liftTarget = 0; liftTarget = 0;
set_lift_kp(0.0173f); set_lift_kp(0.0173f);
} }
void LiftMech::lift_control() {
liftError = liftTarget - liftRotation.get_position();
liftVelocity = get_lift_kp() * liftError;
lift.move(-liftVelocity);
}
void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUsed) { void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUsed) {
switch (currController) switch (currController)
@@ -66,6 +70,10 @@ void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUs
} }
} }
void LiftMech::lift_auton_control(long pickedHeight) {
liftTarget = pickedHeight;
}
void LiftMech::cycle_states() { void LiftMech::cycle_states() {
currLiftState ++; currLiftState ++;
@@ -76,28 +84,11 @@ void LiftMech::cycle_states() {
liftTarget = liftStates[currLiftState]; liftTarget = liftStates[currLiftState];
} }
} }
void LiftMech::reset_state() { void LiftMech::reset_state() {liftTarget = 0;}
currLiftState = 0;
if (!liftStates.empty()) { void LiftMech::set_lift_kp(float _liftKp) {liftKP = _liftKp;}
liftTarget = liftStates[currLiftState];
}
}
void LiftMech::lift_control() { int LiftMech::get_lift_state() {return liftStates[currLiftState];}
liftError = liftTarget - liftRotation.get_position();
liftVelocity = get_lift_kp() * liftError;
lift.move(-liftVelocity);
}
void LiftMech::set_lift_kp(float _liftKp) {
liftKP = _liftKp;
}
int LiftMech::get_lift_state() {
if (!liftStates.empty()) {
return liftStates[currLiftState];
}
}
int LiftMech::get_num_lift_states() {return numLiftStates;} int LiftMech::get_num_lift_states() {return numLiftStates;}
float LiftMech::get_lift_kp() {return liftKP;} float LiftMech::get_lift_kp() {return liftKP;}
@@ -162,39 +153,39 @@ void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUs
break; break;
} }
break; break;
case ControllerR::slave: case ControllerR::master:
switch (buttonUsed) switch (buttonUsed)
{ {
case ButtonsR::arrow_buttons: case ButtonsR::arrow_buttons:
if (slave.get_digital(DIGITAL_RIGHT)) { if (master.get_digital(DIGITAL_RIGHT)) {
cycle_states(); cycle_states();
} }
else if (slave.get_digital(DIGITAL_DOWN)) { else if (master.get_digital(DIGITAL_DOWN)) {
reset_state(); reset_state();
} }
break; break;
case ButtonsR::Y_B_buttons: case ButtonsR::Y_B_buttons:
if (slave.get_digital(DIGITAL_Y)) { if (master.get_digital(DIGITAL_Y)) {
cycle_states(); cycle_states();
} }
else if (slave.get_digital(DIGITAL_B)) { else if (master.get_digital(DIGITAL_B)) {
reset_state(); reset_state();
} }
break; break;
case ButtonsR::left_shoulder_buttons: case ButtonsR::left_shoulder_buttons:
if (slave.get_digital(DIGITAL_L1)) { if (master.get_digital(DIGITAL_L1)) {
cycle_states(); cycle_states();
} }
else if (slave.get_digital(DIGITAL_L2)) { else if (master.get_digital(DIGITAL_L2)) {
reset_state(); reset_state();
} }
break; break;
case ButtonsR::right_shoulder_buttons: case ButtonsR::right_shoulder_buttons:
if (slave.get_digital(DIGITAL_R1)) { if (master.get_digital(DIGITAL_R1)) {
cycle_states(); cycle_states();
} }
else if (slave.get_digital(DIGITAL_R2)) { else if (master.get_digital(DIGITAL_R2)) {
reset_state(); reset_state();
} }
break; break;
+9 -9
View File
@@ -56,7 +56,7 @@ void default_constants() {
// Custom auton routes // Custom auton routes
// //
void quick_right_blue() { void quick_right_blue() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::blue, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -85,7 +85,7 @@ void quick_right_blue() {
} }
void quick_right_red() { void quick_right_red() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::red, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -114,7 +114,7 @@ void quick_right_red() {
} }
void blue_left_3pin() { void blue_left_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::blue, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -185,7 +185,7 @@ void blue_left_3pin() {
} }
void blue_right_4pin() { void blue_right_4pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::blue, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -271,7 +271,7 @@ void blue_right_4pin() {
} }
void blue_right_3pin() { void blue_right_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::blue, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -342,7 +342,7 @@ void blue_right_3pin() {
} }
void red_left_3pin() { void red_left_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::red, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -413,7 +413,7 @@ void red_left_3pin() {
} }
void red_right_3pin() { void red_right_3pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::red, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -484,7 +484,7 @@ void red_right_3pin() {
} }
void red_right_4pin() { void red_right_4pin() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::red, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::red, 100, true);
lift.move(80); lift.move(80);
pros::delay(420); pros::delay(420);
@@ -581,7 +581,7 @@ void skills() {
} }
void Test() { void Test() {
sorter.color_sorter(mySensors.leftColorSensor, control_period::auton, wanted_color::blue, 100, true); sorter.color_sorter(mySensors.leftColorSensor, wanted_color::blue, 100, true);
} }
/// ///
+7 -66
View File
@@ -22,10 +22,10 @@ ez::tracking_wheel vert_tracker(17, 3.25, 2.0); // This tracking wheel is para
// Default Objects // Default Objects
Pneumatics pistonControl; Pneumatics pistonControl;
Mechanisms motorControl; Mechanisms motorControl;
//ArmMech armObj;
/** /**
* This is creating and initializing and instance of the Optical sensors structure * Creates and initializes and instance of the Optical sensors structure
* *
* Finds the memory location of the two color sensors, which then the "mySensors" container * 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. * gives to the pointers. So now the pointers have somewhere to point to in memory.
@@ -40,14 +40,8 @@ namespace ez {
} }
// Lift constructor // Lift constructor
LiftMech liftObj( LiftMech liftObj(
{0, -19714, -13017, -27993, -17491, -48393, -37459, -69706, -58957, -89693, -79453, -106664, -99115}, 13); {0, -19714, -13017, -27993, -17491, -48393, -37459, -69706, -58957, -89693, -79453, -106664, -99115}, 13);
// Wrist constructor
/*WristMech wristObj(
{0, -14529}, 2);*/
/** /**
* Runs initialization code. This occurs as soon as the program is started. * Runs initialization code. This occurs as soon as the program is started.
* *
@@ -60,22 +54,7 @@ void initialize() {
pros::delay(500); // Stop the user from doing anything while legacy ports configure pros::delay(500); // Stop the user from doing anything while legacy ports configure
/*armObj.set_state_values(
{0, -5642},
{0, -22702},
{0, -19740},
{0, -17121}
);
liftObj.set_ranges(
{0, 63194},
{63194, 94246},
{94246, 139878},
{139878, 150000}
);
armRotation.reset_position();*/
liftRotation.reset_position(); liftRotation.reset_position();
//wristRotation.reset_position();
pros::Task liftControlTasck([&]{ pros::Task liftControlTasck([&]{
while (true) { while (true) {
@@ -313,54 +292,16 @@ void opcontrol() {
// Call custom drive functions here // Call custom drive functions here
pistonControl.control_piston(PistonsP::PlaceHolderP, ControlPeriodP::driver, pistonControl.control_piston(PistonsP::PlaceHolderP, ControlPeriodP::driver,
ControllerP::master, ButtonsP::arrow_buttons); ControllerP::master, ButtonsP::arrow_buttons);
/*motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::right_shoulder_buttons, motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::right_shoulder_buttons,
MotorGroups::lift_MG, 127, -127);*/ MotorGroups::lift_MG, 127, -127);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::left_shoulder_buttons, motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::left_shoulder_buttons,
MotorGroups::claw_M, -127, 127); MotorGroups::claw_M, -127, 127);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::Y_B_buttons, motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::Y_B_buttons,
MotorGroups::roller_M, 127, 0); MotorGroups::roller_M, 127, 0);
// Basic control scheme
/*arm.set_brake_mode(MOTOR_BRAKE_HOLD);
if (master.get_digital(DIGITAL_L1)) {
arm.move(90);
}
else if (master.get_digital(DIGITAL_L2)) {
arm.move(-90);
}
else {
arm.brake();
}
lift.set_brake_mode(MOTOR_BRAKE_HOLD); //liftObj.lift_driver_control(ControllerR::master, ButtonsR::right_shoulder_buttons);
if (master.get_digital(DIGITAL_R1)) {
lift.move(127);
}
else if (master.get_digital(DIGITAL_R2)) {
lift.move(-127);
}
else {
lift.brake();
}
wrist.set_brake_mode(MOTOR_BRAKE_HOLD);
if (master.get_digital(DIGITAL_A)) {
wrist.move(20);
}
else if (master.get_digital(DIGITAL_B)) {
wrist.move(-20);
}
else {
wrist.brake();
}*/
//armObj.arm_driver_control(ControllerR::master, ButtonsR::left_shoulder_buttons);
liftObj.lift_driver_control(ControllerR::master, ButtonsR::right_shoulder_buttons);
//armObj.arm_driver_control(ControllerR::slave, ButtonsR::left_shoulder_buttons);
//liftObj.lift_driver_control(ControllerR::slave, ButtonsR::right_shoulder_buttons);
//wristObj.wrist_driver_control(ControllerR::slave, ButtonsR::Y_B_buttons);
//wristObj.rotate_wrist(90);
//Basic drive presets
chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.opcontrol_tank(); // Tank control // chassis.opcontrol_tank(); // Tank control
// chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade // chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade
@@ -373,7 +314,7 @@ void opcontrol() {
//std::cout << "Wrist rotation sensor value: " << "\033[33m" << wristRotation.get_position() << " cdg" << "mm\033[0m" << std::endl; //std::cout << "Wrist rotation sensor value: " << "\033[33m" << wristRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
//std::cout << "Arm limit switch value: " << "\033[34m" << armReset.get_value() << "mm\033[0m" << std::endl;*/ //std::cout << "Arm limit switch value: " << "\033[34m" << armReset.get_value() << "mm\033[0m" << std::endl;*/
///pros::delay(250); //pros::delay(250);
pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME
} }
} }