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)

PhilBot 24-01-2008 13:42

Re: New C18 3.0+ Compatible FRC Code
 
I just discovered something else interesting about the gyro code... specifically the way the angle resolution relates to the analog input scaling.
I detected this as I was logging heading data as I was driving around and around our track.

On my system I have 4 Analog inputs, that I'm running 4 amples per update at 1600 Hz... This give me a Gyro update rate of 100 updates per second, and an ADC Range of 2048 and

In the Gyro code... for an ADXRS150 I have

Quote:

#define GYRO_SENSITIVITY_RAD 1396L // in units of milliradians/sec/volt
And finally I have

Quote:

long Get_Gyro_Angle(void)
{
// Return the calculated gyro angle to the caller.
return(((gyro_angle * GYRO_SENSITIVITY * 5L) / (ADC_RANGE * ADC_UPDATE_RATE)) * GYRO_CAL_FACTOR);
}
So, since I've been caught before on this one.. I calculated the value of the divisor of this expression. ADC_RANGE * ADC_UPDATE_RATE = 2048 * 100 = 204800. So I'm dividing a "Long" by this number.... I should be able to calculate the maximum result I can get...

Max Long is 2147483648 so if I divide this by 204800 I get 10485 ... Which, in theory is the maximum result I can get...
But wait, this is millirads so the maximum angle I can measue is... just over 1.6 full rotations...

Oops... Either I did my math wrong, or I have to reduce my update rate.
In fact, this does reflect what I see in my log data... after getting to 10485 mRad, the angle starts counting down again...

So I need to reduce my ADC range/rate, or reduce my measurement accuracy (like changing to tenth of a degree.)

No wonder my bot corrected in the wrong direction on evey second lap :)

kaszeta 24-01-2008 13:49

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by PhilBot (Post 685004)
No wonder my bot corrected in the wrong direction on evey second lap :)

Just to make sure we didn't have odd problems like this, our code looked something like

Code:

void Read_Yaw(void) {
  phi=Get_Gyro_Angle();
  phi=phi%6283L;  // Avoid unneccesary wraparound
}


Kevin Watson 24-01-2008 16:38

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by PhilBot (Post 685004)
I detected this as I was logging heading data as I was driving around and around our track.

Well, you have to assume something is gonna break if you do enough loop de loops :).

-Kevin

cdennisxlx2 24-01-2008 18:21

Re: New C18 3.0+ Compatible FRC Code
 
Sorry if this has been addressed before I don’t have time to go through all 288 posts but we are having an issue when we compile. Here is what our output looks like, if anyone can help it would be greatly appreciated. Thank you
Code:

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_frc.mcs".
Clean: Done.
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722 "autonomous.c" -fo="autonomous.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_frc.h:31:Error [1027] unable to locate 'p18cxxx.h'
C:\FRC2008\2008 Code\ifi_frc_simple_30\serial_ports.h:48:Error [1027] unable to locate 'stdio.h'

Halting build on first failure as requested.
BUILD FAILED: Thu Jan 24 15:12:09 2008


comphappy 24-01-2008 20:17

Re: New C18 3.0+ Compatible FRC Code
 
You need to go to the project menu then build options then project
On the directory tab select Header Search Path (i dont have mplab infront of me right now but it is the header one), create a new one that points to the mcc18\include folder where ever that may be, it might be in C:\Program Files\ or just under C:\
Seeing as that variable is off you may also need to set the Library Search Path to mcc18\lib folder

Kevin Watson 24-01-2008 20:23

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by ghhs_1527 (Post 685151)
Sorry if this has been addressed before I don’t have time to go through all 288 posts but we are having an issue when we compile. Here is what our output looks like, if anyone can help it would be greatly appreciated. Thank you
Code:

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_frc.mcs".
Clean: Done.
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722 "autonomous.c" -fo="autonomous.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_frc.h:31:Error [1027] unable to locate 'p18cxxx.h'
C:\FRC2008\2008 Code\ifi_frc_simple_30\serial_ports.h:48:Error [1027] unable to locate 'stdio.h'
Halting build on first failure as requested.
BUILD FAILED: Thu Jan 24 15:12:09 2008


It looks like MPLAB doesn't know where to find the C18 header files (it seems to me that if you just sneeze while MPLAB is running, it'll forget all kinds of vital information <grin>). Anyway, go to Project > Build Options > Directories tab > Include Search Path and then point it to c:\mcc18\h.

-Kevin

Kevin Watson 24-01-2008 21:22

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Manoel (Post 684968)
Would it be too much to ask for an updated library for the EDU-RC? ;)

Yes, at some point I'll port code to the EDU-RC (and maybe Vex too).

-Kevin

cdennisxlx2 24-01-2008 22:16

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Kevin Watson (Post 685216)
It looks like MPLAB doesn't know where to find the C18 header files (it seems to me that if you just sneeze while MPLAB is running, it'll forget all kinds of vital information <grin>). Anyway, go to Project > Build Options > Directories tab > Include Search Path and then point it to c:\mcc18\h.

-Kevin

well my first errors are gone but now i get these...
Code:

Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "autonomous.c" -fo="autonomous.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "disabled.c" -fo="disabled.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "ifi_code.c" -fo="ifi_code.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "ifi_frc.c" -fo="ifi_frc.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "interrupts.c" -fo="interrupts.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "pwm.c" -fo="pwm.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "serial_ports.c" -fo="serial_ports.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "teleop.c" -fo="teleop.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\FRC2008\2008 Code\ifi_frc_simple_30\teleop.c:105:Warning [2066] type qualifier mismatch in assignment
Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8722  /i"C:\mcc18\h" "timers.c" -fo="timers.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\mcc18\bin\mplink.exe" /l"C:\Program Files\microchip\mcc18\lib" "C:\FRC2008\2008 Code\ifi_frc_simple_30\18f8722.lkr" "C:\FRC2008\2008 Code\ifi_frc_simple_30\autonomous.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\disabled.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_code.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_frc.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\interrupts.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\pwm.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\serial_ports.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\teleop.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\timers.o" "C:\FRC2008\2008 Code\ifi_frc_simple_30\ifi_frc_8722.lib" /m"ifi_frc.map" /w /o"ifi_frc.cof"

MPLINK 4.1, Linker
Copyright (c) 2006 Microchip Technology Inc.
Error - could not find file 'clib.lib'.
Errors    : 1


Link step failed.
BUILD FAILED: Thu Jan 24 19:11:44 2008


Kevin Watson 25-01-2008 00:53

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by ghhs_1527 (Post 685310)
well my first errors are gone but now i get these...

The first warning can be eliminated by changing the memory model to large: Project > Build Options > MPLAB C18 tab > Catagories: Memory Model > select large model for code and data.

The clib.lib error is due to MPLAB not knowing where your compiler libraries are installed: Project > Build Options > Directories tab > Library Search Path

-Kevin

cdennisxlx2 25-01-2008 01:05

Re: New C18 3.0+ Compatible FRC Code
 
cool, it all works now, thank you very much :)

Kevin Watson 25-01-2008 02:58

Re: New C18 3.0+ Compatible FRC Code
 
Just FYI, I believe that I have a single version of the code that will work with all robot controllers from 2004 on and can be built with C18 2.4 or 3.1. After seeing if I can improve the gyro integration code (per Philbot's posting above), doing some additional testing, and writing a bit more documentation, I should be able to release the code in the next few days.

-Kevin

billbo911 25-01-2008 10:05

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Kevin Watson (Post 685456)
Just FYI, I believe that I have a single version of the code that will work with all robot controllers from 2004 on and can be built with C18 2.4 or 3.1. After seeing if I can improve the gyro integration code (per Philbot's posting above), doing some additional testing, and writing a bit more documentation, I should be able to release the code in the next few days.

-Kevin

Kevin,
You truly are an example that all FIRSTers can look to, including myself. Thank you for your incredible efforts!!

stevethetinker 25-01-2008 20:20

Re: New C18 3.0+ Compatible FRC Code
 
I do like the new code layout. I would like to see the code for C18 2.4. We do prototyping on previous years' robots and having both 3.15 and 2.4 on our machines seems a bit difficult to manage.

Jon236 26-01-2008 17:26

Re: New C18 3.0+ Compatible FRC Code
 
Kevin,

Now finding that the RC is stuck in Programming Mode at the end of download if adc is initialized.......any suggestions? (I did read the readmes!!!)

Jon Mittelman

1jbinder 26-01-2008 18:28

Re: New C18 3.0+ Compatible FRC Code
 
Hi Kevin,
We keep on getting a error that ADC_CH0 is not defined. This happens when we try to use rc_ana_in_01. We looked in all of the header files including the complier file and could not find the definition but it is clearly used in ifi_frc.h.This might be a stupid error but please can someone help us.
Thanks,
Julan


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

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