Go to Post FIRST is a pretty decent microcosm of real life, those who work hard, accomplish more decent lesson to learn, and FIRST is allowing us to learn it. - Aren_Hill [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 12-02-2003, 22:53
cantwell03's Avatar
cantwell03 cantwell03 is offline
Registered User
#0651 (Schuylkillbotics)
 
Join Date: Feb 2003
Location: Schuylkill County, PA
Posts: 1
cantwell03 is an unknown quantity at this point
Send a message via AIM to cantwell03
Ok one problem

When creating my code for the Autonomous mode, i'm running into a problem with making a counter of some sort so i can change directions or perform actions during the mode. I thought i'd try setting up one like most other languages time = time + 1 << thats how i know how to do it, its plan and simple. I've not had too much experiene with PBASIC but there must be another way.

Also my if statments sorta go like this, are they the problem?

if time < (a certain time) then do_a_turn

do_a_turn:
"turn code"

if theres something wrong with that lemme know too. I'm probly doing something really dumb, but its a big problem we're having.
thanks!
  #2   Spotlight this post!  
Unread 13-02-2003, 00:52
Anthony Kesich's Avatar
Anthony Kesich Anthony Kesich is offline
Programmer Turned Engineer
AKA: SonKenshin
#1097 (Site 3 Engineernig)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Sacramento, CA
Posts: 186
Anthony Kesich has a spectacular aura aboutAnthony Kesich has a spectacular aura about
Send a message via AIM to Anthony Kesich
Re: Ok one problem

Quote:
Originally posted by cantwell03
if time < (a certain time) then do_a_turn

do_a_turn:
"turn code"
Here's the problem my friend. No matter what, your code will execute your "turn code." If the if statement is found to be true, it will jump to do_a_turn, if it is found to be false, then it will just keep going and run into the "turn code" so your code is right except for one thing, you need a goto statement between your if/then and your lable. It would look something like this:

Code:
if time < (a certain time) then do_a_turn:
 goto skip_do_a_turn:

do_a_turn:
 "turn code"

skip_do_a_turn:
kinda ugly and confusing, wouldn't you say? so i prefere an alternate meathod of inverting your ifthen statements, which would look like this:

Code:
if time >= (a certain time) then skip_turn:
 "turn code"
skip_turn:
a lot simpler. if you look at it, it does the same as the previous code. In the first one, if the time is greater than the set time, then it would keep going, hit the goto statement, and skip the code. if it were less than, it would jump to the code and preform it. on the seconf one, if it were greater, it would jump to the lable, skipping the "turn code." if it were less than, it would just keep going and preform the turn. Hope this helps.

-Kesich
__________________
C is screwing up my English--I'm ending all my sentences in semi-colons;

Horray for most things! -George Carlin

"Sure, I'll play rugby. Besides, I have a lot of experience running from really big guys who want to cream me." -Me, Freshman year
  #3   Spotlight this post!  
Unread 13-02-2003, 01:00
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,604
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
assuming you want to use pbasic 2.0 syntax, the easiest way (that I have found) to keep everything straight is to do something like this:
Code:
if condition1 then do_condition1
if condition2 then do_condition2
if condition3 then do_condition3
'add else condtion here if necessary
goto end_conditions

do_condition1:
   'condition1 code here
goto end_conditions

do_condition2:
   'condition2 code here
goto end_conditions

do_condition3:
   'condition 3 code here
goto end_conditions

end_conditions:
'increment counter or whatever else you want to do.
doing this allows you to add as many conditions as you want very easily.

this would be equivilent to a nested if...else if...else if...else statement in C.
  #4   Spotlight this post!  
Unread 13-02-2003, 07:28
RoboCoder RoboCoder is offline
Registered User
#1002 (Circuit Runner)
 
Join Date: Jan 2003
Location: Wheeler High School, Marietta Ga
Posts: 65
RoboCoder is on a distinguished road
Send a message via AIM to RoboCoder Send a message via Yahoo to RoboCoder
PBASIC 2.5

If you are using PBASIC 2.5, then try using the select / case statements like so:

select (timer)
case 0 to 300
'code to make robot go straight
case 301 to 500
'turning code
'.....etc
endselect


that way it will go to the section of code you want, and it stays neat, orderly, and you dont have to mess with a ton and a half of labels
__________________
You might be an Engineering Major....

if you'll assume that a "horse" is a "sphere" in order to make the math easier

if you know vector calculus but you cant remember how to do long division

if it is sunny and 70 degrees outside, and you are working on a computer
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
Victor problem Andy Baker Electrical 15 24-06-2003 09:49
The problem with scouting... archiver 2001 10 23-06-2002 23:49
joystick problem archiver 2000 12 23-06-2002 23:08
Major problem with chipphua motors aka Scott White Motors 18 19-03-2002 19:44
Heres a big problem that I think Discreet does not know what they are talking about. wes16zeus 3D Animation and Competition 9 09-01-2002 23:31


All times are GMT -5. The time now is 23:54.

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