Skip to content

Commit

Permalink
Add precalibrate functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethanol5455 committed Feb 24, 2024
1 parent 1c9fa48 commit a01e9b2
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class CatapultDeployStatus {
RemoveBlock,
Home,
PullBackFirst,
PullBackFirstPrecalibrated,
PlaceBlock,
PullBackSecond,
};
Expand Down Expand Up @@ -79,6 +80,15 @@ void handle_catapult_deploy()
deploy_timer.Restart();
}
break;
case CatapultDeployStatus::PullBackFirstPrecalibrated:
catapult_group.move_absolute(2100, MAX_RPM);
if (catapult_group.get_positions()[0] >= 2100 ||
deploy_timer.GetElapsedTime().AsSeconds() > 5.0) {
catapult_deploy_status =
CatapultDeployStatus::PlaceBlock;
deploy_timer.Restart();
}
break;
case CatapultDeployStatus::PlaceBlock:
catapult_block.move(-MAX_VOLTAGE);
if (deploy_timer.GetElapsedTime().AsMilliseconds() >= 500.0) {
Expand Down Expand Up @@ -106,6 +116,12 @@ void set_deploy_catapult()
deploy_timer.Restart();
}

void set_deploy_catapult_precalibrated() {
catapult_deploy_status = CatapultDeployStatus::PullBackFirstPrecalibrated;
deploy_timer.Restart();
catapult_group.tare_position();
}

void initCommon()
{
pros::lcd::initialize();
Expand Down Expand Up @@ -208,6 +224,7 @@ enum class AutoActionType {
IntakeSetExtend,
IntakeSpin,
DeployCatapult,
DeployCatapultPrecalibrated,
WaitForCatapultDeploy,
FireCatapultTime,
WaitForCatapultEngage,
Expand Down Expand Up @@ -326,6 +343,16 @@ class AutonomousSequence {
autonomous_steps.push_back(new_action);
}

void deploy_catapult_precalibrated()
{
AutoStep new_action;

new_action.action_type = AutoActionType::DeployCatapultPrecalibrated;
new_action.timeout_ms = 0;

autonomous_steps.push_back(new_action);
}

void wait_for_catapult_deploy(double timeout_ms = 10000)
{
AutoStep new_action;
Expand Down Expand Up @@ -449,6 +476,10 @@ class AutonomousSequence {
catapult_deployed_in_auto = true;
set_deploy_catapult();
break;
case AutoActionType::DeployCatapultPrecalibrated:
catapult_deployed_in_auto = true;
set_deploy_catapult_precalibrated();
break;
case AutoActionType::WaitForCatapultDeploy:
if (catapult_deploy_status ==
CatapultDeployStatus::NotDeploying) {
Expand All @@ -463,7 +494,7 @@ class AutonomousSequence {
catapult_block.brake();
if (catapult_group
.get_current_draws()[0] >
500) {
500 && auto_change_timer.GetElapsedTime().AsMilliseconds() > 200) {
num_ready_to_procede += 1;
}
break;
Expand Down Expand Up @@ -519,8 +550,13 @@ void autonomous()

AutonomousSequence auto_sequence;

// #define SKILLS_AUTO
// #define CALIBRATE_CATAPULT_AUTO
#define SKILLS_AUTO

#ifdef CALIBRATE_CATAPULT_AUTO
auto_sequence.wait_for_catapult_engage();
auto_sequence.wait_for_catapult_slip();
#else
#ifndef SKILLS_AUTO
// Grab starting triball
auto_sequence.move_position(-DRIVE_UNITS_PER_INCH * 1.5, MAX_RPM / 4.0,
Expand Down Expand Up @@ -575,7 +611,8 @@ void autonomous()
#else
auto_sequence.set_intake_extension(true, MAX_RPM, 250);
auto_sequence.set_intake_extension(false, MAX_RPM, 250);
auto_sequence.deploy_catapult();
// auto_sequence.deploy_catapult();
auto_sequence.deploy_catapult_precalibrated();
auto_sequence.wait_for_catapult_deploy();
auto_sequence.move_position(DRIVE_UNITS_PER_DEGREE * 25, 0,
MAX_RPM / 4.0, MAX_RPM / 4.0, 500);
Expand All @@ -597,6 +634,7 @@ void autonomous()
auto_sequence.set_intake_spin(0, 0);
auto_sequence.drive_speed(-MAX_VOLTAGE, 500);
auto_sequence.drive_speed(0, 0);
#endif
#endif

auto_sequence.run_auto();
Expand Down Expand Up @@ -634,7 +672,8 @@ void opcontrol()
initCommon();

if (!catapult_deployed_in_auto)
set_deploy_catapult();
// set_deploy_catapult();
set_deploy_catapult_precalibrated();

while (true) {
handle_catapult_deploy();
Expand Down

0 comments on commit a01e9b2

Please sign in to comment.