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)

SuspectZero 30-01-2008 23:24

Re: New C18 3.0+ Compatible FRC Code
 
will the encoder code work with the US Digital E4P-250-250 encoder which is built-in on the Andy Mark Super Shifter transmission? also what kind of output should u expect from the encoder and the gyro?

Alan Anderson 31-01-2008 00:24

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by SuspectZero (Post 689219)
will the encoder code work with the US Digital E4P-250-250 encoder which is built-in on the Andy Mark Super Shifter transmission?

The E4P is a standard quadrature encoder. I can assure you that it works perfectly with Kevin's encoder library for the standard IFI code, and I have very high confidence that it will work just as perfectly with his new framework.

JHale 31-01-2008 21:52

Re: New C18 3.0+ Compatible FRC Code
 
Having the same problem with the new code as someone mentioned before.

When I build the project with Initialize_ADC() uncommented, it builds fine but encounters a code error.

When I build the project with ENABLE_TIMER_4 defined in timers.h, the linker encounters the error:

Error - symbol 'Timer_4_ISR' has multiple definitions.


I have tried commenting out the definition for Timer_4_ISR() in timers.c (because it does nothing) but we get back to the code error. Also, ENABLE_TIMER_4 is defined in ifi_frc.h.

Using a 2007 RC, MCC18 3.10;

Thanks!
-James

Jon236 31-01-2008 22:48

Re: New C18 3.0+ Compatible FRC Code
 
per Kevin's read-me

2) Enable the timer 4 interrupt service routine in ifi_frc.h
3) Make sure timer 4 is disabled at the top of timers.h.

Kevin Watson 03-02-2008 12:38

Re: New C18 3.0+ Compatible FRC Code
 
I've written replacement code for IFI's Get_Analog_Value() function. It's now included with both builds of the new code on my website. You can also just grab the files and drop then into your project.

-Kevin

Jon236 03-02-2008 14:06

Re: New C18 3.0+ Compatible FRC Code
 
So, per your documentation, to use your 'quickie' adc code, you shouldn't run them with the gyro code, right?

Kevin Watson 03-02-2008 14:21

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Jon236 (Post 691405)
So, per your documentation, to use your 'quickie' adc code, you shouldn't run them with the gyro code, right?

No, you shouldn't as they'll interfere with each other. You can always just increase the number of analog channels sampled by the adc.c code when using the gyro.

-Kevin

Code Monkey 06-02-2008 19:18

Re: New C18 3.0+ Compatible FRC Code
 
I have gotten Timer0 to work as a clock for the code. A few misadventures (like not putting the initialize function in the Initialization.c in Teleop.c), but actually is very easy to implement in the new code with the prescaling.

I have not gotten the encoder 3 and 4 to work. no error messages, but get_encoderX_count always comes back 0. any ideas?

Kevin Watson 06-02-2008 19:52

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Code Monkey (Post 693479)
I have gotten Timer0 to work as a clock for the code. A few misadventures (like not putting the initialize function in the Initialization.c in Teleop.c), but actually is very easy to implement in the new code with the prescaling.

I have not gotten the encoder 3 and 4 to work. no error messages, but get_encoderX_count always comes back 0. any ideas?

If it builds with no error messages it's probably because you didn't enable the call to the encoder ISRs at the top of ifi_frc.h.

I'm thinking about password protecting the project zip files with a password that's something like read_the_readme.txt_file_before_doing_anything :).

-Kevin

RyanN 06-02-2008 20:43

Re: New C18 3.0+ Compatible FRC Code
 
Okay, I'm having a little more trouble... I'm trying to get some potentiometers working on our robot, so I read the readme and did everything it told me to do:
Quote:

My comments are in all capitals.
FROM README.TXT

By default the analog to digital and gyro software is disabled.
Perform these steps to get your gyro working:

1) Enable the Initialize_ADC() and Initialize_Gyro() functions in
teleop.c/Initialization(). CHECK, REMOVED THE // BEFORE INITIALIZE_ADC(), LEFT THE GYRO ALONE
2) Enable the timer 4 interrupt service routine in ifi_frc.h CHECK
3) Make sure timer 4 is disabled at the top of timers.h. CHECK, THE // WERE ALREADY THERE, NO CHANGE
4) Depending on the operating modes you will be using the gyro,
place calls to the Process_Gyro_Data() function in the disabled.c/
Disabled_Spin(), autonomous.c/Autonomous_Spin() and/or teleop.c/
Teleop_Spin() functions. DID NOT DO, NOT USING GYRO
5) Add gyro bias calibration code that will execute before you
use your gyro. Example calibration code has been placed in
disabled.c/Disabled() that can be used for the competition (this
requires that you use a mode dongle to emulate the field
controller, which will put you in disabled mode for a period of
time before transitioning to autonomous mode). For testing
purposes you can also use the example code in teleop.c/Teleop()
to make sure your gyro is working. DID NOT DO, NOT USING GYRO
6) Follow the instructions in adc_readme.txt, adc.h, gyro_readme.txt,
and gyro.h for information related to installation and calibration
of your gyro. CHECK, SEE BELOW

FROM ADC_README:

Usage notes:

1) A #include statement for the adc.h header file must be
included at the beginning of each source file that calls the
functions in adc.c. The statement should look like this:
#include "adc.h". ALREADY INCLUDED IN TELEOP.C, CHECK

2) Define the number of analog channels that you'd like this
software to track by opening adc.h and following the embedded
instructions above #define NUM_ADC_CHANNELS. CHANGED THE NUMBER FROM 1 TO 2 SINCE WE'RE USING 2 POTENTIOMETERS, CHECK

3) For advanced users, analog channels can be oversampled to
decrease noise and gain resolution in your analog measurements.
The oversampling ratio can be changed from the default x4
by commenting-out the line #define ADC_SAMPLES_PER_UPDATE_4
found in adc.h and then removing the // from in front of one
of the other options. Measurement range and resolution can be
determined from this table: I'M NOT ADVANCED, SO I LEFT THIS ALONE

ADC Samples Effective
Averaged Bits of Measurement Voltage
Per Update Resolution Range Per Bit
___________ __________ ___________ _________
1 10 0-1023 4.88 mV
2 10 0-1023 4.88 mV
4 11 0-2047 2.44 mV
8 11 0-2047 2.44 mV
16 12 0-4095 1.22 mV
32 12 0-4095 1.22 mV
64 13 0-8191 610 uV
128 13 0-8191 610 uV
256 14 0-16383 305 uV


4) Finally, pick the master sample rate by selecting one
of the available rates found in adc.h. The update rate can
be determined using this formula:

Update Rate =
Sample Rate / (Samples Per Update * Number Of Channels)
LOOKS LIKE YOU HAVE ALREADY DONE THIS USING THIS FORMULA, CHECK
I think I have done everything I needed to do, but when I try to build, it says
Quote:

C:\Robot Code\2008\ifi_frc_sensor_30\teleop.c:256:Error [1105] symbol 'ADC_CH0' has not been defined
Here is where it is saying this...
Quote:

liftpos = Get_Analog_Value(rc_ana_in01);
I also tried the quick_adc, but I was having trouble, so I went back to this...

Update: I may have fixed it, but I'm unsure... Instead of Get_Analog_Value(rc_ana_in01), I used Get_ADC_Result(1). Will this work? I'm not going to be able to try this on our robot until Saturday as I'm going out of town for the next 2 days.

Kevin Watson 06-02-2008 21:16

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by RyanN (Post 693549)
I also tried the quick_adc, but I was having trouble, so I went back to this...

You just use a number from 1 to 16 to select the ADC channel. As an example:

liftpos = Get_Analog_Value(1); or liftpos = Quick_ADC(1);

Of course you'd probably want to #define these values in a header file and then the code would look like this:

// this goes at the top of the source file or in a header file like robot.h
#define ARM_ELBOW_POT 1 // analog input one
#define ARM_WRIST_POT 2 // analog input two

unsigned int elbow_pot;
unsigned int wrist_pot;

elbow_pot = quick_adc(ARM_ELBOW_POT);
wrist_pot = quick_adc(ARM_WRIST_POT);

Because it's simpler, I would use quick_adc() if you're only using potentiometers on your 'bot.

-Kevin

emersont49 06-02-2008 21:53

Re: New C18 3.0+ Compatible FRC Code
 
We are using Kevin's code to read the gyro and control our steering. Our steering is connected to a 10K linear pot. We are reading the pot with get_ADC_value and feeding it to a PID function. The intent is to have servo controlled steering.

We are having a lot of trouble getting the servo to respond properly. We are working on tuning our PID loop and having some success.

Here is my question: We are calling the PID routine in Default_Routine so it executes very 26.2 ms. Should we be calling it in a fast loop?

RyanN 06-02-2008 22:21

Re: New C18 3.0+ Compatible FRC Code
 
Thanks again for the help. I found out why the quick_adc.c and quick_adc.h were not working... Even though I said add files to project, it never did copy them to the project folder, like I expected it would... Still getting used to MPLAB. It compiled without any error (just the way I like it :D) and I'm going to try it out hopefully Saturday.

Code Monkey 07-02-2008 14:24

Re: New C18 3.0+ Compatible FRC Code
 
We had the enables in the IFI_FRC.h. The problem was in the format of the print statement (note to others- output from encoders is a long integer). The encoders were working just fine. Sometimes it really is just dumb stuff. (Thank you Kevin for being patient)

sfs 08-02-2008 01:12

Re: New C18 3.0+ Compatible FRC Code
 
I just tried to build the ifi_frc_sensor project with MPLAB IDE v7.20 and C18 2.4 (had to use the project wizard to create new mcp/mcw files, as I was unable to open the ones that came with). After updating the ifi_frc.h header file to define the proper compiler macro (USE_C18_24), I now am getting these errors:

timers.c:72:Error [1205] unknown member 'PSA' in '__tag_216'
timers.c:72:Error [1131] type mismatch in assignment

Apparently the header file mcc18\p18f8722.h defines T0CON bit 3 as T0PS3, but the timers.c file references it as 'PSA' instead. Should the code read:

#ifdef USE_C18_24
T0CONbits.T0PS3 = 1;
#else
T0CONbits.PSA = 1;
#endif

??


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