Easy C Autonomous using encoders

kay guys i need help big time, i have been trying to get my robot to drive 100 tick and then stop using encoders on my 2 front wheels (some images in the link here: https://vexforum.com/t/17c-dr4b-preview/28083/1 )
I have tried using while and if/else loops to get it to work but have not gotten anywhere in the hours that I have tried.
if anyone wouldn’t mind checking out my Easy C program that would be awesome, cause i have my competition in a week lol.

Here is my project if you so like to look at:
17C_competition_project-2015-01-08.zip (62.9 KB)

Well, there really is no code in that project trying to drive forward 100 ticks.

100 ticks is a short distance, 2-3 inches usually (depends on gearing etc.)

The general form of code to do this type of thing is.

// Drive forwards 1000 counts - assumes the encoder count increases as you drive forward 
PresetQuadEncoder ( 3 , 4 , 0) ;// Set encoder back to 0
while ( GetQuadEncoder( 3, 4 ) < 1000 )
    {
    AUTO_Drive_foraward ( ) ;
    Wait ( 25 ) ;
    }
    
// Stop the drive - you need to make this user function, send 0 to all motors 
AUTO_Drive_Stop ( ) ;

If the encoder count decrements when going forwards then swap the two encoder cable digital ports (ie. rewire them on the cortex).

In easy C we have really nice basic blocks that help out with small things like this.
Theres a block that does this for you.

pic: https://drive.google.com/file/d/0B4Ncpd5mvXJ8OTdGVmZyZmtTbXc/view?usp=sharing

The block works as a wait block(in timed autonomous) but it waits until the encoder is 100 ticks instead of x amount of time.

here correction here is what i did in the pic
17c competition pic thing.jpg

Is it not working?

If not you can always take away the if encoder==1 and replace it with the smart task block i mentioned earlier and put auto drive stop under the smart task block.

DRIVE_Left_Encoder is just a variable, it does not change just because you assigned a value to it once, you need to update that in the loop as well.

Also the if statement only is evaluated once, then you go to the next statement.
You would need a while loop like this.

      PresetQuadEncoder ( 1 , 2 , 0) ; // // Set encoder back to 0
      DRIVE_left_Encoder = GetQuadEncoder ( 1 , 2 ) ;
      AUTO_Drive_foraward ( ) ;
      while ( DRIVE_Left_Encoder < 100 )
      {
            DRIVE_left_Encoder = GetQuadEncoder ( 1 , 2 ) ;
            Wait ( 25 ) ;
      }
      // Stop the drive - you need to make this user function, send 0 to all motors 
      AUTO_Drive_Stop ( ) ;

Stanley’s way is more efficient using the built in smart functions.

thanks guys i will try it out as soon as i can put my wheels back on :slight_smile:

here will this work?
17c encoder thing 2.jpg

It should, as long as when the drive moves forward the encoder value increases positively.

If that happens it will work.