EasyC project

Hey, i’ve been using this set up for my autonomous period during competition.
My program uses 2 Quadcore encoders.
It worked when I programmed for regular shaft encoders, but when i switched to quadcore commands, nothing’s working
I didnt change any hardware-just plugged in the second wire and programmed appropriately for it.
Right now the program just trys to lift both joints of my arm without stopping. It used to just raise the arm to a certain position. The problem function is called Armset

Thanks in advance,
Andrew

PS. I checked my old program’s armset, and it’s exactly the same set up except regular shaft encoders
D21.zip (2.29 KB)

Well for the quadrature encoders, everything works the same except for the fact that now you can check the direction of the movement.

Looking through code, I came upon a couple of issues that I would like to bring up. Lets see…

  • First of all, I believe there could be an issue with your if else statements values. Remember the quadrature encoders are able to read negative values as well as positive and since you have your code based off of positive encoder values this might be an issue. I have changed the if statements so that they incorporate both directions (negative and positive).
  • Your “If” and “Else If” statements are not structure correctly… All I would do in this case is change the “else if” to just “else” and you should be fine.
  • Another minor problem, is the break command. This statement could due to the fact that during execution the second arm might reach its position first (assuming main arm gets stuck) and then you will only have the second arm extended with the main arm in its initial position. Although chances of this happening are low, I would change it nevertheless. To change it, I created two new variables initially set at a value of 1 (lets say finished1 and finished2). So lets say I place an assignment block in each “else” loop. One stating “finished1 = 0” and the other stating “finished2 = 0” Then at the very end of a code I would place a statement saying that if “finished1 == 0 && finished2 == 0” then break… You will understand it much better once you see it.
  • I have also included two printf statements in your code that will tell you what direction the quadrature encoders are reading. (negative or positive)

I have modified and attached the code below. If you have any other questions, just ask.

Technic-R-C

btw I have EasyCPro, so if you can’t open it I’ve also pasted the code below. I will attach the zip file in a couple of minutes.

#include "Main.h"

void Armset ( unsigned long armset )
{
      int secondarm; 
      int mainarm; 
      int finished = 1; 
      int finishedone = 1; 

      // Interrupt 1 is second arm 
      // Interrupt 2 is main arm 
      StartQuadEncoder ( 1 , 5 , 1 ) ;
      StartQuadEncoder ( 2 , 6 , 0 ) ;
      // StartQuads goes before preset 
      PresetQuadEncoder ( 1 , 5 , 0) ;
      PresetQuadEncoder ( 2 , 6 , 0) ;
      while ( 1 )
      { // moves both arms at same time
            secondarm = GetQuadEncoder ( 1 , 5 ) ;
            mainarm = GetQuadEncoder ( 2 , 6 ) ;
            // Check Quad Direction (Negative or Positive) 
            PrintToScreen ( "Second Arm =       %d\n" , (int)secondarm ) ;
            PrintToScreen ( "Mainarm =       %d\n" , (int)mainarm ) ;
            if ( mainarm < 6 || mainarm > -6 )
            {
                  SetPWM ( 5 , 0 ) ;
            }
            else
            {
                  SetPWM ( 5 , 127 ) ;
                  StopQuadEncoder ( 2 , 6 ) ;
                  finished = 0 ;
            }
            if ( secondarm < 22 || secondarm > -22 )
            {
                  SetPWM ( 6 , 0 ) ;
            }
            else
            {
                  SetPWM ( 6 , 127 ) ;
                  StopQuadEncoder ( 1 , 5 ) ;
                  finishedone = 0 ;
            }
            // This is the part where the code checks whether or not both arms have moved to their position 
            if ( finished == 0 && finishedone == 0 )
            {
                  PrintToScreen ( "Finished\n" ) ;
                  break ;
            }
      }
}

Alright, thanks for the help. I’m going to try these changes out.
I was thinking maybe instead of using positive and negative values, that if i just inverted each encoder again it might work…but ill try it your way.
thanks for picking up on my whole break command problem, that’s what confused me the most when i first wrote the program.
ill get back to on my results
thanks again,
Andrew

No prob,

This could potentially work, but I prefer changing a number in the code rather than a mechanical setup.

Technic-R-C

I believe you can swap the two cables coming from the encoder, and that will effectively invert the value.

  • Dean

Good catch! I didn’t even think of that…

There you have it, 3 ways to change the readings coming in from the encoder.

Technic-R-C

Thanks Quazar, your quick-fix worked the best.
And to Technic for teachin me more

One more thing…
when programming the encoders, does the preset command go first, or does the start? i think i read somewhere that start goes first, but when i looked at the encoder test, it had preset coming first…

I always put start before preset… this makes sense because you first have to initialize something and then later on preset it. I included this format in the code I posted below.

Technic-R-C

hmmm…i always thought of it like, you preset the pins before you start bowling… bad example though. maybe i should post in an official forum?

I tryed to implement a code with the ‘finished’ assignments, but when i stuck it in with the rest of my functions, it wouldn’t continue to the next function. I’ll post my code below, please check it out.

After completing the Armset function, it won’t continue to SCORE
D15redmove.zip (2.66 KB)

From the comments in your code it looks like we got the first part hammered out.

Now lets get down to your next problem…

Lets see…

  1. From what I see this looks like your code for the autonomous mode… however when I go into your autonomous function I see no code inside the C source file… This means that nothing is running when you upload the code to your bot.

So how about we start off with this…

Out of the functions you currently have created, which ones do you want to run during autonomous and in what order? In other words, what do you want your autonomous to do?

Once we get this figured out, I can help you work out the order in which the functions are called, etc.

Technic-R-C

I want the autonomous to preform the Armset Function, then SCORE, then after the motor commands, Move.

When i reverted back to having the break command in the else of my armset function, it continued to my other functions in order afterwards. however, i’d still like to know how to properly call functions in the order i posted above