Compare commits

..
2 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
6 changed files with 98 additions and 93 deletions

No files matched your search

+3 -2
View File
@@ -55,10 +55,11 @@ namespace ez {
* \param looped
* 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
* from inside the structure.
@@ -82,7 +82,6 @@ namespace ez{
float liftKP;
public:
int liftHeight; // Current height of the lift in centdegrees
int currLiftState;
int liftTarget;
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.
void lift_driver_control(enum ControllerR, enum ButtonsR);
void lift_auton_control(int pickState);
void lift_auton_control(long pickedHeight);
void cycle_states();
void reset_state();
void lift_control(); // Computes the velocity for the lift to move at.
+69 -3
View File
@@ -1,4 +1,5 @@
#include "main.h"
#include "pros/screen.h"
using namespace ez;
@@ -8,7 +9,7 @@ ColorSensors::ColorSensors() {}
* 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) {
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
c_sensor->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);
}
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) {
@@ -53,7 +53,6 @@ void ColorSensors::color_sorter(pros::Optical* c_sensor, control_period period,
roller.move(65);
}
break;
default:
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) {
if (sensorNum == 1 && period == auton) {
pros::delay(100);
@@ -4,11 +4,10 @@
using namespace ez;
LiftMech::LiftMech() {
liftHeight = 0;
liftError = 0;
liftVelocity = 0;
liftStates = {0, 0, 0, 0};
liftStates = {0, 0};
}
LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) {
liftStates = _liftStates;
@@ -17,6 +16,11 @@ LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) {
liftTarget = 0;
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) {
switch (currController)
@@ -66,25 +70,8 @@ void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUs
}
}
void LiftMech::lift_auton_control(int pickState) {
switch (pickState)
{
case 1:
liftTarget = liftStates[0];
break;
case 2:
liftTarget = liftStates[1];
break;
case 3:
liftTarget = liftStates[2];
break;
case 4:
liftTarget = liftStates[3];
break;
default:
liftTarget = liftStates[0];
break;
}
void LiftMech::lift_auton_control(long pickedHeight) {
liftTarget = pickedHeight;
}
void LiftMech::cycle_states() {
@@ -97,28 +84,11 @@ void LiftMech::cycle_states() {
liftTarget = liftStates[currLiftState];
}
}
void LiftMech::reset_state() {
currLiftState = 0;
void LiftMech::reset_state() {liftTarget = 0;}
if (!liftStates.empty()) {
liftTarget = liftStates[currLiftState];
}
}
void LiftMech::set_lift_kp(float _liftKp) {liftKP = _liftKp;}
void LiftMech::lift_control() {
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_lift_state() {return liftStates[currLiftState];}
int LiftMech::get_num_lift_states() {return numLiftStates;}
float LiftMech::get_lift_kp() {return liftKP;}
+9 -9
View File
@@ -56,7 +56,7 @@ void default_constants() {
// Custom auton routes
//
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);
pros::delay(420);
@@ -85,7 +85,7 @@ void quick_right_blue() {
}
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);
pros::delay(420);
@@ -114,7 +114,7 @@ void quick_right_red() {
}
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);
pros::delay(420);
@@ -185,7 +185,7 @@ void blue_left_3pin() {
}
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);
pros::delay(420);
@@ -271,7 +271,7 @@ void blue_right_4pin() {
}
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);
pros::delay(420);
@@ -342,7 +342,7 @@ void blue_right_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);
pros::delay(420);
@@ -413,7 +413,7 @@ void red_left_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);
pros::delay(420);
@@ -484,7 +484,7 @@ void red_right_3pin() {
}
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);
pros::delay(420);
@@ -581,7 +581,7 @@ void skills() {
}
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);
}
///
+5 -36
View File
@@ -22,7 +22,7 @@ ez::tracking_wheel vert_tracker(17, 3.25, 2.0); // This tracking wheel is para
// Default Objects
Pneumatics pistonControl;
Mechanisms motorControl;
//ArmMech armObj;
/**
* Creates and initializes and instance of the Optical sensors structure
@@ -40,17 +40,7 @@ namespace ez {
}
// Lift constructor
LiftMech liftObj(
<<<<<<< HEAD
{0, 0, 0, 0}, 4);
=======
{0, -19714, -13017, -27993, -17491, -48393, -37459, -69706, -58957, -89693, -79453, -106664, -99115}, 13);
>>>>>>> 4be5e2958fb4be3d35cbe58b8933bfde5ce90ed3
// Wrist constructor
/*WristMech wristObj(
{0, -14529}, 2);*/
/**
* Runs initialization code. This occurs as soon as the program is started.
@@ -64,22 +54,7 @@ void initialize() {
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();
//wristRotation.reset_position();
pros::Task liftControlTasck([&]{
while (true) {
@@ -317,22 +292,16 @@ void opcontrol() {
// Call custom drive functions here
pistonControl.control_piston(PistonsP::PlaceHolderP, ControlPeriodP::driver,
ControllerP::master, ButtonsP::arrow_buttons);
/*motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::right_shoulder_buttons,
MotorGroups::lift_MG, 127, -127);*/
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::right_shoulder_buttons,
MotorGroups::lift_MG, 127, -127);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::left_shoulder_buttons,
MotorGroups::claw_M, -127, 127);
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::Y_B_buttons,
MotorGroups::roller_M, 127, 0);
// Basic control scheme
//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);
//liftObj.lift_driver_control(ControllerR::master, ButtonsR::right_shoulder_buttons);
//Basic drive presets
chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.opcontrol_tank(); // Tank control
// chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade