Fixed a problem where the OPControl was trying to pull values from an array that never had any values to begin with
causeing a segmentation fault and crashing the brain. Also changed how the function lift_range_finder worked. Instead of just makeing a variable eqaul to a number it also returns the value so we can use it outside of the function. We also added actual values to all the arrays.
This commit is contained in:
1 parent
c46a581eb1
commit
24ee947fd5
8 files changed
+340
-192
No files matched your search
@@ -5,7 +5,13 @@ using namespace ez;
|
||||
|
||||
ArmMech armObjRange;
|
||||
|
||||
LiftMech::LiftMech() {}
|
||||
LiftMech::LiftMech() {
|
||||
liftHeight = 0;
|
||||
liftError = 0;
|
||||
liftVelocity = 0;
|
||||
|
||||
liftStates = {0, 0, 0, 0};
|
||||
}
|
||||
LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) {
|
||||
liftStates = _liftStates;
|
||||
numLiftStates = _numLiftStates;
|
||||
@@ -14,14 +20,14 @@ LiftMech::LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates) {
|
||||
set_lift_kp(0.0173f);
|
||||
}
|
||||
|
||||
void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed) {
|
||||
void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUsed) {
|
||||
switch (currController)
|
||||
{
|
||||
case Controller::master:
|
||||
case ControllerR::master:
|
||||
|
||||
switch (buttonUsed)
|
||||
{
|
||||
case Buttons::arrow_buttons:
|
||||
case ButtonsR::arrow_buttons:
|
||||
if (master.get_digital(DIGITAL_RIGHT)) {
|
||||
lift.move(127);
|
||||
}
|
||||
@@ -29,7 +35,7 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
case Buttons::Y_B_buttons:
|
||||
case ButtonsR::Y_B_buttons:
|
||||
if (master.get_digital(DIGITAL_Y)) {
|
||||
lift.move(127);
|
||||
}
|
||||
@@ -37,7 +43,7 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
case Buttons::left_shoulder_buttons:
|
||||
case ButtonsR::left_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
lift.move(127);
|
||||
}
|
||||
@@ -45,7 +51,7 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
case Buttons::right_shoulder_buttons:
|
||||
case ButtonsR::right_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
lift.move(127);
|
||||
}
|
||||
@@ -57,11 +63,11 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Controller::slave:
|
||||
case ControllerR::slave:
|
||||
|
||||
switch (buttonUsed)
|
||||
{
|
||||
case Buttons::arrow_buttons:
|
||||
case ButtonsR::arrow_buttons:
|
||||
if (slave.get_digital(DIGITAL_RIGHT)) {
|
||||
cycle_states();
|
||||
}
|
||||
@@ -69,7 +75,7 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case Buttons::Y_B_buttons:
|
||||
case ButtonsR::Y_B_buttons:
|
||||
if (slave.get_digital(DIGITAL_Y)) {
|
||||
cycle_states();
|
||||
}
|
||||
@@ -77,7 +83,7 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case Buttons::left_shoulder_buttons:
|
||||
case ButtonsR::left_shoulder_buttons:
|
||||
if (slave.get_digital(DIGITAL_L1)) {
|
||||
cycle_states();
|
||||
}
|
||||
@@ -85,7 +91,7 @@ void LiftMech::lift_driver_control(Controller currController, Buttons buttonUsed
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case Buttons::right_shoulder_buttons:
|
||||
case ButtonsR::right_shoulder_buttons:
|
||||
if (slave.get_digital(DIGITAL_R1)) {
|
||||
cycle_states();
|
||||
}
|
||||
@@ -126,15 +132,20 @@ void LiftMech::lift_auton_control(int pickState) {
|
||||
void LiftMech::cycle_states() {
|
||||
currLiftState ++;
|
||||
|
||||
if (currLiftState == numLiftStates) {
|
||||
currLiftState = 0;
|
||||
if (!liftStates.empty()) {
|
||||
if (currLiftState == numLiftStates) {
|
||||
currLiftState = 0;
|
||||
}
|
||||
liftTarget = liftStates[currLiftState];
|
||||
}
|
||||
liftTarget = liftStates[currLiftState];
|
||||
}
|
||||
|
||||
void LiftMech::reset_state() {
|
||||
currLiftState = 0;
|
||||
liftTarget = liftStates[currLiftState];
|
||||
|
||||
if (!liftStates.empty()) {
|
||||
liftTarget = liftStates[currLiftState];
|
||||
}
|
||||
}
|
||||
|
||||
void LiftMech::lift_control() {
|
||||
@@ -143,20 +154,20 @@ void LiftMech::lift_control() {
|
||||
lift.move(liftVelocity);
|
||||
}
|
||||
|
||||
void LiftMech::lift_range_finder() {
|
||||
int LiftMech::lift_range_finder() {
|
||||
liftHeight = liftRotation.get_position();
|
||||
|
||||
if (liftHeight >= firstRange[0] && liftHeight <= firstRange[1]) {
|
||||
armObjRange.targetPos = 0;
|
||||
if (firstRange.size() >= 2 && liftHeight >= firstRange[0] && liftHeight <= firstRange[1]) {
|
||||
return armObjRange.targetPos = 0;
|
||||
}
|
||||
else if (liftHeight >= secondRange[0] && liftHeight <= secondRange[1]) {
|
||||
armObjRange.targetPos = 1;
|
||||
else if (secondRange.size() >= 2 && liftHeight >= secondRange[0] && liftHeight <= secondRange[1]) {
|
||||
return armObjRange.targetPos = 1;
|
||||
}
|
||||
else if (liftHeight >= thirdRange[0] && liftHeight <= thirdRange[1]) {
|
||||
armObjRange.targetPos = 2;
|
||||
else if (thirdRange.size() >= 2 && liftHeight >= thirdRange[0] && liftHeight <= thirdRange[1]) {
|
||||
return armObjRange.targetPos = 2;
|
||||
}
|
||||
else if (liftHeight >= fourthRange[0] && liftHeight <= fourthRange[1]) {
|
||||
armObjRange.targetPos = 3;
|
||||
else if (fourthRange.size() >= 2 && liftHeight >= fourthRange[0] && liftHeight <= fourthRange[1]) {
|
||||
return armObjRange.targetPos = 3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +182,10 @@ void LiftMech::set_ranges(std::vector<int> _firstRange, std::vector<int> _second
|
||||
fourthRange = _fourthRange;
|
||||
}
|
||||
|
||||
int LiftMech::get_lift_state() {return liftStates[currLiftState];}
|
||||
int LiftMech::get_lift_state() {
|
||||
if (!liftStates.empty()) {
|
||||
return liftStates[currLiftState];
|
||||
}
|
||||
}
|
||||
int LiftMech::get_num_lift_states() {return numLiftStates;}
|
||||
float LiftMech::get_lift_kp() {return liftKP;}
|
||||
Reference in new issue
Block a user