Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PBasic Question (http://www.chiefdelphi.com/forums/showthread.php?t=14703)

Melissa H. 06-10-2002 20:53

PBasic Question
 
I'm new to programming PBasic...though I know a little of C and C++(very minimal though :( ) I was wondering, how can I start learning PBasic and/or find out more on this programming language?

Anything would be helpful!:D

rbayer 06-10-2002 21:27

My advice would be to grab the default code from InnovationFIRST's website (http://www.innovationfirst.com) and go through it line-by-line until you understand it.

After that, I'd try playing around with my emulator (http://FIRSTprograms.tripod.com/Programs.htm) and see what comes out. If you ever run into problems, post them here and you'll get an answer in a few hours at the most.

Also, if you feel like a challenge, here is the code we used last year: http://FIRSTprograms.tripod.com/cog2002.txt

Ian W. 06-10-2002 21:34

Quote:

Originally posted by rbayer
My advice would be to grab the default code from InnovationFIRST's website (http://www.innovationfirst.com) and go through it line-by-line until you understand it.

what he said. that's what i did, and considering i had about 2 hours to learn it, i did pretty good.

Melissa H. 07-10-2002 07:12

Thanks for the help!!! The http://www.innovationfirst.com was probably the most helpful (with the default program and all....:D )

Matt Reiland 07-10-2002 15:30

Even more fun!!
 
1 Attachment(s)
Here is some Swerve code broken into processor slots if you get bored.

Hopefully your team can get the edu robot to try out or get your hands on a IFI controller. For right now the emulator is great also.

Thanks for the hard work rbayer!

PBasic is not that hard but living in the hardware limitations is more difficult.

f22flyboy 31-10-2002 14:19

Quote:

Originally posted by rbayer


Also, if you feel like a challenge, here is the code we used last year: http://FIRSTprograms.tripod.com/cog2002.txt

I get most of it, but I am confused by this line:


if ((gear_shifting=1) and (gear_count=10)) then shift


do you have to press the top button of your joystick 10 times to shift?

I'm still learning this code so if this is a stupid question feel free to flame me.

Matt Reiland 31-10-2002 14:45

Quote:

Originally posted by f22flyboy


I get most of it, but I am confused by this line:


if ((gear_shifting=1) and (gear_count=10)) then shift


do you have to press the top button of your joystick 10 times to shift?


My best guess for the code is you have to press the top button to shift gears which will stop both drive motors while the shift takes place, they increment a counter for a delay (gear_count) when it increments to 10 the shift takes place (relay lowGear toggles) when gear_count hits 40 it looks like the section gets skipped over

BUt I am not sure where gear_shifting ever gets reset back to zero after the first initialization.?

f22flyboy 31-10-2002 14:55

How long
 
Do you have any idea how long it would be? Does is there a preset time for counter-type variables, or does it depend on the rest of your program?

f22flyboy 31-10-2002 15:00

startShift:
leftDrive=127
rightDrive=127
gear_shifting=1
gear_count=0




also what is this here for?

p1_sw_top_prev=p1_sw_top

I see that it sets p1_sw_top_prev=0 but why not just say that?

SlamminSammy 31-10-2002 15:17

Quote:

Originally posted by f22flyboy

p1_sw_top_prev=p1_sw_top

I see that it sets p1_sw_top_prev=0 but why not just say that?

The gear_count is a delay to prevent damage to the gearbox and I think the p1_sw_top_prev=p1_sw_top resets the input and as for not setting it equal to zero, the button may not have started in the zero (off) position.

Anyway, Rob will be back in an hour and explain everything.

Matt Reiland 31-10-2002 15:20

Quote:

Originally posted by f22flyboy
startShift:
leftDrive=127
rightDrive=127
gear_shifting=1
gear_count=0




also what is this here for?

p1_sw_top_prev=p1_sw_top

I see that it sets p1_sw_top_prev=0 but why not just say that?

As for time, it will depend on the program length and the number of processor 'slots' you are using. The longer the program scan, the slower the delay will be.

Gear Count =0 will set up a fresh delay since it increments to 40 and stops incrementing until the next time a gear shift is requested. Gear Count would be at 40 coming into that statement

p1_sw_top_prev=p1_sw_top
this type of statement is useful for storing the value of the switch on the previous scan and checking the current state against what you had before to see if a change has taken place, kind of a 1-shot since after the current scan they will both agree again

f22flyboy 31-10-2002 15:27

how long
 
Can someone on this team tell us about how long the delay is?

Matt Reiland 31-10-2002 16:05

This is from the archives I assume it to be close

close enough for govt work...
Posted by control guy at 1/29/2001 10:29 AM EST


Student on team #250 from HVCC.


In Reply to: Re: PBASIC Loop Speed?
Posted by Lloyd Burns on 1/28/2001 4:38 AM EST:



The program loops are roughly 1/40 sec. Although, the time between loops can vary if you lose signal momentarily. Also, depending on your code, a program loop may take longer some times around than other times. Such as if you had many strings of if statements and you're having the program go here, then here, then here, etc., etc. Hope this helps.

rbayer 31-10-2002 16:46

Ok, I'm back (sort of). Actually, I'm sitting in my CSci class right now, but I don't really feel like listening, so I'm responding here.

The p1_sw_top_prev=p1_sw_top does exactly what Matt said, it stores the state for the next loop. Since almost no one can press and release a button within 1/40th of a second, we need to make sure that it is actually a "new" button press and not just someones finger left on the switch from earlier. This lets us use the top switch as a toggle. I.e. each time you press it, the gear we are in changes.

As for the timing, it ends up being about 1.5-2 seconds from the time you press the button to the time you can drive again. That is for the full 40 loops. The 10 loop part takes approx. 1/4 as long.

If you can understand this type of time-delay, you have a very good grasp on PBASIC as this type of looping isn't overly intuitive.

Anyway, let me know if there are any other sections that are unclear or don't make sense.

--Rob

SlamminSammy 31-10-2002 22:38

Re: how long
 
Quote:

Originally posted by f22flyboy
Can someone on this team tell us about how long the delay is?
Just plug the code into RoboEmu and see for yourself!


All times are GMT -5. The time now is 01:55.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi