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
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user