[Robotgroup] PBasic question

Gray Mack gray_mack at yahoo.com
Wed Dec 6 16:21:40 PST 2006


With microprocessors, it is always best to avoid non integer math when possible so that things run faster.
So for example if you did the multiply first: distance*41 and then divide by speed to get an integer.
12*41/9 = 54.6666 and truncates to 54
Since the loop can only be executed an integral number of times then you want an integer anyway.
There are ways to round instead of truncate, or multiply your numbers by 100 so that everything is in 100th second instead of second but if you need to be that exact you might also have to account for ramp up and ramp down time on the motors. 
-Gray

----- Original Message ----
From: Mohammad El-Abid <elabidster at gmail.com>
To: Austin Robotgroup Mailing List <robotgroup at puremagic.com>
Sent: Wednesday, December 6, 2006 5:23:37 PM
Subject: [Robotgroup] PBasic question


Okay I got the boe-bot and they have a experiment where you find out how
fast it's going and how to calculate how long it takes for it to go x
distance with



Distance divided by speed. So I thought I would one-up that! So I wrote a
code that you just enter in the inches per sec. your machine goes then how
far you want it to go (in ins), but I'm a programmer and know very well that
there are Floats, Fixnums, Bignums, and decs. So in PBasic what is the
decimal code?



Here's my code for those who are interested:



' {$STAMP BS2}

' {$PBASIC 2.5}

' This is for distance measurement

speed VAR Byte ' inches per sec.

distance VAR Word ' how many inches should it go?

division VAR Word

' math

speed = 9

distance = 12

division = distance/speed

DEBUG ? speed

DEBUG ? distance

DEBUG ? division

DEBUG 41*division, CR



'41 runs = 1 sec.

FOR counter = 1 TO 41*division

  PULSOUT 13, 850

  PULSOUT 12, 650

  PAUSE 20

NEXT



END

_______________________________________________
Robotgroup mailing list
Robotgroup at puremagic.com
http://lists.puremagic.com/cgi-bin/mailman/listinfo/robotgroup


 
____________________________________________________________________________________
Yahoo! Music Unlimited
Access over 1 million songs.
http://music.yahoo.com/unlimited



More information about the Robotgroup mailing list