Skip to content

Commit 0246477

Browse files
RushilGhoshuakotaobisepehrnik7gmailcom
committed
Added code for a limit switch at the bottom of the
lift - The switch's purpose is to reset the lift's position to Default once it is pressed, this is to mitigate issues with the lift being shaken around by collisions during a match - We created a function hasLiftReachedBottom that checks the switch's input, we use it in the mobile goal states - It needs to be fixed because currently we continuously create references to the switch whenever we call it, this doesn't look clean - There is currently a memory permission error when the intake button is pressed while the lift is at Mobile Goal Height, the intake just keeps spinning without stopping Co-authored-by: uakotaobi <[email protected]> Co-authored-by: sepehrnik7gmailcom <[email protected]>
1 parent f85da37 commit 0246477

File tree

6 files changed

+51
-21
lines changed

6 files changed

+51
-21
lines changed

Diff for: 2024/prototype/intake_mechanisms/include/Ilift.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,21 @@ class Ilift {
8282
virtual bool isLiftSpinning() const = 0;
8383

8484
/**
85-
* Previously, the lift stops moving when it hits a physical barrier. Rubber
86-
* bands were added to overcome the slippage (the lift moved downwards
87-
* because the lift motor could not hold its position). Thus, rubber bands
88-
* were added to fight gravity.
85+
* Our robot's 'lift' is a lever that flips upward and over. Before
86+
* 2025-02-14, when moving the lift "down", this lever mechanism would be
87+
* physically stopped by metal hitting metal: the lift could not physically
88+
* move down further. We took advantage of that in order to transition from
89+
* the MOBILE_GOAL_DOWN state to the DEFAULT_LOWEST_HEIGHT state: all we had
90+
* to test was whether the lift motor stopped rotating!
8991
*
90-
* However, this strains the lift motor when moving down because the
91-
* physical barrier stopping it rubber bands. The lift doesn't fully stop
92-
* (sprongy-sprongy). Our state machines worked by checking whether the lift
93-
* has stopped spinning due to obstruction.
92+
* But after 2025-02-14, rubber bands were added to help resist the lift's
93+
* downward drift under load due to gravity. That caused a new problem: The
94+
* rubber bands physically restrain the lever from hitting the bottommost
95+
* point (where there used to be a *THUD*, there was not a *SPROING*.)
9496
*
95-
* Since, this is no longer valid due to the rubber bands preventing the
96-
* complete stop, we will use a limit switch to determine when the lift has
97-
* reached low enough.
97+
* So we can no longer rely on rotations stopping to let us know we've hit
98+
* rock bottom. That's why the team added a limit switch, and that's what
99+
* this function tests for.
98100
*/
99101
virtual bool hasLiftReachedBottom() const = 0;
100102

Diff for: 2024/prototype/intake_mechanisms/include/prototypes.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ class PivotRampPrototype : public Idrive, public Iintake, public Ilift,
5151
* solenoid for controlling pneumatic mobile goal grabber.
5252
* @param pneumaticsClimb A digital_out object connected to the
5353
* pneumatics responsible for the climb hooks.
54+
* @param limitSwitch A limit switch at the bottom of the lift that will
55+
* transition us out of the MOBILE_GOAL_DOWN state into the
56+
* DEFAULT_STATE.
57+
5458
*/
5559
PivotRampPrototype(const std::vector<vex::motor>& left_motors_,
5660
const std::vector<vex::motor>& right_motors_,
5761
const std::vector<vex::motor>& intake, const std::vector<vex::motor>& lift,
5862
double rotationsToTop, const vex::digital_out& pneumaticsClamp,
59-
const vex::digital_out& pneumaticsClimb);
63+
const vex::digital_out& pneumaticsClimb, const vex::limit& limitSwitch);
6064

6165
/**
6266
* Drive the robot at the given speeds.
@@ -120,6 +124,8 @@ class PivotRampPrototype : public Idrive, public Iintake, public Ilift,
120124

121125
bool isLiftAvailable() const;
122126

127+
bool hasLiftReachedBottom() const;
128+
123129
LiftHeights liftHeights() const {
124130
return liftHeights_;
125131
}
@@ -146,6 +152,7 @@ class PivotRampPrototype : public Idrive, public Iintake, public Ilift,
146152
public: // Temporary for testing
147153
vex::digital_out pneumaticClamp;
148154
vex::digital_out pneumaticClimb;
155+
vex::limit limitSwitch;
149156
};
150157

151158
#endif // (ifndef __PROTOTYPE_H_INCLUDED__)—

Diff for: 2024/prototype/intake_mechanisms/include/robot-config.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const auto gearbox_ratio = ratio6_1;
2222
const double autonomous_speed_pct = 15.0;
2323

2424
// PID Controller constants for the Turn Task.
25-
const double TURN_TASK_P_GAIN = 9 * 1e-4;
25+
const double TURN_TASK_P_GAIN = 5.9 * 1e-4;
2626
const double TURN_TASK_I_GAIN = 0;
2727
const double TURN_TASK_D_GAIN = 0;
2828

@@ -39,9 +39,13 @@ const double LIFT_VELOCITY_PERCENT = 50.0;
3939
const int CONTROLLER_LIFT_STATE_ROW = 1;
4040
const int CONTROLLER_LIFT_POSITION_ROW = 2;
4141
const int CONTROLLER_ROBOT_STOPPED_ROW = 3;
42+
const int CONTROLLER_LIMIT_SWITCH_ROW = 4;
43+
const int CONTROLLER_LIFT_LIMIT_SWITCH_COLUMN = 5;
44+
4245
const int BRAIN_CLAMP_VALUE_ROW = 5;
4346
const int BRAIN_LIFT_POSITION_ROW = 6;
4447

48+
4549
/**
4650
* Deadzones the intake speed velocities, meaning if they are below a certain
4751
* threshold, we treat it as if it were 0.
@@ -62,6 +66,7 @@ const double MOBILE_GOAL_INTAKE_DURATION_MILLISECONDS = 200;
6266
*/
6367
const double TURN_TASK_EPSILON_DEGREES = 1;
6468

69+
6570
/**
6671
* Used to initialize code/tasks/devices added using tools in VEXcode Text.
6772
*

Diff for: 2024/prototype/intake_mechanisms/src/main.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,31 @@ PivotRampPrototype makePivotRampPrototype() {
131131
vex::motor liftMotor1(LIFT_MOTOR_PORT);
132132
vector<motor> liftMotors = {liftMotor1};
133133

134-
const double rotationsToTop = 6; //This value has been determined experimentally.
134+
const double rotationsToTop = 1.5; //This value has been determined experimentally.
135135

136136
vex::triport::port DOUBLE_SOLENOID_PORT = Seventeen59A.ThreeWirePort.C;
137137
digital_out pneumaticClamp(DOUBLE_SOLENOID_PORT);
138138

139-
vex::triport::port CLIMB_PORT = Seventeen59A.ThreeWirePort.B;
139+
vex::triport::port CLIMB_PORT = Seventeen59A.ThreeWirePort.G;
140140
digital_out pneumaticClimb(CLIMB_PORT);
141141

142+
vex::triport::port SWITCH_PORT = Seventeen59A.ThreeWirePort.B;
143+
vex::limit limitSwitch(SWITCH_PORT);
144+
142145
PivotRampPrototype p(leftMotors,
143146
rightMotors,
144147
intakeMotors,
145148
liftMotors,
146149
rotationsToTop,
147150
pneumaticClamp,
148-
pneumaticClimb);
151+
pneumaticClimb,
152+
limitSwitch);
149153
p.setLiftHeights({
150154
// These values have been determined experimentally.
151155
.defaultHeight = 0,
152-
.mobileGoalHeight = 0.56,
156+
.mobileGoalHeight = 0.46,
153157
.allianceStakeHeight = rotationsToTop,
154-
.wallStakeHeight = 3.6
158+
.wallStakeHeight = 1.3
155159
});
156160
return p;
157161
}

Diff for: 2024/prototype/intake_mechanisms/src/prototypes.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ PivotRampPrototype::PivotRampPrototype(const std::vector<vex::motor>& left_motor
9191
const std::vector<vex::motor>& right_motors_,
9292
const std::vector<vex::motor>& intake_, const std::vector<vex::motor>& lift_,
9393
double rotToTop, const vex::digital_out& pneumaticClamp_,
94-
const vex::digital_out& pneumaticClimb_)
94+
const vex::digital_out& pneumaticClimb_, const vex::limit& limitSwitch_)
9595
: left_motors(left_motors_), right_motors(right_motors_),
9696
intake_motors(intake_), lift_motors(lift_), rotationsToTop(rotToTop), pneumaticClamp(pneumaticClamp_),
97-
pneumaticClimb(pneumaticClimb_) {
97+
pneumaticClimb(pneumaticClimb_), limitSwitch(limitSwitch_) {
9898
// Where we are right now -- the initialLiftPosition -- will now
9999
// correspond to an encoder value of zero.
100100
for_each(lift_motors.begin(), lift_motors.end(), [](motor& current_motor) {
@@ -223,6 +223,16 @@ bool PivotRampPrototype::isLiftAvailable() const {
223223
return !lift_motors.empty();
224224
}
225225

226+
bool PivotRampPrototype::hasLiftReachedBottom() const {
227+
// PivotRampPrototype* that = const_cast<PivotRampPrototype*>(this);
228+
// int limitSwitchValue = that->limitSwitch.value();
229+
vex::limit input(Seventeen59A.ThreeWirePort.B);
230+
Controller.Screen.setCursor(CONTROLLER_LIMIT_SWITCH_ROW, CONTROLLER_LIFT_LIMIT_SWITCH_COLUMN);
231+
Controller.Screen.print("%d [%s]", input.value(), (input ? "true" : "false")); // Ternary operator
232+
// Controller.Screen.print<int>(limitSwitchValue);
233+
return input.value();
234+
}
235+
226236
void PivotRampPrototype::clamp(bool active) {
227237
this->pneumaticClamp.set(active);
228238
}

Diff for: 2024/prototype/intake_mechanisms/src/updateLiftState.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ void updateLiftState(
102102
} else {
103103
robotWithLift.moveLiftDirect(0);
104104
}
105+
robotWithLift.hasLiftReachedBottom();
105106
break;
106107

107108
case LiftState::MOBILE_GOAL_UP:
109+
robotWithLift.hasLiftReachedBottom();
108110
if (!robotWithLift.isLiftSpinning()) {
109111
robotWithLift.moveLiftDirect(0);
110112
if (!upButton) {
@@ -115,7 +117,7 @@ void updateLiftState(
115117
break;
116118

117119
case LiftState::MOBILE_GOAL_DOWN: // Heading down to the lowest height
118-
if (!robotWithLift.isLiftSpinning()) {
120+
if (robotWithLift.hasLiftReachedBottom()) {
119121
robotWithLift.moveLiftDirect(0);
120122
if (!downButton) {
121123
state = LiftState::DEFAULT_LOWEST_HEIGHT;

0 commit comments

Comments
 (0)