Pulling back Catapult while driving in autonomous (PROS)

I’m running into an issue where I have to pull the catapult back before moving to intake another disc, but I want to drive while doing so. would something like this work?

void Shoot() {
  CataAssist.set_value(true);
  pros::delay(20);
  Cata= 100;
  pros::delay(500);
  CataAssist.set_value(false);
  waitUntil(CataStop.get_value());
  Cata= 0;
}

Then, later in the code:

//*SHOOT
  Shoot();

  //*INTAKE TWO FROM TRIPPLE STACK

  chassis.set_drive_pid(-6, DRIVE_SPEED);
  chassis.wait_drive();
 
  chassis.set_turn_pid(28, TURN_SPEED);
  chassis.wait_drive();

I could be wrong, but I believe “pros::delay()” is blocking code, keeping you from continuing to drive. One way to run this asynchronously would be to use a state machine:

if (mCATA.get_position() > 0 && catapultState){
				mCATA = -127;
			}

if (mCATA.get_position() <= 0 && catapultState){
				catapultState = false;
				catapultRelease.set_value(catapultState);
			}
			
if (mCATA.get_position() < 1.9 && !catapultState){ 
				mCATA = 127;
			}

if (mCATA.get_position() >= 1.9 && !catapultState){
				mCATA = 0;
				mCATA.brake();
			}

Note: our catapult has a pneumatic release with a 1 or 0 held in the ‘catapultState’ boolean, and a Motor ‘mCATA’ that controlls the position/power of the catapult.
That allows us to either move the catapult up or down while still being able to drive around. If you are feeling more advanced, however, you can take the route my team did and look into creating a task. I don’t know all the technical info for that, so consult the Pros API if you wish to go that route.

I’ve been trying things like using if statements and while looos but it’s not really working. If I use a while my robot just doesn’t move and when I use if statements the cata just keeps shooting instead of stopping when down.

All I want to do is stop the catapult using our limit switch. It works flawlessly in driver control but I cant move the robot and pull back the catapult at the same time. I need something running in the background that way it doesnt mess with the rest of the autonomous. I’ve read up on tasks and things but its all so confusing to me, especially when it works just fine in driver control.

Yes, using tasks will help here. That way you can run the catapult independently from your drivetrain. We use C++, but PROS should be similar. You can initiate a new task for the catapult at the beginning of driver control (before the forever loop in drive control). In the catapult task you can have your logic check a button being pressed on the controller to fire the catapult, reload and stop the catapult once the limit switch is pressed.

3 Likes

This is for Autonomous.

Yes, same holds true when being used with autonomous. In the task you won’t be checking for a button press, but you can check for a value that indicates to fire the catapult, reload, and stop upon limit switch being pressed.

1 Like

I figured this out, and its actually quite simple.

First, make a function that only brings the arm down, lets call this BringArmDown(). Inside of this function, just have an if statemet to where if the limit switch is not pressed, rotate the arm. This is just a simple code to bring the arm down from shooting at the top.

In turn, to shoot from auto, you would need to make a function to fire the catapult, and then have it stop at the top (spin catapult, wait like 600 miliseconds, stop catapult), we will call this ShootCatapult().

Then with these functions, during auto, when you were to shoot, have the following code:

ShootCatapult();
BringArmDown();

However, to have the arm come down in a task inside of pros, change the code to look like this:

ShootCatapult();
pros::Task ArmTask1(BringArmDown);

Where ArmTask1 can be litterally any string of text, but for each time you call this task, add 1 to the number. This would allow for the next, lets say PID, in your autonomous code to run while the task of the BringArmDown function is running.

In addition, with the ShootCatapult function, you can add this same form of a task to make a momentum shot.

Hope this helps, and happy coding!!

1 Like