Go to Post If you want to change the culture sometimes you need to change a little yourself - Koko Ed [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 14-01-2008, 09:43
team550 team550 is offline
Registered User
FRC #0550
 
Join Date: Nov 2005
Location: washington nj
Posts: 8
team550 is an unknown quantity at this point
Help Autonomous code not working

Quote:
/************************************************** *****************************
* FILE NAME: user_routines_fast.c <FRC VERSION>
*
* DESCRIPTION:
* This file is where the user can add their custom code within the framework
* of the routines below.
*
* USAGE:
* You can either modify this file to fit your needs, or remove it from your
* project and replace it with a modified copy.
*
* OPTIONS: Interrupts are disabled and not used by default.
*
************************************************** *****************************/

#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "user_Serialdrv.h"


/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/

#define FORWARD 0

#define RIGHT 1

#define LEFT 2

#define BACKWARD 3

#define SLOW_FORWARD 5

static unsigned int delay;

static unsigned int direction;

/************************************************** *****************************
* FUNCTION NAME: InterruptVectorLow
* PURPOSE: Low priority interrupt vector
* CALLED FROM: nowhere by default
* ARGUMENTS: none
* RETURNS: void
* DO NOT MODIFY OR DELETE THIS FUNCTION
************************************************** *****************************/
#pragma code InterruptVectorLow = LOW_INT_VECTOR
void InterruptVectorLow (void)
{
_asm
goto InterruptHandlerLow /*jump to interrupt routine*/
_endasm
}


/************************************************** *****************************
* FUNCTION NAME: InterruptHandlerLow
* PURPOSE: Low priority interrupt handler
* If you want to use these external low priority interrupts or any of the
* peripheral interrupts then you must enable them in your initialization
* routine. Innovation First, Inc. will not provide support for using these
* interrupts, so be careful. There is great potential for glitchy code if good
* interrupt programming practices are not followed. Especially read p. 28 of
* the "MPLAB(R) C18 C Compiler User's Guide" for information on context saving.
* CALLED FROM: this file, InterruptVectorLow routine
* ARGUMENTS: none
* RETURNS: void
************************************************** *****************************/
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD /* You may want to save additional symbols. */

void InterruptHandlerLow ()
{
unsigned char int_byte;
if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) /* The INT2 pin is RB2/DIG I/O 1. */
{
INTCON3bits.INT2IF = 0;
}
else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) /* The INT3 pin is RB3/DIG I/O 2. */
{
INTCON3bits.INT3IF = 0;
}
else if (INTCONbits.RBIF && INTCONbits.RBIE) /* DIG I/O 3-6 (RB4, RB5, RB6, or RB7) changed. */
{
int_byte = PORTB; /* You must read or write to PORTB */
INTCONbits.RBIF = 0; /* and clear the interrupt flag */
} /* to clear the interrupt condition. */
else
{
CheckUartInts(); /* For Dynamic Debug Tool or buffered printf features. */
}
}


/************************************************** *****************************
* FUNCTION NAME: User_Autonomous_Code
* PURPOSE: Execute user's code during autonomous robot operation.
* You should modify this routine by adding code which you wish to run in
* autonomous mode. It will be executed every program loop, and not
* wait for or use any data from the Operator Interface.
* CALLED FROM: main.c file, main() routine when in Autonomous mode
* ARGUMENTS: none
* RETURNS: void
************************************************** *****************************/
void User_Autonomous_Code(void)

// Base Level
{
/* 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! */
// Autonnmous mode Level
{
direction = FORWARD; /* initial jump for switch */
delay = 191; /* 5 second delay (191 * .0262ms = ~5s) */

if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
// Get and Send Data Level
{

Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */

/************************************************** *****************************

* FUNCTION NAME: User_Autonomous_Code

* PURPOSE: Execute user's code during autonomous robot operation.

* You should modify this routine by adding code which you wish to run in

* autonomous mode. It will be executed every program loop, and not

* wait for or use any data from the Operator Interface.

* CALLED FROM: main.c file, main() routine when in Autonomous mode

* ARGUMENTS: none

* RETURNS: void

************************************************** *****************************/



/*
This code demostrates how to move a robot in autonomous mode. When invoked,

the robot will move forward for 5 seconds, turn right for 1 second, backup

for 2 seconds, turn left for 1 second then continue forward at a slow speed

until autonomous mode is deactivated.



Two motors should be hooked up to pwms 4 and 3. The wiring on one motor should

be swapped in reference to the other motor (on the victor output terminals).

When autonomous mode is complete, pwm 4 and pwm 3 are set to neutral.

*/

switch (direction)

// Switch Level
{

case FORWARD:

do {pwm04 = pwm03 = 127 + 60;
delay --;}

while (delay !=0)

direction = RIGHT;

delay = 38; /* 1 second delay (38 * .0262ms = ~1s) */

break;

case RIGHT:

pwm04 = 127 - 40; /* do a slow right turn */

pwm03 = 127 + 40;

delay--;

if (delay == 0)

{

direction = BACKWARD;

delay = 76; /* 2 second delay (76 * .0262ms = ~2s) */

}

break;

case BACKWARD:

pwm04 = 127 - 50; /* go backwards for 2 seconds */

pwm03 = 127 - 50;

delay--;

if (delay == 0)

{

direction = LEFT;

delay = 38; /* 1 second delay (38 * .0262ms = ~1s) */

}

break;

case LEFT:

pwm04 = 127 + 40; /* do a slow left turn */

pwm03 = 127 - 40;

delay--;

if (delay == 0)

{

direction = SLOW_FORWARD;

delay = 1; /* immediately go forward at a slow rate */

}

break;

case SLOW_FORWARD:

pwm04 = pwm03 = 127 + 30; /* go forward slowly */

break;

} /* end SWITCH secton */

/* Generate_Pwms(pwm13,pwm14,pwm15,pwm16); - not needed if your not using pwms 13-16 */

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

} /* status flag section */

pwm04 = 127; /* set to neutral after autonomous mode */

pwm03 = 127;

}

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

}

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


/************************************************** *****************************
* FUNCTION NAME: Process_Data_From_Local_IO
* PURPOSE: Execute user's realtime code.
* You should modify this routine by adding code which you wish to run fast.
* It will be executed every program loop, and not wait for fresh data
* from the Operator Interface.
* CALLED FROM: main.c
* ARGUMENTS: none
* RETURNS: void
************************************************** *****************************/
void Process_Data_From_Local_IO(void)
{
/* Add code here that you want to be executed every program loop. */

}

/************************************************** *****************************
* FUNCTION NAME: Serial_Char_Callback
* PURPOSE: Interrupt handler for the TTL_PORT.
* CALLED FROM: user_SerialDrv.c
* ARGUMENTS:
* Argument Type IO Description
* -------- ---- -- -----------
* data unsigned char I Data received from the TTL_PORT
* RETURNS: void
************************************************** *****************************/

void Serial_Char_Callback(unsigned char data)
{
/* Add code to handle incomming data (remember, interrupts are still active) */
}


/************************************************** ****************************/
/************************************************** ****************************/
/************************************************** ****************************/
that is our autonomus code and it appears it should work fine but doesnt
any help or suggestions is greatly appriciated
 


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
Incrementation Code not working benhulett Programming 6 12-02-2007 17:39
easyc demo code not working sniggel Programming 5 28-01-2007 16:40
Camera not working in autonomous Roger Programming 9 09-03-2006 07:38
Camera code not working.... DemonYawgmoth Programming 5 11-02-2006 09:21
Gyro not working in Autonomous? kaszeta Programming 7 11-02-2006 01:28


All times are GMT -5. The time now is 09:59.

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