Go to Post The championship event is a meta-game of inches. People will complain about unbalanced/unequal divisions, whether you think it's silly or not. - PayneTrain [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 31-01-2002, 22:30
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Subtotaling in PBASIC?

This is a pretty obvious question:

Is it possible to subtotal in PBASIC? Like, every time a cycle completes, a variable, lets call it Counter, goes up one?

I know in C++ to do that it's simple, just one line of code:

Counter = Counter + 1;
or
Counter++;

If I can, how can I do that in PBASIC? My other programming sidekick thought it would just be:

Counter = Counter + 1

Then, once a cycle, Counter would increase one integer, and eventually a "If Statement" would reset it to zero. I'm not sure if that syntax is right, and I figured might as well ask, and save some time and lots of possible fustration, as was caused with the switch operated PWMs, as some of you know . So, if I'm right, thanks, if I'm completely wrong, well, don't feel bad to be brutaly honest, even though that really isn't the spirit here, which is good.

Thanks,
Ian W.
  #2   Spotlight this post!  
Unread 31-01-2002, 22:34
Manoel's Avatar
Manoel Manoel is offline
Registered User
FRC #0383 (Brazilian Machine)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Porto Alegre, RS, Brazil
Posts: 608
Manoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond repute
Send a message via ICQ to Manoel Send a message via MSN to Manoel
Unless I'm very wrong, that is possible
__________________
Manoel Flores da Cunha
Mentor
Brazilian Machine
Team # 383
  #3   Spotlight this post!  
Unread 31-01-2002, 22:39
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Yay! That makes everything so much easier! I think. Hmm, I wonder if I can tell you what I want this for. Nah, not now. I'll tell you guys in a few weeks. Thanks.

Now, off to the nice bed, blanket, and best of all, pillow!

*Goes to sleep with grin on face, dreaming about PBASIC...*

  #4   Spotlight this post!  
Unread 31-01-2002, 22:40
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
How about tring this...

Your syntax is correct.

Counter = Counter +1

Does what it does in nearly every programming language (despite the fact that it makes math profs crazy!).

Perhaps a better idea for what you are trying to do is:

Time = Time + 1 + Delta_T

Where Delta_T is the variable passed to you by the master CPU that tells you how many data packets you have missed since the last time you got a good packet of data from the master CPU.

If you use this construct, you will have a more reliable method to have something stay on for 2 seconds for example.

If you just use counter as you initially proposed, your loop time figures into the time that passes before you reach a set number. Also figured into the mix is the fact that you may have a noisy radio environment or you may have some other problem communicating with the OE.

In these cases, you can have the time until counter reaches a fixed number vary by mulitples of 2 or 3.

With Delta_T added in, your program takes into account the fact that you missed packets and thus your time estimations are more robust.

Joe J.
  #5   Spotlight this post!  
Unread 31-01-2002, 22:43
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Hmm, I wish I spoke techie too...

I understood everything you said up to the Delta_T part. All we want the Counter is to count how long a switch is on for, and to automatically turn it off. We hope it works, because it just makes our lives easier (the way our robot is set up). So, does the Delta_T really matter? If it does, can you "dumb-down" the language so I can understand it? Or maybe I just need more sleep.
  #6   Spotlight this post!  
Unread 31-01-2002, 22:54
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Here is the thing...

You cannot count on how long it will take you to get through a loop of your program.

If you have a program that is complex, you may make it in 24 msec one time and 26 msec in another.

If you make it in 24 msec, you MAY be ready to receive the next packet of data that comes from the OI, if you take 26msec, you will definitely MISS the data packet and have to wait around until the next one arrives (which will be a while because they only come at best at 25 msec intervals).

Now, add to that that not all data packets make it through intact you you begin to realize that you will only get to increment your counter at variable intervals. The intervals are outside of your programs control.

So....

What is a clever sheep supposed to do?

Well, FIRST gives you some help. If you ask for it (by setting c_Delta_T = 1 in the default program and by including Delta_T in your SERIN command, which gets data from the master CPU), the master CPU will tell you how many data packets you missed since the last time you got data from it.

SO...

Rather than just adding 1 to counter each time through the loop, you can add in Delta_T, the number of data packets you missed. This will help you keep your clock up to speed even when your program is running slower (perhaps because you left a Debug statement in the code -- you naughty little debugger you) or because you are at a competition and there are many other robots broadcasting on frequencies very near your own.

It is not a big deal but it is a better mouse trap if you care to build it.

Joe J.
  #7   Spotlight this post!  
Unread 01-02-2002, 12:10
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
That makes a bit more sense to me. Not completely, but enough so that I can explain it to someone who will. Thanks again, now we can possible make our robot all nice and happy.
  #8   Spotlight this post!  
Unread 01-02-2002, 12:58
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Hmm, as it stands now, I just need to count an approx. time (say 3 seconds), and then something will occur. Do I need the Delta_T thing if I'm just counting approx. times? Or should I still try to implement it just for the heck of it? Can someone please help me?
  #9   Spotlight this post!  
Unread 01-02-2002, 13:06
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Depends on consequences...

If 3 seconds is good and 4 or 6 seconds is okay. Don't bother.

If 4 seconds is very bad and 6 seconds is very very bad, you have to do it using Delta_T.

If you are anal retentive, you do it just because you can and that means you should ;-)

Joe J.
  #10   Spotlight this post!  
Unread 01-02-2002, 13:10
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Hmm, looks like I'll have to use the Delta_T thingy. Luckily, I think that there's at least one or two other people who will be able to explain how it works to me in more detail then can be explained here. Thanks for your help, now for a bit of code writting and most likely a lot of trial and error. Whee!
  #11   Spotlight this post!  
Unread 01-02-2002, 13:14
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Where is Delta_T added to the serin command? I've figured out everything but that, I think. If all works, then just adding it to the serin command, and waiting about one hour (I'm still in school, we have a sub in my computer science class) untill i can get to the robot, and we shall see if it works. Yay!
  #12   Spotlight this post!  
Unread 01-02-2002, 13:50
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
Quote:
Originally posted by Joe Johnson
Rather than just adding 1 to counter each time through the loop, you can add in Delta_T, the number of data packets you missed.
Joe,
I don't remember whether Delta_T means the-number-of-packets-your-program-missed-since-you-successfully-received-a-data-packet, or the-number-of-cycles-since-you-last-successfully-received-a-data-packet. So the question is: should you add 1+Delta_T to your counter each time (if the former is true), or just Delta_T?
__________________
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

Last edited by Greg Ross : 01-02-2002 at 14:49.
  #13   Spotlight this post!  
Unread 01-02-2002, 15:05
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Yay! It works! I haven't tried the Delta_T thing yet, because I'm not sure where it goes into the Serin command. If someone can tell me this, then I can make it even better, but as of now, we can use a relay with one two-pole toggle switch. Yay! Thanks guys! Now, who wants to tell me where the Delta_T goes into the Serin command?
  #14   Spotlight this post!  
Unread 01-02-2002, 18:26
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,605
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
Quote:
Originally posted by gwross

I don't remember whether Delta_T means the-number-of-packets-your-program-missed-since-you-successfully-received-a-data-packet, or the-number-of-cycles-since-you-last-successfully-received-a-data-packet. So the question is: should you add 1+Delta_T to your counter each time (if the former is true), or just Delta_T?
delta_t contains the number of packets missed, so to do a counter you would need to say counter = counter + 1 + delta_t

Quote:
Originally posted by Ian W.
I haven't tried the Delta_T thing yet, because I'm not sure where it goes into the Serin command.

You will notice in the code that there are two serin statements. The top one is commented out, but has all the variables listed in it in the proper order. The second one is the one that is actually used. put delta_t in the same spot as it is in the first one (almost for sure it would be last). You also need to change C_deta_t to 1 like Joe J. said in an earlier message.

Hope this helps
  #15   Spotlight this post!  
Unread 01-02-2002, 18:39
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
Ok, thanks. I figured it would go near the end, but I wasn't completely sure, and I didn't want to screw up the uP.
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
PBASIC ARCTAN function Greg Ross Programming 14 11-05-2003 12:28
Need to learn PBASIC...Where Should I Go? IMDWalrus Programming 5 29-04-2003 16:43
Obscure PBASIC for RoboEmu rbayer Programming 1 28-03-2003 23:57
PBasic 2.5 vs. 2.0 Anthony Kesich Programming 6 09-02-2003 22:06
RoboEmu v.1a (another PBASIC emulator) rbayer Programming 0 07-07-2002 00:45


All times are GMT -5. The time now is 20: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