VEXcode Pro goal rush issue

I’ve recently been trying to learn how to program using VEXcode Pro (all I’ve used before is blocks) and have already programmed the basic functions of the robot (drivetrain, mogo lift, fourbar, clamp). When I was trying to replicate the autonomous code we have in blocks I ran into an issue.
autonc++
I want the autonomous to clamp while going forward the 55 inches, completely travel the 55 inches, and then perform the rest of the commands. However, the code is waiting the 1.1 seconds, clamping, and then immediately going backwards. How would I go about fixing this?

At which part of moving 55 inches forwards do you want the clamp to start moving?

1 Like

I want it to clamp down after it has been moving forward for 1.1 seconds.

One thing you should look into are threads. You could start a thread right before moving forwards and just make it wait 1.1 seconds (in the thread). It’ll work in sync with the moving forwards.
I asked about this a few days ago: How to use VEX Threads - Programming Support / VEXcode Pro V5 Text Tech Support - VEX Forum. It has more explanation and resources.

1 Like

Before the “reverse 40 inches”, you’ll need to wait for the asynchronous “forward 55 inches” to complete.

3 Likes

look into this.

      /** 
       * @brief Checks to see if any of the motors are rotating to a specific target.
       * @return Returns a true Boolean if the motor is on and is rotating to a target. Returns a false Boolean if the motor is done rotating to a target.
       */
      virtual bool 	isMoving( void );
5 Likes

The program I have in the image above does clamp along with going forward, but the drive backwards command overrides the rest of the distance after it clamps.

The fourth parameter of the driving forwards 55 inches command is false, which means it runs, but doesn’t check to see if it has been completed before going onto the next command.
This means it’ll immediately go onto the next instruction: wait(1.1, seconds).
After 1.1 seconds, it’ll immediately set the two cylinders to true, and then move reverse, which overrides the previous instruction.

3 Likes

I think there is a function like Drivetrain.is_done(). If you did

cylinder1 & 2 turn off
driveFor(55, inches, false) 
// It will move onto the next commands without waiting for completion
wait(1.1)
cylinder1 & 2 turn on
waitUntil(Drivetrain.is_done())
driveFor(reverse, 40, inches)

I think it would do what you want. This is not working code, obviously, so you’ll have to find the is_done() and waitUntil() functions yourself, but I think this is what you want.

3 Likes

This is what I want, I’ll experiment with it