Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   No Signal From Gyro (http://www.chiefdelphi.com/forums/showthread.php?t=30758)

colt527 14-10-2004 19:40

No Signal From Gyro
 
First, thanks in advance for taking the time to read this. Here is our problem. For the past week we have been trying to use a gyro to help our robot go strait in autonomous control. We have 2 Gyros and we wrote the code for the EDU bot for initial testing and have 2 working gyro control codes. So we thought it was time to impliment them into our competition bot from last year. Basically we just copied the code from the EDU bot into the User_Autonomous function in user_routine_fast.c on our competion. Here is 1 version of the code we put in that worked perfectly on the EDU bot:

Code:

//CODE OMMITTED FOR POSTING PURPOSES

//Gyro Variables Located at top of user_routines_fast.c

long int gyro_input;
long int gyro_error = 0;
unsigned int left_speed = 175;
unsigned int right_speed = 175;

#define LEFT_START_SPEED 175
#define RIGHT_START_SPEED 175
#define ACCEPT_ERROR 70
#define TURN_SPEED 1

//CODE OMMITTED FOR POSTING PURPOSES

void User_Autonomous_Code(void)
{
  /* Initialize all PWMs and Relays when entering Autonomous mode, or else it
    will be stuck with the last values mapped from the joysticks.  Remember,
    even when Disabled it is reading inputs from the Operator Interface.
  */
    pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
    pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
    relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
    relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
    relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
    relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

  while (autonomous_mode)  /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);  /* DO NOT DELETE, or you will be stuck here forever! */

        /* Add your own autonomous code here. */
               
                //START GYRO CODE
                       

                gyro_input = Get_Analog_Value(rc_ana_in01);//Get the value


                if((gyro_input<505) || (gyro_input>520))//Cusion
                {
                        gyro_error += ((int)gyro_input - (int)523);
                }

                if(gyro_error < -ACCEPT_ERROR)//Too far left
                {
                        if(left_speed <= 250)
                                left_speed += TURN_SPEED;
                }
                else if(gyro_error > ACCEPT_ERROR)//Too far right
                {
                        if (right_speed <= 250)
                                right_speed += TURN_SPEED;
                }
                else if((gyro_error < ACCEPT_ERROR) && (gyro_error > -ACCEPT_ERROR))//Going back on course
                {
                        left_speed = LEFT_START_SPEED;
                        right_speed = RIGHT_START_SPEED;
                }


                pwm13 = left_speed;//pwm13 goes to left motor
                pwm15 = right_speed;//pwm15 goes to right motor

                printf("Gyro: %5u Error: %5u PWM13: %5u PWM15 %5u \n",(int)gyro_input,(int)gyro_error,(int)pwm13,(int)pwm15);

        Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

        Putdata(&txdata);  /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
}

Thats everything i modified in the default code for the FRC. The problem comes at Get_Analog_Value(). It is not getting an analog value, it is just coming up 0 in the printf (which printed fine on the EDU bot). We have really tried everything and it never gets a signal, we tried it on both gyros we have, we tried many different rc_ana_in ports, we even tried plugging the gyro in backwards and into the digital ports =P. Nothing makes it display a value. Is there some place where you have to initialize something to let you use rc_ana_in01 like in the EDU code. We are really stummped and very frustrated and ready to throw out using the gyros.

Thanks again for your time.

Mark McLeod 14-10-2004 20:44

Re: No Signal From Gyro
 
Your analog I/O should already be setup in User_Initialization() in the user_routines.c file by the statement:

Set_Number_of_Analog_Channels(SIXTEEN_ANALOG);

I think Get_Analog_Value returns "unsigned int" if I recall correctly, so you might want to typecast the call to “(long int)”.

Will you be at the SBPLI mini-comp tomorrow? If so look me up and I'll help you debug the gyro input.

colt527 14-10-2004 20:59

Re: No Signal From Gyro
 
Quote:

Originally Posted by Mark McLeod
Your analog I/O should already be setup in User_Initialization() in the user_routines.c file by the statement:

Set_Number_of_Analog_Channels(SIXTEEN_ANALOG);

I think Get_Analog_Value returns "unsigned int" if I recall correctly, so you might want to typecast the call to “(long int)”.

Will you be at the SBPLI mini-comp tomorrow? If so look me up and I'll help you debug the gyro input.

1.) We have that Set_Number_of_Analog_Channels() in there
2.) We have tried to type cast it to every variable known to c =P

it would just be

gyro_input = (long int)(Get_Analog_Value(rc_ana_in01));

right?

3.) Nah, we wanted to go to the mini-comp but could not afford the cost of a bus since the district busses would still be on duty.

EricS-Team180 14-10-2004 22:12

Re: No Signal From Gyro
 
This is going to sound a bit whacked, but try getting rid of:

Generate_Pwms(pwm13,pwm14,pwm15,pwm16);


and try just mapping your motor outputs to pwm's 9-12 or anything but 13-16


I think we ran into something similar last year and finally tracked it down to using the Get_Analog function in conjunction with the Generate_Pwms

In the FRC, PWM 13-16 aren't output from the same microprocessor as the others and this seems to create some kind of conflict.

Eric

Mark McLeod 14-10-2004 22:45

Re: No Signal From Gyro
 
Quote:

Originally Posted by 527Paranoia
2.) We have tried to type cast it to every variable known to c =P

it would just be

gyro_input = (long int)(Get_Analog_Value(rc_ana_in01));

right?

You got it right.

Does the gyro still give you a proper reading on the Edu controller? Just to make sure it didn't develop a loose connection (although doubtful since you tried both).

What model gyro are you testing?

If your team meets after school I could take a late lunch or drop by after work (in Bethpage) if you can't isolate the problem. I hate the thought of you giving up the gyro after you got it working on the Edu.

eugenebrooks 14-10-2004 23:50

Re: No Signal From Gyro
 
We use analog feedback for our arm, and a gyro to control turns
on our robot. The cast on the GetAnalogValue() call is not required,
because the routine is declared somewhere,
but the cast for arguments to printf is, because "char" will otherwise
get pushed on the stack, for efficiency purposes, I presume.

We have the "generate pwms" call commented out in our code, and
use only the "normal" pwm outputs, it being general policy to comment
out anything that might be considered "exotic" and a cause of possible
trouble. I think that the "Keeper of the magic 8 ball" has it right
on this question... Pitch the "generate pwms" and go for the normal
pwm outputs.

colt527 15-10-2004 19:41

Re: No Signal From Gyro
 
Ok, here is the latest updates from our Attempts at getting a signal from the Gyro. Here is all our autonomous code is:

Code:


//VARIABLES DECALARED AT TOP

unsigned long int gyro_input;

void User_Autonomous_Code(void)
{
  /* Initialize all PWMs and Relays when entering Autonomous mode, or else it
    will be stuck with the last values mapped from the joysticks.  Remember,
    even when Disabled it is reading inputs from the Operator Interface.
  */
    pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
    pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;
    relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;
    relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;
    relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;
    relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

  while (autonomous_mode)  /* DO NOT CHANGE! */
  {
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {
        Getdata(&rxdata);  /* DO NOT DELETE, or you will be stuck here forever! */

        gyro_input = Get_Analog_Value(rc_ana_in01);
        printf("gyro: %d",(int)gyro_input);
               
        Putdata(&txdata);  /* DO NOT DELETE, or you will get no PWM outputs! */
    }
  }
}

And we get in out output from the printf "Gyro: 0". I can't make it any simpler! and its absolutly driving me up a wall! What could possible be wrong other then our FRC hates me and is broken in some way....does anyone out there have any thoughts on why this thing might still not work. Even if its something incredibly simple that you assume all teams should know please tell. Thanks again.

I also remember right before the 2004 competition FIRST released an unpdate for the controller that we never did.... did that have anything to do with analog inputs?

PS. Currently we are meeting after school on Fridays @ 2:00pm, and we sometimes meet during the week just to work on some small things, so if we cant get it working soon maby it would be best if you stop by and have someone who really knowns what they are doing (ie. not ne one from our team) look at it.

EricS-Team180 15-10-2004 22:53

Re: No Signal From Gyro
 
...hmmmm, I know you're only posting part of the file, but have you #included:
ifi_aliases.h
ifi_defaults.h and
ifi_utilities.h at the top of the file?

Without them you're missing the function prototype and definitions for
Get_Analog_Value(rc_ana_in01)


.....just a thought...cause that'll hose it up


I don't see any problem with your print, but I would make gyro_input an unsigned int to match the return type in the function prototype.


Hope that helps,
Eric

Mark McLeod 16-10-2004 15:11

Re: No Signal From Gyro
 
The RC firmware update innovation-FIRST posted doesn't affect this problem. That had to do with initializing PWM & RELAY values when changing modes.

Nothing looks bad in your code and the failure to typecast in this one case shouldn’t be noticable, so lets go deeper.
I’ve attached an entire FRC project from the default code with two analog read statements added to Process_Data_From_Master_uP() for no other reason than that routine was handy (I posted just that routine below-those are the only changes made to the default code). Test with the whole project to eliminate the chance that something elsewhere in your code is causing the problem as Eric says.
You'll see one statement reads from analog input 1, the other from analog input 16. I tested with our gyro on input 1 and with a potentiometer on input 16. You don’t need to have a pot handy. The Get_Analog_Input will return “1023” if nothing is attached to the input pins, and if you connect the “SIG” and “BLK” pins with a paperclip you’ll get a reading of zero.
Try testing with this. You can just IFI_Load the .hex file or recompile the whole project if you like.

Code:

void Process_Data_From_Master_uP(void)
{
long CurrentGyro=0;
int pot=0;
 
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
 
Default_Routine(); /* Optional. See below. */
 
/* Add your own code here. */
 
CurrentGyro = (long)Get_Analog_Value(rc_ana_in01);
printf("Gyro= %d", (int)CurrentGyro);
 
pot = Get_Analog_Value(rc_ana_in16);
printf("pot= %d", pot);
 
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
 
Putdata(&txdata);                        /* DO NOT CHANGE! */
}

Quote:

Originally Posted by 527Paranoia
What could possible be wrong other then our FRC hates me and is broken in some way....

You’re looking for three things.
1) If both analog inputs = 0 no matter what, even disconnected, that means bad FRC analog inputs, ergo the FRC hates you.
2) If the pot works, but the gyro doesn’t then the gyro hates you.
3) If they both work then something else in the code hates you.

P.S. Friday afternoons are good for me. Clear it with your advisor first then PM me directions both to the school and where I find the team at school. I'll be coming south on the SOB

EricS-Team180 16-10-2004 20:34

Re: No Signal From Gyro
 
Quote:

Originally Posted by Mark McLeod
..... I'll be coming south on the SOB

....I drive I-95 south to West Palm Beach, every day and it's an SOB too <ha!>

....anyway, your plan is a good one Mark. They'll get to the bottom of this and love that little gyro chip ;)

Eric

colt527 17-10-2004 18:34

Re: No Signal From Gyro
 
Ok, the 2 differences in my code from yours is that
1.) I used global variables instead of local ones for gyro input.
2.) and I did not initialize them to anything anywhere

I don't know if that will cause any problems....but what I did notice was that the analog inputs gave 0 when nothing was connected to them, which makes me think the FRC is messed .... but what makes me think its only semi-messed is that when we hooked up a pot we were getting a reading from 0-6 corrosponding with the position of the "turny thing" on the pot. I thought that it SHOULD display 0-1023 like a good 10 bit unsigned integer, so either our pot doesnt like numbers above 6 or the FRC is broken.

I will load the code next available chance and tell you the results. But really, thanks for caring! =) Its always good to know that if you have no clue what you are doing there is someone out there.

Mark McLeod 17-10-2004 19:59

Re: No Signal From Gyro
 
Quote:

Originally Posted by 527Paranoia
Ok, the 2 differences in my code from yours is that
1.) I used global variables instead of local ones for gyro input.
2.) and I did not initialize them to anything anywhere

I don't know if that will cause any problems....

Won't make any difference. I only used locals to isolate the issue, and initialized them to make sure Get_Analog_Input was really returning a value.

The rest of your description doesn't sound good for the FRC, but run through the test. If the problem looks like the FRC, drop in reads and do the open/closed pin test on all the other analog inputs to see if they're all blown.

Also, test the range of your pot on the EDU to see if it behaves properly there. I'll bring my own pot on Friday if the problem doesn't get solved by then.

colt527 19-10-2004 07:30

Re: No Signal From Gyro
 
OK, the mentor said it is OK for you to stop by on Friday. I PMed you the exact directions and everything else you need to get into the building.


All times are GMT -5. The time now is 20:12.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi