Go to Post Successful teams - in almost any aspect of life (i.e. not just robotics) - don't make excuses and assign blame when something goes wrong. They improvise. They adapt. They overcome. They correct the problem and move on. - dlavery [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 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
  #2   Spotlight this post!  
Unread 14-01-2008, 09:55
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: Help Autonomous code not working

1: You say it doesn't work, but that isn't enough information. Tell us what you expect it to do, and tell us what it's doing instead.

2: Put code between [ code ] and [ /code ] tags when you post it here. It will preserve the formatting.

3: Don't use delay loops the way it looks like you're trying to. If you take too long before calling the Putdata() function, the master CPU assumes your code is hung and signals a code error. You'll need to figure out how to execute the complete while (autonomous_mode) loop without pausing in the middle.
  #3   Spotlight this post!  
Unread 14-01-2008, 09:58
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
Re: Help Autonomous code not working

we are trying to make the bot go forward constantly but have the ir have control over the autonomus code
  #4   Spotlight this post!  
Unread 14-01-2008, 10:10
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,587
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Help Autonomous code not working

I'm a little confused, or possibly you are. All of your cases in your big switch statement there are appropriately written to let the robot framework do your looping and timing.... Except the very first case, FORWARD. You have a do-while loop there that will process in about 1ms and then kick you straight into the right turn. If you change this first case from using a fruitless do-while to the proper if(delay == 0) structure of all your other cases, I think your code might work. At the very least the FORWARD case would work.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #5   Spotlight this post!  
Unread 14-01-2008, 10:33
seanl's Avatar
seanl seanl is offline
"The Everything person"
FRC #0867 (Absolute Value)
Team Role: Leadership
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Arcadia, CA
Posts: 267
seanl will become famous soon enoughseanl will become famous soon enough
Re: Help Autonomous code not working

you cant do the delay like that it would delay the 26 ms. loop time which in turn would cause a code error on the robot. i figured that out in the summer. the only way you could pull off a delay is by adding a global vaiable that counts the number of iterations of the while loop in the autonomous code.

1. declare a variable at the top
2. put a (variable)++ in the loop
3. use the variable as a counter for your delay.
__________________
, Sean

TEAM 867
-electrical
-pneumatics
-programming



2008 Autodesk Visualization Grand Prize Winner
  #6   Spotlight this post!  
Unread 14-01-2008, 10:35
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
Re: Help Autonomous code not working

i thank you we moved the initial if statement above the while and that fixed the code
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
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 08:22.

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