Compare commits
2
Commits
ecebf87643
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62670f8c80 | ||
|
|
83ac6ad184 |
No files matched your search
@@ -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.
|
||||||
|
|||||||
@@ -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,25 +70,8 @@ void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiftMech::lift_auton_control(int pickState) {
|
void LiftMech::lift_auton_control(long pickedHeight) {
|
||||||
switch (pickState)
|
liftTarget = pickedHeight;
|
||||||
{
|
|
||||||
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::cycle_states() {
|
void LiftMech::cycle_states() {
|
||||||
@@ -97,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;}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
+5
-36
@@ -22,7 +22,7 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and initializes and instance of the Optical sensors structure
|
* Creates and initializes and instance of the Optical sensors structure
|
||||||
@@ -40,17 +40,7 @@ namespace ez {
|
|||||||
}
|
}
|
||||||
// Lift constructor
|
// Lift constructor
|
||||||
LiftMech liftObj(
|
LiftMech liftObj(
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
{0, 0, 0, 0}, 4);
|
|
||||||
=======
|
|
||||||
{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);
|
||||||
>>>>>>> 4be5e2958fb4be3d35cbe58b8933bfde5ce90ed3
|
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -64,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) {
|
||||||
@@ -317,22 +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
|
//liftObj.lift_driver_control(ControllerR::master, ButtonsR::right_shoulder_buttons);
|
||||||
//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
|
||||||
|
|||||||
Reference in new issue
Block a user