I uncoommented all the code to use the lift with the rotation sensor. Next I need to make it more usable and intuitive to setup.
This commit is contained in:
1 parent
3bbad07dea
commit
7bf206c454
5 files changed
+154
-21
No files matched your search
@@ -57,7 +57,8 @@ namespace ez {
|
||||
*
|
||||
* \param controlPeriodM
|
||||
* The current control period were in
|
||||
*
|
||||
* \param controllerM
|
||||
*
|
||||
*
|
||||
*/
|
||||
void motor_control(enum ControlPeriodM, enum ControllerM, enum ButtonsM, enum MotorGroups, float fw_motor_speed, float rev_motor_speed);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <vector>
|
||||
#include "api.h"
|
||||
//#include "main.h"
|
||||
#include "pros/adi.hpp"
|
||||
#include "pros/rotation.hpp"
|
||||
|
||||
@@ -79,10 +78,6 @@ namespace ez{
|
||||
class LiftMech {
|
||||
private:
|
||||
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;
|
||||
|
||||
@@ -101,10 +96,10 @@ namespace ez{
|
||||
void cycle_states();
|
||||
void reset_state();
|
||||
void lift_control(); // Computes the velocity for the lift to move at.
|
||||
int lift_range_finder(); // Finds the ranges for the arm to use
|
||||
//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);
|
||||
//void set_ranges(std::vector<int> _firstRange, std::vector<int> _secondRange, std::vector<int> _thirdRange, std::vector<int> _fourthRange);
|
||||
|
||||
int get_lift_state();
|
||||
int get_num_lift_states();
|
||||
|
||||
@@ -38,7 +38,7 @@ inline ez::Piston PlaceHolder({'G',true});
|
||||
*
|
||||
* [2] - Color sensors
|
||||
*/
|
||||
inline pros::Rotation liftRotation({0});
|
||||
inline pros::Rotation liftRotation({18});
|
||||
inline pros::Rotation armRotation({0});
|
||||
inline pros::Rotation wristRotation({0});
|
||||
|
||||
|
||||
@@ -2,6 +2,145 @@
|
||||
#include "EZ-Template/rotation_mechanisms/rotation_calc.hpp"
|
||||
|
||||
using namespace ez;
|
||||
|
||||
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;
|
||||
currLiftState = 0;
|
||||
liftTarget = 0;
|
||||
set_lift_kp(0.0173f);
|
||||
}
|
||||
|
||||
void LiftMech::lift_driver_control(ControllerR currController, ButtonsR buttonUsed) {
|
||||
switch (currController)
|
||||
{
|
||||
case ControllerR::slave:
|
||||
|
||||
switch (buttonUsed)
|
||||
{
|
||||
case ButtonsR::arrow_buttons:
|
||||
if (master.get_digital(DIGITAL_RIGHT)) {
|
||||
lift.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_DOWN)) {
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
case ButtonsR::Y_B_buttons:
|
||||
if (master.get_digital(DIGITAL_Y)) {
|
||||
lift.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_B)) {
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
case ButtonsR::left_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
lift.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
case ButtonsR::right_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
lift.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
lift.move(-127);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ControllerR::master:
|
||||
|
||||
switch (buttonUsed)
|
||||
{
|
||||
case ButtonsR::arrow_buttons:
|
||||
if (slave.get_digital(DIGITAL_RIGHT)) {
|
||||
cycle_states();
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_DOWN)) {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case ButtonsR::Y_B_buttons:
|
||||
if (slave.get_digital(DIGITAL_Y)) {
|
||||
cycle_states();
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_B)) {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case ButtonsR::left_shoulder_buttons:
|
||||
if (slave.get_digital(DIGITAL_L1)) {
|
||||
cycle_states();
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_L2)) {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case ButtonsR::right_shoulder_buttons:
|
||||
if (slave.get_digital(DIGITAL_R1)) {
|
||||
cycle_states();
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_R2)) {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LiftMech::cycle_states() {
|
||||
currLiftState ++;
|
||||
|
||||
if (!liftStates.empty()) {
|
||||
if (currLiftState == numLiftStates) {
|
||||
currLiftState = 0;
|
||||
}
|
||||
liftTarget = liftStates[currLiftState];
|
||||
}
|
||||
}
|
||||
void LiftMech::reset_state() {
|
||||
currLiftState = 0;
|
||||
|
||||
if (!liftStates.empty()) {
|
||||
liftTarget = liftStates[currLiftState];
|
||||
}
|
||||
}
|
||||
|
||||
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_num_lift_states() {return numLiftStates;}
|
||||
float LiftMech::get_lift_kp() {return liftKP;}
|
||||
|
||||
/*
|
||||
ArmMech armObjRange;
|
||||
|
||||
|
||||
+10
-12
@@ -39,12 +39,12 @@ namespace ez {
|
||||
};
|
||||
}
|
||||
// Lift constructor
|
||||
/*LiftMech liftObj(
|
||||
LiftMech liftObj(
|
||||
|
||||
{0, 63194, 94246, 139878}, 4);
|
||||
{0, }, 4);
|
||||
|
||||
// Wrist constructor
|
||||
WristMech wristObj(
|
||||
/*WristMech wristObj(
|
||||
|
||||
{0, -14529}, 2);*/
|
||||
|
||||
@@ -73,15 +73,13 @@ void initialize() {
|
||||
{139878, 150000}
|
||||
);
|
||||
|
||||
armRotation.reset_position();
|
||||
armRotation.reset_position();*/
|
||||
liftRotation.reset_position();
|
||||
wristRotation.reset_position();*/
|
||||
//wristRotation.reset_position();
|
||||
|
||||
/*pros::Task liftControlTasck([&]{
|
||||
while (true) {
|
||||
armObj.arm_control();
|
||||
liftObj.lift_control();
|
||||
wristObj.wrist_control();
|
||||
pros::delay(10);
|
||||
}
|
||||
});*/
|
||||
@@ -354,14 +352,14 @@ void opcontrol() {
|
||||
}
|
||||
else {
|
||||
wrist.brake();
|
||||
}
|
||||
}*/
|
||||
//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);*/
|
||||
//wristObj.rotate_wrist(90);
|
||||
|
||||
chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
|
||||
// chassis.opcontrol_tank(); // Tank control
|
||||
@@ -370,10 +368,10 @@ void opcontrol() {
|
||||
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade
|
||||
|
||||
// Terminal debugging
|
||||
/*std::cout << "Arm rotation sensor value: " << "\033[31m" << armRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
//std::cout << "Arm rotation sensor value: " << "\033[31m" << armRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
std::cout << "Lift rotation sensor value: " << "\033[32m" << liftRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
std::cout << "Wrist rotation sensor value: " << "\033[33m" << wristRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
std::cout << "Arm limit switch value: " << "\033[34m" << armReset.get_value() << "mm\033[0m" << std::endl;*/
|
||||
//std::cout << "Wrist rotation sensor value: " << "\033[33m" << wristRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
//std::cout << "Arm limit switch value: " << "\033[34m" << armReset.get_value() << "mm\033[0m" << std::endl;*/
|
||||
|
||||
///pros::delay(250);
|
||||
pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME
|
||||
|
||||
Reference in new issue
Block a user