Log in

View Full Version : Hints For Rookie Programmers


Noah
24-01-2003, 01:29
Thought I would lay down a couple guidelines:

1) Never program when you have less than 6 hours of sleep in the past 24. IT DOESN'T WORK (Without a lot of coffee)

2) Always initialize your PWM outputs to 127. If you don't it will default to 0. (0 is full reverse. I forgot to initialize my motor outputs. We turned on the robot, and it went backwards full speed and almost bashed one of our engineers in the shins... )

3) Don't forget to increase those counters! (Well... I forgot this crucial step in one loop in our autonomous program... our robot was spinning in a circle for about five minutes)

Ok, they're obvious, I know... just thought I'd share them. Anyone got any others to add?

Rickertsen2
24-01-2003, 01:34
sleep.... programmers don't need sleep. I have fallen asleep coding before. Thats when u stop.

rbayer
24-01-2003, 01:42
Originally posted by Noah

1) Never program when you have less than 6 hours of sleep in the past 24. IT DOESN'T WORK (Without a lot of coffee)


In that case, I don't think I'd ever be able to do any coding, much less be able to code during the build season. Sleep is for the weak! :cool:

Anyway, some other good ones:

*Always make sure your CON stuff matches your SERIN.

*Always test code before uploading it to the robot.

*Never let an ME person touch the laptop.

*~ is not (no pun intended) the same as NOT.

Noah
24-01-2003, 01:45
While the code I write at 4:00 am is a great deal more efficient and interesting than anything I write while under the influence of sleep, No-one (Myself included) can ever reason out just what I did. I almost always end up rewriting such code (In a signifigantly more obvious way) later. In the end, I would have saved my own time by sleeping when I was programming and programming when I was sleeping. (Of course, I haven't slept recently as I write this, so perhaps I'm a bit of a hypocrite). Of course, when I'm awake I also don't forget to increment my counters and such...
Granted, that was when I had gone for 36 hours without sleep, but even so, that was pathetic. ::Bangs head against wall for miserable failures::

rbayer
24-01-2003, 02:01
Originally posted by Noah
While the code I write at 4:00 am is a great deal more efficient and interesting than anything I write while under the influence of sleep, No-one (Myself included) can ever reason out just what I did.

You mean like this line taken directly from RoboEmu (comment included)?

*(unsigned int *)((int)out+i*sizeof(unsigned int))=result; //have fun figuring out this one


If this line ever fails, I'm going to have to delete it (and most of the surrounding function) and start over. It seemed like such a good idea at the time...

Cipher X
24-01-2003, 22:28
All i got to say is that DONT use too many debug statements { I dont belive they tell you this in the manual}

I was writing code for a neighboring team {947} and they were using a potentionmeter and i was just testing it out seeing what values it was outputting. But on top of that i just wanted to make sure that i was getting all teh right inputs and i was giving out all the right outputs. By the end of it i wound up with like 13 {some stupid number} DEBUG statements. Now all of a sudden the Revolving light turn off and on and all the motors work and then doesnt work and then works etc.. Now i took out all the Debug statements and everything worked fine. I think its because the timing for the DEBUG statements is too long and maybe too many of them makes the whole loop go so much slower that the controller looses its timing i guess. only thing i could think off. But remember try not to use more than like 10 DEBUG statements Max at once. I dont know if PBasic 2.5 fixes this but i am pretty sure it doesnt i have tried it out yet.

Cipher X

Jferrante
25-01-2003, 05:30
I am afraid that despite the complaints of the useless posts I must add in the classic line that is all to needed in this thread.

What is sleep and where can I download it?

FotoPlasma
25-01-2003, 06:25
Originally posted by Jferrante
What is sleep and where can I download it?

I've been looking for a cracked copy for weeks... No luck yet. I guess I'll stay up and keep searching...

As for programming tips, keep a copy of the Basic Stamp Manual (http://www.parallax.com/Downloads/Documentation/bs/BASIC_Stamp_Manual_v2-0.pdf) handy. If you're ever unsure of the syntax of a command, you can alway lookup it, hyuk hyuk.

If you ever REALLY need to stay awake (like, life threatening emergency, or just for fun) Sobe Adrenaline Rush (http://www.sobebev.com/product_info/adrenalinerush.shtml) will most likely do it for you, and it tastes good, too.

Oh, listen to music that won't agitate or otherwise negatively affect you. You're going to get pissed off at your code enough as it is, without sub-par music blasting in your ears. Pink Floyd, The Beatles, Phish, Tool... whatever you're comfortable with.

One last thing. The light of your computer's monitor is ALWAYS enough light to work under.

Dave...
25-01-2003, 07:39
*Never let an ME person touch the laptop.

I guess I'm in trouble since I'm an ME and the programmer for the past three years.

Did a pretty good job of winging it though, eh? Never crashed the robot into my own shin (or anyone else's, but came close):D

Curtis Williams
26-01-2003, 16:33
Crashing into a shin? We should be so lucky. The MEs didn't listen when I told them to back away during testing. One got smacked in the jaw with a van door motor when the robot went full reverse.

Anyway, sleep is the absolute worse thing you can do to yourself while programming. After sleep you are too energetic to sit down and code. You have to stay on the edge where you are too sleepy to run outside, but awake enough to code. Every time you sleep you are loosing the 8 hours taken by sleep, and 16 hours because your energy level is too high. If you keep this "good sleep" up you will never have good programming time. You must stay awake, and when you hit the edge, you must stay there. Caffeine helps.

Raven_Writer
26-01-2003, 18:43
Originally posted by Dave...
I guess I'm in trouble since I'm an ME and the programmer for the past three years.

Did a pretty good job of winging it though, eh? Never crashed the robot into my own shin (or anyone else's, but came close):D
lol. Also came close to crashing an old robot into the ground, and running into a few members :D (the good times).

EvanG
26-01-2003, 21:55
As a programmer, i can say i've found that having a close to hand set of switches with a kill switch is effective for when your bot decides to go AWOL... until the kill switch solder breaks.

Anthony Kesich
26-01-2003, 23:36
Anyway, sleep is the absolute worse thing you can do to yourself while programming. After sleep you are too energetic to sit down and code. You have to stay on the edge where you are too sleepy to run outside, but awake enough to code.

Its true, i tell ya. Every week, we have at least one 12-hour meeting, and for at least the first 8 hours i do almost no programming, unless we need it desperately (I'm normally found trying to pose as a grease monkey :D). But for those final 3 hours or so, i get [b]everything[b] done. I used to think it was just me, but it seems i'm wrong.

-Anthony

redbeard0531
26-01-2003, 23:52
Originally posted by Anthony Kesich
Its true, i tell ya. Every week, we have at least one 12-hour meeting, and for at least the first 8 hours i do almost no programming, unless we need it desperately (I'm normally found trying to pose as a grease monkey :D). But for those final 3 hours or so, i get [b]everything[b] done. I used to think it was just me, but it seems i'm wrong.

-Anthony

You must be sleep deprived

if 8 + 3 = 12 then GOSUB HelpMe

HelpMe:
Grade = Grade MAX 2 ' sends me back to second grade
Return

;) :cool:

I must say that 8p - 2a are my best programming hours.

btw, if you have a food lion neer you, dr perkey and mountain loin are cheap, great tasting, and loaded with caffine and sugar!:yikes: :D

Anthony Kesich
27-01-2003, 00:00
im both fearing and looking forward to the final weekend. WE have a 5 day weekend at my school that weekend cuz of combining holidays and teacher meetings, so either ill rock and programming and make something godly or i will go into a coma from lack of sleep (or food if i do progam too intensly :yikes: )

-Anthony

Jeff_Rice
27-01-2003, 00:38
I have enough trouble programming in pbasic while i'm awake. But in my defense I have this to offer; I only just started. Today was my first real day programming, and I made several syntax errors. I managed to change the output of the joystick code from linear to varying with the square. Ugh. I've only got one bug left to kill. But the first bugs I had- man! I bumped the joystick and the robot went screaming full speed into a bunch of 55 gallon drums. I am so happy there is a disable switch. But yeah, it works fine going forward any speed but if you pull the joystick back into the reverse corner areas, it starts going forward. I have something going negative; tomorrow I'll figure out what and fix it.

Goya
27-01-2003, 16:48
Originally posted by Jeff_Rice
I have enough trouble programming in pbasic while i'm awake. But in my defense I have this to offer; I only just started. Today was my first real day programming, and I made several syntax errors. I managed to change the output of the joystick code from linear to varying with the square. Ugh. I've only got one bug left to kill. But the first bugs I had- man! I bumped the joystick and the robot went screaming full speed into a bunch of 55 gallon drums. I am so happy there is a disable switch. But yeah, it works fine going forward any speed but if you pull the joystick back into the reverse corner areas, it starts going forward. I have something going negative; tomorrow I'll figure out what and fix it.


Are you trying to change the joystick from using only the y-axis to being able to use the entire plane of the joystick?

This code is publicly available, but I should thank you for trying to make the code yourself, before "reinventing the wheel."

Gobiner
29-01-2003, 03:05
I've found this (http://www.thinkgeek.com/caffeine/candy/5bf6/) to be of great value whilst attempting to fit programming into my schedule. I find soft classical music nice for coding, but try to stay away from the really good stuff as that will probably distract you from the finer things in life, lik enjoying your silly programming errors.
Also, PBASIC 3.0 should include the necessary math functions to evaluate our robots name (e^(pi*i)+2).

EmilyM
31-01-2003, 23:13
Being a rookie programmer myself, I am perhaps super-qualified to post a couple hints...

First off, I have verified Noah's assertion that counter variables do not in fact increment themselves. Increment your counters!

And secondly, remember that byte variables only count so high. Thus there is a problem with the following code:

testvar VAR byte
select testvar
case 0 to 300
do something
case 301 to 400
do something else 'This is never going to get executed!
endselect
testvar = testvar +1 'This part is important too!

I, of course, learned both of these the hard way. =)

RoboCoder
01-02-2003, 07:53
One important thing to mention is: PBASIC does not like negative values.........period I learned this the hard way when trying to do a case statement on the difference between two byte values and the negative code never executed :-P took me a while to figure it out, but have it running smoothly. oh and counters dont increment themselves, although didnt I hear that from somewhere already? hmmm......oh well :p

Dave...
01-02-2003, 09:14
Originally posted by Gobiner
Also, PBASIC 3.0 should include the necessary math functions to evaluate our robots name (e^(pi*i)+2).

Cool name for a robot. Do you have a hard time explaining it to others??

Believe it or not, I have (e^(i·pi)+1=0) on my cabinet at work. Even other engineers don't behold the beauty of this equation. It brings tears to my eyes... Ok, not really, but close.

Jeremy J
01-02-2003, 12:57
Well, I don't get it and I'm a rookie programmer. I find that trying to code at 3 am after playing Unreal Tournament 2003 for 3 hours straight is the best method. You're too tired to play effectively, but too non-tired to sleep. Of course, when you wake up laying face first on the keyboard and read your code and dunno what it does, that's your problem :)

Jeff_Rice
01-02-2003, 14:10
Our robot already used an ordinary 1 joystick code. I just fixed it so that the speed is not linear, but parabolic. And I fixed it the day after that post.

Gusman1188
01-02-2003, 14:52
On our first attempt to program auton. mode, the robot did go into full reverse and it bashed our programmer in the legs. We couldn't get it off him.

Skabana159
01-02-2003, 16:21
There is a hole in a wall in CSU where 2001's robot decided that it's arm (big iron bar on a motor) would go really fast for no apparent reason. By the way, there is no hole in CSU ;)
We shelled the motor ripping it out, had to get a new one.

Ryan Meador
01-02-2003, 21:56
Here's my $0.02: subroutines don't call themselves. GOSUB is your friend.

Relating to this year's program, inverse tangent w/o negative numbers is fuuuuuuuun. :P

evulish
01-02-2003, 22:55
From all the engineer-bashing (robot-wise) I've been hearing in here...I think the number 1 tip would be to PROP YOUR ROBOT UP! :D Get two 2x4's...set them on their edge...and put your robot on them. Not on a table, either. No more chances of killing your ME's :P

TangoBravo1318
20-02-2003, 09:16
Originally posted by Anthony Kesich
Its true, i tell ya. Every week, we have at least one 12-hour meeting, and for at least the first 8 hours i do almost no programming, unless we need it desperately (I'm normally found trying to pose as a grease monkey :D). But for those final 3 hours or so, i get [b]everything[b] done. I used to think it was just me, but it seems i'm wrong.

-Anthony


lol! i have done the same exact thing: help out with wiring or filing, etc, and then program during the last half-hour. i [and some team members] thought it was just me! lol..

TangoBravo1318
20-02-2003, 09:22
hmmm...i have just started with PBASIC (i have experience with VBASIC and QBASIC, etc) and my team said that the robot's motors "pulsed" when they pushed the joysticks forward (two-joystick-tank-drive) here's the code i added, it checks for exceptions, and then divides the speed by 4 (i hope?!)
'============= New Code ========================
'Added code to reduce p1_y and p2_y to 1/4 power
'Maybe only 1/2 power??

if p1_y = 0 then skip_one
if p1_y = 125 then skip_one
if p1_y = 126 then skip_one
if p1_y = 127 then skip_one
if p1_y = 128 then skip_one
if p1_y = 129 then skip_one
if p1_y = 255 then skip_one
p1_y = (p1_y / 4)

skip_one:
if p2_y = 0 then skip_two
if p2_y = 125 then skip_two
if p2_y = 126 then skip_two
if p2_y = 127 then skip_two
if p2_y = 128 then skip_two
if p2_y = 129 then skip_two
if p2_y = 255 then skip_two
p2_y = (p2_y / 4)

skip_two:
' End code
'SEROUT COMMAND GOES HERE...
(Can anyone help on auton mode?!?!?!)
Thanks

TangoBravo1318
20-02-2003, 10:11
About initilizing the PWM outputs:

Okay, i have set all the unused PWM outputs to 127 in the SEROUT line. Is this what you mean? Or should i do something like this in the VAR section:

'-------Declare VAR's-----------------

PWM1 = 127
PWM2 = 127

...

'------------------------------------------

Noah
20-02-2003, 20:07
That is exactly what I mean. If you don't declare your variables to 127 before your first serout statement then the robot begins in the full backward state. Not fun for the engineer standing directly behind the robot expecting it to drive forward under remote control...