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
@@ -2,28 +2,43 @@
|
||||
|
||||
#include <vector>
|
||||
#include "api.h"
|
||||
//#include "main.h"
|
||||
#include "pros/adi.hpp"
|
||||
#include "pros/rotation.hpp"
|
||||
|
||||
namespace ez{
|
||||
|
||||
enum class ControlPeriod {
|
||||
/**
|
||||
* Enumeration to hold the current part of a match were in.
|
||||
*/
|
||||
enum class ControlPeriodR {
|
||||
driver,
|
||||
auton
|
||||
};
|
||||
enum class Controller {
|
||||
/**
|
||||
* Enumeration to hold the different controllers avalable.
|
||||
*/
|
||||
enum class ControllerR {
|
||||
master,
|
||||
slave
|
||||
};
|
||||
enum class Buttons {
|
||||
/**
|
||||
* Enumeration to hold the different buttons to use.
|
||||
*/
|
||||
enum class ButtonsR {
|
||||
arrow_buttons,
|
||||
Y_B_buttons,
|
||||
left_shoulder_buttons,
|
||||
right_shoulder_buttons
|
||||
};
|
||||
|
||||
/**
|
||||
* Arm mechanism class.
|
||||
*
|
||||
* Sets up all constructors, variables, and functions.
|
||||
*/
|
||||
class ArmMech{
|
||||
private:
|
||||
// Arrays to hold different values for the arm.
|
||||
std::vector<int> levelOneArmStates;
|
||||
std::vector<int> levelTwoArmStates;
|
||||
std::vector<int> levelThreeArmStates;
|
||||
@@ -32,20 +47,20 @@ namespace ez{
|
||||
float armKP;
|
||||
|
||||
public:
|
||||
std::vector<int> selectedStates;
|
||||
int targetPos;
|
||||
std::vector<int> selectedStates; // Array for the arm to actaully use.
|
||||
int targetPos; // Value to be changed based on the height of the lift
|
||||
int currArmState;
|
||||
int armTarget;
|
||||
float armError;
|
||||
float armVelocity;
|
||||
|
||||
ArmMech();
|
||||
ArmMech(); // Defualt constructor
|
||||
|
||||
void arm_driver_control(enum Controller, enum Buttons);
|
||||
void arm_driver_control(enum ControllerR, enum ButtonsR);
|
||||
void arm_auton_control(int pickState);
|
||||
void cycle_states();
|
||||
void reset_state();
|
||||
void arm_control();
|
||||
void arm_control(); // Computes the velocity for the arm to move at.
|
||||
|
||||
void set_arm_kp(float _armKP);
|
||||
void set_state_values(std::vector<int> _levelOneArmStates, std::vector<int> _levelTwoArmStates, std::vector<int> _levelThreeArmStates, std::vector<int> _levelFourArmStates);
|
||||
@@ -55,32 +70,37 @@ namespace ez{
|
||||
float get_arm_kp();
|
||||
};
|
||||
|
||||
/**
|
||||
* List mechanism class.
|
||||
*
|
||||
* Sets up all constructors, variables, and functions.
|
||||
*/
|
||||
class LiftMech {
|
||||
private:
|
||||
std::vector<int> liftStates;
|
||||
int numLiftStates;
|
||||
float liftKP;
|
||||
std::vector<int> liftStates; // Array the lift uses to move.
|
||||
std::vector<int> firstRange;
|
||||
std::vector<int> secondRange;
|
||||
std::vector<int> thirdRange;
|
||||
std::vector<int> fourthRange;
|
||||
int numLiftStates;
|
||||
float liftKP;
|
||||
|
||||
public:
|
||||
int liftHeight; // Current height of the lift in centdegrees
|
||||
int currLiftState;
|
||||
int liftTarget;
|
||||
int liftHeight;
|
||||
float liftError;
|
||||
float liftVelocity;
|
||||
|
||||
LiftMech();
|
||||
LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates);
|
||||
LiftMech(); // Default constructor
|
||||
LiftMech(std::initializer_list<int> _liftStates, int _numLiftStates); // Constructor to initialze array and amount of values in array.
|
||||
|
||||
void lift_driver_control(enum Controller, enum Buttons);
|
||||
void lift_driver_control(enum ControllerR, enum ButtonsR);
|
||||
void lift_auton_control(int pickState);
|
||||
void cycle_states();
|
||||
void reset_state();
|
||||
void lift_control();
|
||||
void lift_range_finder();
|
||||
void lift_control(); // Computes the velocity for the lift to move at.
|
||||
int lift_range_finder(); // Finds the ranges for the arm to use
|
||||
|
||||
void set_lift_kp(float _liftKP);
|
||||
void set_ranges(std::vector<int> _firstRange, std::vector<int> _secondRange, std::vector<int> _thirdRange, std::vector<int> _fourthRange);
|
||||
@@ -90,9 +110,14 @@ namespace ez{
|
||||
float get_lift_kp();
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrist mechanism class.
|
||||
*
|
||||
* Sets up all constructors, variables, and functions.
|
||||
*/
|
||||
class WristMech {
|
||||
private:
|
||||
std::vector<int> wristStates;
|
||||
std::vector<int> wristStates; // Array the wrist uses to move
|
||||
int numWristStates;
|
||||
float wristKP;
|
||||
|
||||
@@ -102,12 +127,12 @@ namespace ez{
|
||||
float wristError;
|
||||
float wristVelocity;
|
||||
|
||||
WristMech();
|
||||
WristMech(std::initializer_list<int> _wristStates, int _numWristStates);
|
||||
WristMech(); // Default constuctor
|
||||
WristMech(std::initializer_list<int> _wristStates, int _numWristStates); // Constructor to initialze array and amount of values in array.
|
||||
|
||||
void wrist_driver_control(enum Controller, enum Buttons);
|
||||
void wrist_driver_control(enum ControllerR, enum ButtonsR);
|
||||
|
||||
void rotate_wrist(int wristThreshold);
|
||||
void rotate_wrist(int wristThreshold); // Rotates the wrist based where the arm is.
|
||||
void reset_state();
|
||||
void wrist_control();
|
||||
|
||||
|
||||
Reference in new issue
Block a user