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:
Carter committed 2026-09-09 13:29:07 -04:00
1 parent c46a581eb1
commit 24ee947fd5
8 files changed
+340 -192

No files matched your search

+19 -8
View File
@@ -6,24 +6,35 @@
#include "EZ-Template/piston.hpp"
namespace ez {
enum class Pistons {
claw_piston
};
enum class ControlPeriod {
/**
* Enumeration to hold the current part of a match were in.
*/
enum class ControlPeriodP {
driver,
auton
};
enum class Controller {
/**
* Enumeration to hold the different controllers avalable.
*/
enum class ControllerP {
master,
slave
};
enum class Buttons {
/**
* Enumeration to hold the different buttons to use.
*/
enum class ButtonsP {
arrow_buttons,
Y_B_buttons,
left_shoulder_buttons,
right_shoulder_buttons
};
/**
* Enumeration to hold all the pistons avalable.
*/
enum class PistonsP {
claw_piston
};
class Pneumatics{
@@ -34,7 +45,7 @@ namespace ez {
Pneumatics();
void control_piston(enum Pistons, enum ControlPeriod, enum Controller, enum Buttons);
void control_piston(enum PistonsP, enum ControlPeriodP, enum ControllerP, enum ButtonsP);
bool get_piston_state();
void set_piston_state(bool value);
@@ -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();
+20 -10
View File
@@ -8,29 +8,39 @@
#define CONFIG_H
/**
*
* Sets up the master and slave controllers.
*/
inline pros::Controller master(pros::E_CONTROLLER_MASTER);
inline pros::Controller slave(pros::E_CONTROLLER_PARTNER);
/**
* Declare mechinism motors
* Declares mechinism motors and motor groups.
*/
inline pros::MotorGroup lift({10, 11});
inline pros::MotorGroup wrist({13, 14});
inline pros::Motor arm({12});
inline pros::MotorGroup lift({15, -19});
inline pros::MotorGroup wrist({1, 9});
inline pros::Motor arm({6});
/**
* Declare pistons here
* Declares piston mechanisms.
*/
inline ez::Piston claw({'G',true});
/**
* Declare sensors here
* Declare limit switches and other ADI sensors
*/
inline pros::Rotation liftRotation({15});
inline pros::Rotation armRotation({16});
inline pros::Rotation wristRotation({17});
inline pros::ADIButton liftReset({'A'});
inline pros::ADIButton armReset({'B'});
/**
* Declares all sensors.
*
* [1] - Rotation sensors
*
* [2] - Color sensors
*/
inline pros::Rotation liftRotation({17});
inline pros::Rotation armRotation({8});
inline pros::Rotation wristRotation({21});
inline pros::Optical colorSensorOne({18});
inline pros::Optical colorSensorTwo({19});