1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
IntakeAntiJam.cpp
Go to the documentation of this file.
1// Copyright 2026 California High Robotics, Team 1516X
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "IntakeAntiJam.h"
5#include "pros/rtos.hpp"
6#include "globals.h"
7
8IntakeAntiJam::IntakeAntiJam(pros::Motor& i_motor, pros::Motor& o_motor, pros::Motor& s_motor, int temp)
9 : intakeMotor(i_motor), outtakeMotor(o_motor), storageMotor(s_motor), maxTemp(temp)
10{
11 cmd_intake = 0;
12 cmd_outtake = 0;
13 cmd_storage = 0;
14
15 jam_trigger_loops = 15;
16 reverse_duration_ms = 250;
17
18 jam_counter = 0;
19 is_unjamming = false;
20 anti_jam_enabled = true;
21}
22
23void IntakeAntiJam::enable_anti_jam(bool enable) {
24 anti_jam_enabled = enable;
25
26 if (!anti_jam_enabled) {
27 jam_counter = 0;
28 }
29}
30
31void IntakeAntiJam::set_velocities(float i_vel, float o_vel, float s_vel) {
32 cmd_intake = i_vel;
33 cmd_outtake = o_vel;
34 cmd_storage = s_vel;
35
36 if (!is_unjamming) {
37 intakeMotor.move_velocity(cmd_intake);
38 outtakeMotor.move_velocity(cmd_outtake);
39 storageMotor.move_velocity(cmd_storage);
40 }
41}
42
43void IntakeAntiJam::stop() {
44 set_velocities(0, 0, 0);
45 if (!is_unjamming) {
46 intakeMotor.brake();
47 outtakeMotor.brake();
48 storageMotor.brake();
49 }
50}
51
52void IntakeAntiJam::update() {
53 double max_t = std::max({intakeMotor.get_temperature(),
54 outtakeMotor.get_temperature(),
55 storageMotor.get_temperature()});
56 if (max_t > maxTemp) {
57 intakeMotor.move_velocity(0);
58 outtakeMotor.move_velocity(0);
59 storageMotor.move_velocity(0);
60 return;
61 }
62
63 if (!anti_jam_enabled || matchloader.is_extended()) {
64 jam_counter = 0;
65 return;
66 }
67
68 bool is_stuck = false;
69
70 if (std::abs(cmd_intake) > 0) {
71 std::int32_t intake_eff = intakeMotor.get_efficiency();
72 if (intake_eff >= 7 && intake_eff <= 20) {
73 is_stuck = true;
74 }
75 }
76
77 if (std::abs(cmd_storage) > 0) {
78 std::int32_t storage_eff = storageMotor.get_efficiency();
79 if (storage_eff >= 7 && storage_eff <= 20) {
80 is_stuck = true;
81 }
82 }
83
84 if (is_stuck) {
85 jam_counter++;
86 } else {
87 jam_counter = 0;
88 }
89
90 if (jam_counter > jam_trigger_loops) {
91 is_unjamming = true;
92
93 intakeMotor.move_velocity(-cmd_intake);
94 outtakeMotor.move_velocity(0);
95 if(!intake_lift.is_extended())
96 {
97 storageMotor.move_velocity(0);
98 }
99 else {
100 storageMotor.move_velocity(-cmd_storage);
101 }
102
103
104 pros::delay(reverse_duration_ms);
105
106 intakeMotor.move_velocity(cmd_intake);
107 outtakeMotor.move_velocity(cmd_outtake);
108 storageMotor.move_velocity(cmd_storage);
109
110 jam_counter = 0;
111 is_unjamming = false;
112
113 pros::delay(150);
114 }
115}
pros::adi::Pneumatics matchloader('C', false)
pros::adi::Pneumatics intake_lift('A', false)
pros::Motor storageMotor(2, pros::v5::MotorGears::blue)
pros::Motor outtakeMotor(3, pros::MotorGears::blue)
pros::Motor intakeMotor(-1, pros::v5::MotorGears::blue)