Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   New C18 3.0+ Compatible FRC Code (http://www.chiefdelphi.com/forums/showthread.php?t=60377)

Nathans 16-01-2008 11:03

Re: New C18 3.0+ Compatible FRC Code
 
We're testing the new gyro code, but it overrides all of our commands and sets our pwm outs to 0. Once we put anything referencing the pwm outs we're using, it messes them up. We searched through the code, but we can't find anything that might be causing this. Has anyone else come across this problem?

Kevin Watson 16-01-2008 17:10

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Nathans (Post 679223)
We're testing the new gyro code, but it overrides all of our commands and sets our pwm outs to 0. Once we put anything referencing the pwm outs we're using, it messes them up. We searched through the code, but we can't find anything that might be causing this. Has anyone else come across this problem?

Assuming you're referring to my code, what makes you think the gyro code is causing this? Can you use the "Find in files" search tool to find all instances of the PWM variable that's getting fragged?

-Kevin

Nathans 16-01-2008 17:36

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Kevin Watson (Post 679472)
Assuming you're referring to my code, what makes you think the gyro code is causing this? Can you use the "Find in files" search tool to find all instances of the PWM variable that's getting fragged?

-Kevin

We tried that on Monday. I don't have the results in front of me now, but they were all just definitions. I suspect it has something to do with the gyro code (as downloaded from this thread, not added in by us), as the plain C18 3.0 code doesn't cause this problem. We got this bug on 2 occasions, each time starting from scratch, adding only a few lines for straight joystick-to-PWM drive code, as well as removing the gyro calibration in one instance.

Lafleur 16-01-2008 18:27

Serial Ports
 
Kevin:

Is there a hard limit at 128 bytes in the Serial Queue's??

RX_1_QUEUE_SIZE 128 // Must be a power of two (i.e.,8,16,32,64,128)

ay2b 16-01-2008 19:02

Re: New C18 3.0+ Compatible FRC Code
 
(This may be a little bit of a tangent.)

I'd like to report to anyone who's interested that the C18 3.10 compiler works just fine under Wine (on Linux), after fixing one minor issue.

I had v 2.4 working under Wine. I ran the upgrade, and then things did not work. I don't remember the exact error, but it did not compile successfully. I copied my mcc18 directory from one machine (where I'd run the upgrade) to a different machine, and it worked fine on the new machine. I then copied my ~/.wine directory from the new machine back to the old machine, and the compiler worked fine.

If you plan on using v 3.10 under Wine, my recommendation is to do one of the following:
- Run the upgrade on a Windows machine, and then copy over the mcc18 directory to run it under Wine
- Make a backup of ~/.wine, then run the upgrade program under Wine, then restore ~/.wine.

Kevin Watson 16-01-2008 20:44

Re: Serial Ports
 
Quote:

Originally Posted by Lafleur (Post 679513)
Kevin:

Is there a hard limit at 128 bytes in the Serial Queue's??

RX_1_QUEUE_SIZE 128 // Must be a power of two (i.e.,8,16,32,64,128)

Unless you want to hack the linker script, I suspect the upper limit would be 256. Just out of curiosity, why do you need such a large buffer?

-Kevin

Kevin Watson 16-01-2008 20:51

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Nathans (Post 679483)
We tried that on Monday. I don't have the results in front of me now, but they were all just definitions. I suspect it has something to do with the gyro code (as downloaded from this thread, not added in by us), as the plain C18 3.0 code doesn't cause this problem. We got this bug on 2 occasions, each time starting from scratch, adding only a few lines for straight joystick-to-PWM drive code, as well as removing the gyro calibration in one instance.

I can't think of anything in the gyro or ADC code that would cause this, but I'd be very interested in finding out if it's something knuckle-headed I'm doing in my code. Which compiler are you using and which robot controller are you using (i.e., what year is it from)? Can you zip up your code and send it to me?

-Kevin

Lafleur 17-01-2008 10:54

Re: Serial Ports
 
Quote:

Originally Posted by Kevin Watson (Post 679642)
Unless you want to hack the linker script, I suspect the upper limit would be 256. Just out of curiosity, why do you need such a large buffer?

-Kevin

I don't, just wanting to know the limits of your code...

thanks...

PhilBot 17-01-2008 14:41

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Kevin Watson (Post 678625)
Does it give anyone heartburn if I just release one build for each of the two compiler versions that has support for the ADC, gyro and encoders already built in? You'd be able to remove funtionality by commenting out a few #defines.

-Kevin

I vote for the "All in one" solution..... saves me from having to combine them (which I have a high probability of screwing up).

Phil.

billbo911 17-01-2008 14:45

Re: New C18 3.0+ Compatible FRC Code
 
Kevin,
This is just a thought and should be implemented by teams as they feel their needs require.
In the teleop.c file, you currently have the gyro bias calculation process happen in the Teleop function.
Code:

void Teleop(void)
{
        static unsigned int i = 0;
        static unsigned int j = 0;
        int temp_gyro_rate;
        long temp_gyro_angle;
        int temp_gyro_bias;

        i++;
        j++; // this will rollover every ~1000 seconds

        if(j == 10)
        {
                printf("\rCalculating Gyro Bias...");
        }

        if(j == 60)
        {
                // start a gyro bias calculation
                Start_Gyro_Bias_Calc();
        }

        if(j == 300)
        {
                // terminate the gyro bias calculation
                Stop_Gyro_Bias_Calc();

                // reset the gyro heading angle
                Reset_Gyro_Angle();

                printf("Done\r");
        }


        if(i >= 30 && j >= 300)
        {
                temp_gyro_bias = Get_Gyro_Bias();
                temp_gyro_rate = Get_Gyro_Rate();
                temp_gyro_angle = Get_Gyro_Angle();
                printf(" Gyro Bias=%d\r\n", temp_gyro_bias);
                printf(" Gyro Rate=%d\r\n", temp_gyro_rate);
                printf("Gyro Angle=%d\r\n\r\n", (int)temp_gyro_angle);
                i = 0;
        }

        Update_OI_LEDs();        // located in ifi_code.c
}


This may be fine in some instances, but in competition, the robot is powered up in disabled mode, then transitions into autonomous(Hybrid) then back to disabled and finally into teleop. The gyro bias would never be calculated until well after it may be needed.
Wouldn't it be better if this code were placed in the disabled.c file in the Disabled function. An additional flag could be set to prevent the bias calc process from running during any additional disabled periods.

Kevin Watson 17-01-2008 17:16

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Nathans (Post 679223)
We're testing the new gyro code, but it overrides all of our commands and sets our pwm outs to 0. Once we put anything referencing the pwm outs we're using, it messes them up. We searched through the code, but we can't find anything that might be causing this. Has anyone else come across this problem?

I had a look at your code and it looks like the problem is your limit() function, which is returning a 16-bit integer when it should return an unsigned 8-bit byte. You also had semicolons immediatly after your if statments:

Code:

int limit(int value)
{
if(value >255);
  value =255;
if(value <0);
  value =0;  <== because of the added semicolon above, this statement will always execute and will always set the return value to zero.
return value;
}

Your code should probably look like this:

Code:

unsigned char limit(int value)
{
if(value >255);
value =255;
else if(value <0);
value =0;
return (unsigned char)value;
}

-Kevin

Kevin Watson 17-01-2008 17:22

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by billbo911 (Post 680166)
Wouldn't it be better if this code were placed in the disabled.c file in the Disabled function. An additional flag could be set to prevent the bias calc process from running during any additional disabled periods.

I've already made this change and provided a sample calibration routine in Disabled(). You're waiting because I'm deep in procrastination mode and haven't finished the first cut of the documentation yet <grin>.

-Kevin

Dave Scheck 17-01-2008 17:28

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Kevin Watson (Post 680281)
Your code should probably look like this:
Code:

unsigned char limit(int value)
{
if(value >255);
value =255;
else if(value <0);
value =0;
return (unsigned char)value;
}


Kevin, I think you forgot to remove the semicolons after the IFs in your reply. I think you meant it to be
Code:

unsigned char limit(int value)
{
  if(value > 255)
    value = 255;
  else if(value < 0)
    value = 0;
  return (unsigned char)value;
}


Nathans 17-01-2008 17:40

Re: New C18 3.0+ Compatible FRC Code
 
Thank you. I thought it was probably something stupid I did.

Kevin Watson 17-01-2008 18:00

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Dave Scheck (Post 680294)
Kevin, I think you forgot to remove the semicolons after the IFs in your reply. I think you meant it to be
Code:

unsigned char limit(int value)
{
  if(value > 255)
    value = 255;
  else if(value < 0)
    value = 0;
  return (unsigned char)value;
}


Ahh, my devious little plan succeeded and I verified that at least one person is awake and actually reading the programming forum.

Dave, thanks for catching my gaff <grin>.

-Kevin


All times are GMT -5. The time now is 14:27.

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