Go to Post Geez, now I'm like some all-knowing all-seeing FIRST sage who lives in the moutains waiting for students to venture upwards to my home to ask me if there will ever be a water game....:rolleyes: - 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

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-03-2004, 09:51
jaywion jaywion is offline
Registered User
#0842
 
Join Date: Jan 2004
Location: Phoenix, AZ
Posts: 3
jaywion is an unknown quantity at this point
Post Need help with my code

[/font][/size][/color]I need help with my code, its not working so far in Autonomous mode. We didn't have one at Reginals and want one for nationals please tell me whats wrong with my code.

void User_Autonomous_Code(void)
{

//A handy-dandy macro to convert a number of seconds into a number of 26.2ms ticks
#define SECS_TO_TICKS(a) ( ((long)(a)) * (long)10000 / (long)262 )
//And milliseconds too:
#define MSECS_TO_TICKS(a) ( ((long)(a)) * (long)10 / (long)262 )

/* 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;

tickCount=0;

AUTO_STATE = AUTO_FIRST_STATE;

while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */
printf("In auto mode ");

tickCount++; //tickCount contains the number of 26.2ms "ticks" since the start of the current step

switch (AUTO_STATE)
{
case AUTO_FIRST_STATE:
printf ("First, we go forward for 3 secz %d", (int)tickCount);
pwm13 = 127+100;
pwm15 = 127+100;
printf ("in auto first state pmw13= %d\n",(int)pwm13);
if(tickCount >= SECS_TO_TICKS(1))
{
AUTO_STATE = AUTO_FINISHED; //AUTO_SECOND_STATE;
tickCount = 0;
}
break;
case AUTO_SECOND_STATE:
pwm13 = 127 + 50; pwm15 = 127;

if(tickCount >= SECS_TO_TICKS(3))
{
AUTO_STATE = AUTO_THIRD_STATE;
tickCount = 0;
}
break;
case AUTO_THIRD_STATE:
relay3_fwd=1;
pwm01 = 127; pwm02 = 127;

if(tickCount >= SECS_TO_TICKS(3))
{
AUTO_STATE = AUTO_FOURTH_STATE;
tickCount = 0;
}
break;

case AUTO_FINISHED:
pwm13 = pwm15 = 127;
tickCount=0;
break;
default:
pwm01 = pwm02 = 127;
tickCount=0;
}// end switch



printf("READY to Put Data pwm13 = %d pwm 15=%d/n",(int)pwm13, (int)pwm15);
DisplayBufr( &rxdata ); // Print the 26 bytes received from the Master processor.

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}// end if
}// end while
}// end User_Autonomous_Code
  #2   Spotlight this post!  
Unread 19-03-2004, 10:18
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: Need help with my code

Quote:
Originally Posted by jaywion
I need help with my code, its not working so far in Autonomous mode. We didn't have one at Reginals and want one for nationals please tell me whats wrong with my code.
What is it supposed to do? I noticed one odd thing right away:
Code:
		if(tickCount >= SECS_TO_TICKS(1))
		{
			AUTO_STATE = AUTO_FINISHED; //AUTO_SECOND_STATE;
			tickCount = 0;
		}
Is it really supposed to go to the AUTO_FINISHED state after one second, or did you mean for it to go to AUTO_SECOND_STATE instead?

(If you surround your code with [code] and [/code] tags when you post it here, the whitespace formatting will be preserved.)
  #3   Spotlight this post!  
Unread 19-03-2004, 12:53
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Need help with my code

what does
break;
do? does it make the code stop?
  #4   Spotlight this post!  
Unread 19-03-2004, 13:21
WebWader125
 
Posts: n/a
Re: Need help with my code

Ken: the "break" statement tells the code to go to the end of the enclosing conditional block. In this case, break prevents the code from falling into the next case.

Alan: I assume that he commented out AUTO_SECOND_STATE for debugging.

jaywion: What behavior are you seeing that you don't like?
  #5   Spotlight this post!  
Unread 20-03-2004, 11:09
jaywion jaywion is offline
Registered User
#0842
 
Join Date: Jan 2004
Location: Phoenix, AZ
Posts: 3
jaywion is an unknown quantity at this point
Re: Need help with my code

Quote:
Originally Posted by WebWader125
Ken: the "break" statement tells the code to go to the end of the enclosing conditional block. In this case, break prevents the code from falling into the next case.

Alan: I assume that he commented out AUTO_SECOND_STATE for debugging.

jaywion: What behavior are you seeing that you don't like?
The behavior I dont like is the same I am sure others dont like and that is just sitting their in antonymous mode. It's really disappointing to see that and so I need to fix this code to get the antonymous to work.
  #6   Spotlight this post!  
Unread 20-03-2004, 11:31
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Need help with my code

I suspect Alan's diagnosis (below) is correct. Have you tried it yet? (Or do you have to wait until the championships before you can try it?)
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #7   Spotlight this post!  
Unread 20-03-2004, 11:32
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Need help with my code

What Alan Anderson said - that is exactly why your pwms dont change
  #8   Spotlight this post!  
Unread 19-03-2004, 14:04
jaywion jaywion is offline
Registered User
#0842
 
Join Date: Jan 2004
Location: Phoenix, AZ
Posts: 3
jaywion is an unknown quantity at this point
Re: Need help with my code

Quote:
Originally Posted by Alan Anderson
What is it supposed to do? I noticed one odd thing right away:
Code:
		if(tickCount >= SECS_TO_TICKS(1))
		{
			AUTO_STATE = AUTO_FINISHED; //AUTO_SECOND_STATE;
			tickCount = 0;
		}
Is it really supposed to go to the AUTO_FINISHED state after one second, or did you mean for it to go to AUTO_SECOND_STATE instead?

(If you surround your code with [code] and [/code] tags when you post it here, the whitespace formatting will be preserved.)
I am trying to get it to go forward for so long then stop. The finish call in that area is to see if it goes through the loop but your right it shouldn't be their. Altho we did that the code is not being sent to the PWMs.
  #9   Spotlight this post!  
Unread 19-03-2004, 14:17
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Need help with my code

do any of the printfs print out?

first thing I would try is get rid of the Tic-count stuff and just put numbers in - 38 per second

Last edited by KenWittlief : 19-03-2004 at 14:19.
  #10   Spotlight this post!  
Unread 19-03-2004, 15:36
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: Need help with my code

Oh! This is an old -- and solved -- problem. It doesn't have anything to do with what you wrote. The default code just fails to control the last four pwm outputs in the User_Autonomous_Code() function.
Quote:
Originally Posted by seanwitte
Insert the line "Generate_Pwms(pwm13,pwm14,pwm15,pwm16);" right before
"Putdata(&txdata);" in User_Autonomous_Code().
That should take care of it. (If you had said at the beginning that you weren't getting any response from the pwm outputs, we might have recognized it sooner.)
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
What is your most prefered programming language? Hailfire Programming 156 19-01-2005 21:42
Interrupt timer, executing code asap? SeanCassidy Programming 10 07-03-2004 01:47
Updated Infrared Tracking Code Kevin Watson Programming 0 18-02-2004 21:41
Inserting Naviagation code into Default code? actorindp Programming 3 28-01-2004 18:12
Does your team use the Default code. Jeff McCune General Forum 2 09-01-2003 14:46


All times are GMT -5. The time now is 02:42.

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