Go to Post Welcome to The 2018 FIRST Robotics Competition: Bureaucracy Bash! - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-09-2007, 22:43
Jim E Jim E is offline
Registered User
FRC #1523 (M.A.R.S.)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Lantana, FL
Posts: 188
Jim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond reputeJim E has a reputation beyond repute
Re: Error in code light on, trouble finding error

I can sympathize with you on MPLAB, it can be a pain to find the run-time errors.

Please remember that most causes of the red light of death are caused by not refreshing within the time limits of the processor, or every 26.3 ms.

That ROM array you are initializing at the start looks pretty big. Do you really need that level of precision? Each character will probably eat up 2 bytes of RAM.
Including the camera code and other functions is probably pushing you to the limits of the processors RAM during run time.

My 2cents.
__________________
Team MARS = 1.523 AU from the SUN!

Jim E.
  #2   Spotlight this post!  
Unread 27-09-2007, 10:00
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Error in code light on, trouble finding error

Quote:
Originally Posted by Jim E View Post
That ROM array you are initializing at the start looks pretty big. Do you really need that level of precision? Each character will probably eat up 2 bytes of RAM.
First of all, characters are, by definition, a single byte. On the other hand, the array is defined as int, so each value indeed takes two bytes. On the gripping hand, putting the array in ROM means it takes no RAM anyway.


Tanis, you're only putting values between -127 and 127 in the array. That will fit in a signed char if you do want to cut the array's size in half.

Quote:
Including the camera code and other functions is probably pushing you to the limits of the processors RAM during run time.
There's essentially no dynamic allocation of memory in the program, so RAM usage issues will make themselves known at compile time.

But I didn't notice the reference to camera and tracking code before. The serial port support that goes along with them requires specific changes to the interrupt service routine. Failing to handle interrupts properly is another way to cause the code error light to come on.

Tanis, are you actually using the camera? If so, make sure you've done the appropriate things to user_routines_fast.c as called out in the camera code documentation, and don't forget to call the camera tracking function in the main loop, probably from Default_Routine(). If not, don't #include the unnecessary files.
  #3   Spotlight this post!  
Unread 28-09-2007, 15:18
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Error in code light on, trouble finding error

Using the C18 compiler, 2007 RC, and an edited version of the default master code currently available off the IFI site.

I decided to get rid of the table, it was just a test (one of our mentors suggested it), and wouldn't have made much of a difference.

We've tried reloading the code multiple times (also have used the default code a few times), and our code doesn't work. The default code works fine.

We are not using the camera, so I got rid of that too.
__________________
Team 2052- Knightkrawler
Mentor and volunteer
  #4   Spotlight this post!  
Unread 28-09-2007, 17:44
Bomberofdoom's Avatar
Bomberofdoom Bomberofdoom is offline
Biggest FIRST addict in Israel
AKA: Nir Levanon
FRC #2230 (Zcharia's Angels)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 471
Bomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond repute
Send a message via MSN to Bomberofdoom
Re: Error in code light on, trouble finding error

Does the code compile?
I mean, were you able to transfer it through IFI_Loader (although the code didn't work on the robot)?
__________________
TEAM 2230 ZECHARIA'S ANGELS

2009 Microsoft Israel FRC Regional Winners!
2009 Microsoft Israel FRC Regional Chairman's Award Winners!!!
---------------------------------
2008 Microsoft Israel FRC Regional semi-finalist.
2008 Microsoft Israel FRC Regional Delphi's "Driving Tommorow's Technology" Award winner.
2008 Robot Driver
---------------------------------
2007 GM/Technion Israel FRC Regional semi-Finalist.
2007 GM/Technion Israel FRC Regional Xerox Creativity Award winner.
2007 Robot Driver.
  #5   Spotlight this post!  
Unread 28-09-2007, 18:08
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins
Re: Error in code light on, trouble finding error

What is the name of the file you are trying to download to the RC?
__________________
Eric Haskins KC9JVH
  #6   Spotlight this post!  
Unread 30-09-2007, 10:50
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Error in code light on, trouble finding error

Yes, it compiles, and downloads to the RC.

The file is KickerCode.hex.
__________________
Team 2052- Knightkrawler
Mentor and volunteer
  #7   Spotlight this post!  
Unread 05-10-2007, 16:47
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Error in code light on, trouble finding error

We've been working on it a bit more, the code we've been working on still doesn't work, and were currently trying to start from scratch. We got to about where we were before and it still wont work... suggestions?
__________________
Team 2052- Knightkrawler
Mentor and volunteer
  #8   Spotlight this post!  
Unread 05-10-2007, 18:40
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Error in code light on, trouble finding error

I can't offer any more suggestions without seeing your code. When you say "start from scratch", what exactly is the "scratch"? Specifically, are you taking the 2007 non-camera default code as a base, or are you beginning with something else? What files are you modifying?
  #9   Spotlight this post!  
Unread 05-10-2007, 19:44
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Error in code light on, trouble finding error

Plain, non camera code.

Editing User routines, and possibly ifi_aliases.h, depending on if we get our control box built.


Going to add in all the header files in the original code, except tracking.h, tracking_menu.h, camera_menu.h, and camera.h.
__________________
Team 2052- Knightkrawler
Mentor and volunteer
  #10   Spotlight this post!  
Unread 08-10-2007, 11:15
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Error in code light on, trouble finding error

A nit. Some RAM issues are detected/caught at compile time. But resource exhaustion issues are caught at link time.

There are several "standard" methods of helping debug embedded code. The simplest is to use a macro wrapper and use it with each function call. The macro can be used to either output a message via printf or to set a value into an output port that can be measured or displayed via leds.

When done debugging, just redefine the macro to nothing and allow the code to execute without any debug code overhead. For example, something like:


Code:
int myroutine( int a, int b, int c, int d );
#define DEBUG

#ifdef DEBUG
#define _Call( _arg )  (printf( "CALL: %lX[%d]\n", _arg, __LINE__ )==0)?printf("ERROR!\n"):_arg
#define _Trace( _arg ) printf( "TRAK: %s[%d]\n", _arg, __LINE__ )
#define _Return( _return_value ) { printf( "RETN: [%d] %d\n", __LINE__, _return_value ); return( _return_value ); }
#else
#define _Call( _arg ) _arg
#define _Trace( _arg )
#define _Return( _arg ) return( _arg )
#endif

int main()
{
int status;

    status = _Call( myroutine )(1,2,3,4);
    printf( "status = %d\n", status );
    status = _Call( myroutine )(4,3,3,4);
    printf( "status = %d\n", status );
}
int myroutine( int a, int b, int c, int d)
{
    _Trace( "myroutine" );
    /* routine stuff here... */
    _Return(a+b+c+d);
}
The result is something like:
Code:
CALL: 1200012A0[20]
TRAK: myroutine[27]
RETN: [29] 10
status = 10
CALL: 1200012A0[22]
TRAK: myroutine[27]
RETN: [29] 14
status = 14
You can change the printf call to be any user defined routine you need call to help in debugging the program. You'll need the .map output file to determine which function the routine address matches if just using the call macro. You can get fancier too, if desired.

For interrupt routines, don't use printfs! Instead just toggle a pin to show when you enter/leave the interrupt service routine. Use a scope to track.
  #11   Spotlight this post!  
Unread 09-10-2007, 06:01
FoleyEngineer's Avatar
FoleyEngineer FoleyEngineer is offline
Registered User
AKA: John Crombe
FRC #0910 (Foley Freeze)
Team Role: Coach
 
Join Date: Jul 2006
Rookie Year: 2005
Location: Madison Heights, MI
Posts: 108
FoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond reputeFoleyEngineer has a reputation beyond repute
Re: Error in code light on, trouble finding error

If the default code compiles, downloads and runs fine, then you can solve this by trial and error in pretty short order.

Just add in your "new" code one section at a time, compiling and downloading after each new "section". As soon as it quits working you've found a problem. Split that section in half and repeat. Before long you should have it figured out. The whole process really shouldn't take very long.

Good luck!

P.S. I remember not initializing one of the serial ports (as I wasn't using it) and that caused me untold problems (including the red light). I did what I suggest above and tracked it down right to the line at fault. Dividing by 2 makes pretty quick work of a problem when used recursively.
__________________

2014 Buckeye Champions - thanks 846 & 639, Troy Champions - thanks 33 & 5193, Imagery, Entrepreneurship & Industrial Design Awards
2013 Kettering Champions - thanks 70 & 862, Three Imagery Awards
2012 Western Mich Finalist - thanks 1918 & 85
2011 Trav. City Web Site, Troy Xerox, Mich State Semi Finalist & Judges Awards
2010 Kettering Champion - thanks 67 & 70, Kettering Rockwell Innovation 2010 Troy Finalists - thanks 33 & 288, and Rockwell Innovation
2009 Kettering QF, Detroit Finalists Detroit Creativity Award, Troy Semi-Finalists Troy Creativity Award
2008 WMRI Finalists - thanks 1243 and 904, 2008 Kettering Champion - thanks 67, 1075 and 2619
2008 IRI Judges Award Winner, Great Lakes Finalists - thanks 66 & 217, Western Mich
2007 Curie Division Champions - thanks 330 & 1270

Last edited by FoleyEngineer : 09-10-2007 at 06:05.
  #12   Spotlight this post!  
Unread 12-10-2007, 17:59
Bryan Herbst's Avatar
Bryan Herbst Bryan Herbst is offline
Registered User
AKA: Bryan
FRC #2052 (KnightKrawler)
Team Role: Mentor
 
Join Date: Sep 2007
Rookie Year: 2007
Location: Minneapolis, Minnesota
Posts: 544
Bryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond reputeBryan Herbst has a reputation beyond repute
Re: Error in code light on, trouble finding error

Okay, we rebuilt the code, and it compiles, downloads, and runs just fine, but we lack any reasonable level of control over the bot.

The joysticks seem to make up random values for themselves. When the computer is hooked up to the program port the numbers will jump all over, such once when it stayed at 127, but every ten or so it printed the input, the X would jump to 0. Frequently it will continue going in the same direction, even when you aren't touching the joystick.

Can anyone help us figure out what's going on?

Current default_routines.c:

Code:
/*******************************************************************************
* FILE NAME: user_routines.c <FRC VERSION>
*
* DESCRIPTION:
*  This file contains the default mappings of inputs  
*  (like switches, joysticks, and buttons) to outputs on the RC.  
*
* USAGE:
*  You can either modify this file to fit your needs, or remove it from your 
*  project and replace it with a modified copy. 
*
*******************************************************************************/

#include <stdio.h>

#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "serial_ports.h"
#include "pwm.h"
#include "eeprom.h"
#include "terminal.h"

extern unsigned char aBreakerWa     ped;
int intMax(int x, int y)
{
 int max = x;
 if(y > max)
 {
     max = y;
 }
   return max;
}

int intABS(int i)
{
 if (i < 0)
  return -i;
 else
  return i;
}
int joysticklimit(int inp)
{
 if(inp < 127)
  {
   inp += 1;
   return inp;
  }
 else if (inp > 127)
  {
   inp -= 1;
   return inp;
  }
 else
  {
   return inp;
  }
}



/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/
/* EXAMPLES: (see MPLAB C18 User's Guide, p.9 for all types)
unsigned char wheel_revolutions = 0; (can vary from 0 to 255)
unsigned int  delay_count = 7;       (can vary from 0 to 65,535)
int           angle_deviation = 142; (can vary from -32,768 to 32,767)
unsigned long very_big_counter = 0;  (can vary from 0 to 4,294,967,295)
*/

/*******************************************************************************
* FUNCTION NAME: Limit_Switch_Max
* PURPOSE:       Sets a PWM value to neutral (127) if it exceeds 127 and the
*                limit switch is on.
* CALLED FROM:   this file
* ARGUMENTS:     
*     Argument       Type             IO   Description
*     --------       -------------    --   -----------
*     switch_state   unsigned char    I    limit switch state
*     *input_value   pointer           O   points to PWM byte value to be limited
* RETURNS:       void
*******************************************************************************/
void Limit_Switch_Max(unsigned char switch_state, unsigned char *input_value)
{
  if (switch_state == CLOSED)
  { 
    if(*input_value > 127)
      *input_value = 127;
  }
}


/*******************************************************************************
* FUNCTION NAME: Limit_Switch_Min
* PURPOSE:       Sets a PWM value to neutral (127) if it's less than 127 and the
*                limit switch is on.
* CALLED FROM:   this file
* ARGUMENTS:     
*     Argument       Type             IO   Description
*     --------       -------------    --   -----------
*     switch_state   unsigned char    I    limit switch state
*     *input_value   pointer           O   points to PWM byte value to be limited
* RETURNS:       void
*******************************************************************************/
void Limit_Switch_Min(unsigned char switch_state, unsigned char *input_value)
{
  if (switch_state == CLOSED)
  { 
    if(*input_value < 127)
      *input_value = 127;
  }
}


/*******************************************************************************
* FUNCTION NAME: Limit_Mix
* PURPOSE:       Limits the mixed value for one joystick drive.
* CALLED FROM:   Default_Routine, this file
* ARGUMENTS:     
*     Argument             Type    IO   Description
*     --------             ----    --   -----------
*     intermediate_value    int    I    
* RETURNS:       unsigned char
*******************************************************************************/
unsigned char Limit_Mix (int intermediate_value)
{
  static int limited_value;
  
  if (intermediate_value < 2000)
  {
    limited_value = 2000;
  }
  else if (intermediate_value > 2254)
  {
    limited_value = 2254;
  }
  else
  {
    limited_value = intermediate_value;
  }
  return (unsigned char) (limited_value - 2000);
}


/*******************************************************************************
* FUNCTION NAME: User_Initialization
* PURPOSE:       This routine is called first (and only once) in the Main function.  
*                You may modify and add to this function.
* CALLED FROM:   main.c
* ARGUMENTS:     none
* RETURNS:       void
*******************************************************************************/
void User_Initialization (void)
{
  Set_Number_of_Analog_Channels(SIXTEEN_ANALOG);    /* DO NOT CHANGE! */

/* FIRST: Set up the I/O pins you want to use as digital INPUTS. */
  digital_io_01 = digital_io_02 = digital_io_03 = digital_io_04 = INPUT;
  digital_io_05 = digital_io_06 = digital_io_07 = digital_io_08 = INPUT;
  digital_io_09 = digital_io_10 = digital_io_11 = digital_io_12 = INPUT;
  digital_io_13 = digital_io_14 = digital_io_15 = digital_io_16 = INPUT;
  digital_io_18 = INPUT;  /* Used for pneumatic pressure switch. */
    /* 
     Note: digital_io_01 = digital_io_02 = ... digital_io_04 = INPUT; 
           is the same as the following:

           digital_io_01 = INPUT;
           digital_io_02 = INPUT;
           ...
           digital_io_04 = INPUT;
    */

/* SECOND: Set up the I/O pins you want to use as digital OUTPUTS. */
  digital_io_17 = OUTPUT;    /* Example - Not used in Default Code. */

/* THIRD: Initialize the values on the digital outputs. */
  rc_dig_out17 = 0;

/* FOURTH: Set your initial PWM values.  Neutral is 127. */
  pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;
  pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;

/* FIFTH: Set your PWM output types for PWM OUTPUTS 13-16.
  /*   Choose from these parameters for PWM 13-16 respectively:               */
  /*     IFI_PWM  - Standard IFI PWM output generated with Generate_Pwms(...) */
  /*     USER_CCP - User can use PWM pin as digital I/O or CCP pin.           */
  Setup_PWM_Output_Type(IFI_PWM,IFI_PWM,IFI_PWM,IFI_PWM);

  /* 
     Example: The following would generate a 40KHz PWM with a 50% duty cycle on the CCP2 pin:

         CCP2CON = 0x3C;
         PR2 = 0xF9;
         CCPR2L = 0x7F;
         T2CON = 0;
         T2CONbits.TMR2ON = 1;

         Setup_PWM_Output_Type(USER_CCP,IFI_PWM,IFI_PWM,IFI_PWM);
  */

  /* Add any other initialization code here. */
 
  Putdata(&txdata);             /* DO NOT CHANGE! */

  Serial_Driver_Initialize();

  printf("IFI 2006 User Processor Initialized ...\r");  /* Optional - Print initialization message. */

  User_Proc_Is_Ready();         /* DO NOT CHANGE! - last line of User_Initialization */
}

/*******************************************************************************
* FUNCTION NAME: Process_Data_From_Master_uP
* PURPOSE:       Executes every 26.2ms when it gets new data from the master 
*                microprocessor.
* CALLED FROM:   main.c
* ARGUMENTS:     none
* RETURNS:       void
*******************************************************************************/
void Process_Data_From_Master_uP(void)
{
  static unsigned char i;

  Getdata(&rxdata);   /* Get fresh data from the master microprocessor. */

  Default_Routine();  /* Optional.  See below. */

  /* Add your own code here. (a printf will not be displayed when connected to the breaker panel unless a Y cable is used) */

  printf("Port1 Y %3d, X %3d, Fire %d, Top %d\r",pwm01,pwm05,p1_sw_trig,p1_sw_top);  /* printf EXAMPLE */

  Generate_Pwms(pwm13,pwm14,pwm15,pwm16);

  /* Example code to check if a breaker was ever tripped. */

  if (aBreakerWa     ped)
  {
    for (i=1;i<29;i++)
    {
      if (Breaker_Tripped(i))
        User_Byte1 = i;  /* Update the last breaker tripped on User_Byte1 (to demonstrate the use of a user byte) 
                            Normally, you do something else if a breaker got tripped (ex: limit a PWM output)     */
    }
  }

  Putdata(&txdata);             /* DO NOT CHANGE! */
}

/*******************************************************************************
* FUNCTION NAME: Default_Routine
* PURPOSE:       Performs the default mappings of inputs to outputs for the
*                Robot Controller.
* CALLED FROM:   this file, Process_Data_From_Master_uP routine
* ARGUMENTS:     none
* RETURNS:       void
*******************************************************************************/
void Default_Routine(void)
{
 signed double wL, wR, velocity, rotation, wMax;

 velocity = (p1_y - 127);
 rotation = (p1_x - 127);
  

 wL = velocity - rotation;
 wR = velocity + rotation;


 wMax = intMax(127, intABS(wL));
 wMax = intMax(wMax, intABS(wR));
 wL = (wL * 127 / wMax);

 if (-127 > wL || wL > 127)
   printf("Received an unexpected number [wL] /n");
else
 {
  wR = (wR * 127 / wMax);
  if (-127 > wR || wR > 127)
    printf("Received an unexpected number [wR] /n");
 
  else
   {

 pwm01 = wL + 127;
 pwm02 = 127 - wR;
  
if (rc_dig_in01 == 1) { //If tank pressure is 120...
relay2_fwd = 0;
relay2_rev = 0;
}
else {
relay2_fwd =1;
relay2_rev = 0;
}
}
}

 /*---------- Buttons to Relays----------------------------------------------
  *--------------------------------------------------------------------------
  *  This default code maps the joystick buttons to specific relay outputs.  
  *  Relays 1 and 2 use limit switches to stop the movement in one direction.
  *  The & used below is the C symbol for AND                                
  */
  
relay1_fwd = p1_sw_trig;
relay1_rev = p1_sw_top; //Will kick if trigger is pulled, retract if top button is pushed. No button = no kicker action.


 /*---------- ROBOT FEEDBACK LEDs------------------------------------------------
  *------------------------------------------------------------------------------
  *   This section drives the "ROBOT FEEDBACK" lights on the Operator Interface.
  *   The lights are green for joystick forward and red for joystick reverse.
  *   Both red and green are on when the joystick is centered.  Use the
  *   trim tabs on the joystick to adjust the center.     
  *   These may be changed for any use that the user desires.                       
  */	
  
  if (user_display_mode == 0) /* User Mode is Off */
    
  { /* Check position of Port 1 Joystick */
    if (p1_y >= 0 && p1_y <= 56)
    {                     /* Joystick is in full reverse position */
      Pwm1_green  = 0;    /* Turn PWM1 green LED - OFF */
      Pwm1_red  = 1;      /* Turn PWM1 red LED   - ON  */
    }
    else if (p1_y >= 125 && p1_y <= 129)
    {                     /* Joystick is in neutral position */
      Pwm1_green  = 1;    /* Turn PWM1 green LED - ON */
      Pwm1_red  = 1;      /* Turn PWM1 red LED   - ON */
    }
    else if (p1_y >= 216 && p1_y <= 255)
    {                     /* Joystick is in full forward position*/
      Pwm1_green  = 1;    /* Turn PWM1 green LED - ON  */
      Pwm1_red  = 0;      /* Turn PWM1 red LED   - OFF */
    }
    else
    {                     /* In either forward or reverse position */
      Pwm1_green  = 0;    /* Turn PWM1 green LED - OFF */
      Pwm1_red  = 0;      /* Turn PWM1 red LED   - OFF */
    }  /*END Check position of Port 1 Joystick
    
    /* Check position of Port 2 Y Joystick 
           (or Port 1 X in Single Joystick Drive Mode) */
    if (p2_y >= 0 && p2_y <= 56)
    {                     /* Joystick is in full reverse position */
      Pwm2_green  = 0;    /* Turn pwm2 green LED - OFF */
      Pwm2_red  = 1;      /* Turn pwm2 red LED   - ON  */
    }
    else if (p2_y >= 125 && p2_y <= 129)
    {                     /* Joystick is in neutral position */
      Pwm2_green  = 1;    /* Turn PWM2 green LED - ON */
      Pwm2_red  = 1;      /* Turn PWM2 red LED   - ON */
    }
    else if (p2_y >= 216 && p2_y <= 255)
    {                     /* Joystick is in full forward position */
      Pwm2_green  = 1;    /* Turn PWM2 green LED - ON  */
      Pwm2_red  = 0;      /* Turn PWM2 red LED   - OFF */
    }
    else
    {                     /* In either forward or reverse position */
      Pwm2_green  = 0;    /* Turn PWM2 green LED - OFF */
      Pwm2_red  = 0;      /* Turn PWM2 red LED   - OFF */
    }  /* END Check position of Port 2 Joystick */
    
    /* This drives the Relay 1 and Relay 2 "Robot Feedback" lights on the OI. */
    Relay1_green = relay1_fwd;    /* LED is ON when Relay 1 is FWD */
    Relay1_red = relay1_rev;      /* LED is ON when Relay 1 is REV */
    Relay2_green = relay2_fwd;    /* LED is ON when Relay 2 is FWD */
    Relay2_red = relay2_rev;      /* LED is ON when Relay 2 is REV */

    Switch1_LED = !(int)rc_dig_in01;
    Switch2_LED = !(int)rc_dig_in02;
    Switch3_LED = !(int)rc_dig_in03;
    
  } /* (user_display_mode = 0) (User Mode is Off) */
  
  else  /* User Mode is On - displays data in OI 4-digit display*/
  {
    User_Mode_byte = backup_voltage*10; /* so that decimal doesn't get truncated. */
  }   
  
} /* END Default_Routine(); */



/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
__________________
Team 2052- Knightkrawler
Mentor and volunteer
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coder Error Light paulcd2000 Programming 7 10-02-2007 15:52
180:Error: syntax error help! seanl Programming 8 04-02-2007 11:31
GTS Code Error (the red light of doom!) Denz Programming 9 07-04-2006 17:39
stupid Array error: Error [1300] stack frame too l Validius Programming 7 27-01-2006 10:53
C++ Code Error? Adam Shapiro Programming 9 20-01-2003 13:24


All times are GMT -5. The time now is 11:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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