Okay, here goes....


Closed Thread
Results 1 to 5 of 5
  1. #1
    lefthandsh8k's Avatar
    lefthandsh8k Guest

    Question Okay, here goes....

    Hi everyone.I'm new to microcontrollers (and programming for that matter) and am having some difficulty with a project from John Iovine's "Pic Robotics".

    The project is a reproduction of William Gray Walter's turtle robot.My issue is more than likely a simple one( and will reveal to you how little I know about this once I get the answer).When looking at the program, I noticed it was
    written for the PicBasic Pro.I Have Picbasic.The problem I'm having seems to begin with the definition of variables.Here's the code.





    v1 var byte
    v2 var byte
    s1 var byte
    s2 var word
    rv var byte
    s1 = 150
    rv = 10
    ct var byte
    'drive servomotor**continuous rotation information
    'connected to pin portb.**variable pulse width numbers
    '157 forward * 165 slow forward
    '167 stop
    '169 slow backward * 177 backward
    start:
    pot portb.2,255,v1 'Read resistance of CDS # 1 photocell
    pot portb.3,255,v2 'read resistance of CDS # 2 photocell
    'Check bumper switch "did I hit something?"
    if porta.0 = 0 then avoid 'hit obstacle go into avoid mode
    'is it sleepy time?
    if v1 <= 230 then skp 'is it dark enough to sleep?
    if v2 > 230 then slp 'yes.
    'Is it too bright to see?
    skp: 'no sleep--keep moving
    if v1 >= 12 then skip2 'Is it too bright to live?
    if v2 < 12 then avoid 'yes.
    'Which way do I go?
    skip2: 'Not so bright--should i steer?
    if v1 = v2 then straight ' light is equal.go straight.
    IF V1 > V2 THEN greater 'check light intensity to turn right
    if v1 < v2 then lesser 'check light intensity to turn left
    straight: 'Go forward in the direction your facing
    pulsout portb 6, s1 'Don't move steering
    pulsout portb 7, 157 'Go forward
    goto start
    greater:
    v3 = v1 - v2 'Check numerical difference between Cds cells
    if v3 > rv then right 'If more than rv turn right
    goto straight 'if not go straight
    lesser:
    v3 = v2 - v1 'Check numerical difference between CDS cells
    if v3 > rv then left 'If more than rv turn left
    goto straight 'If not go straight
    right: 'Turn right
    s1 = s1 + 1 'Increment variable sl to turn right
    if sl > 225 then s1 = 225 'limit sl to 225
    pulsout portb 6, s1 'move steering servomotor
    pulsout portb 7, 165 'Go forward slowly
    goto start
    slp: 'Go asleep
    pulsout portb 6, s1 'Don't move steering
    pulsout portb 7, 167 'stop drive servomotor
    goto start
    avoid: 'avoid mode,send
    random s2 'randomize s2
    s1 = s2 / 256 'reduce range of s1 to 1 to 255
    if s1 < 65 then s1 = 65 'set lower limit
    if s1 > 225 then s1 = 225 'set upper limit
    for ct = 1 to 125 'start counter
    pulsout portb 6, s1 'steer in a random direction
    pulsout portb 7, 177 'Reverse drive motor(slow)
    pause 18 'Pause to send instructions at 50 Hz
    next ct 'loop
    s1 = 150 'steer back to center
    goto start


    ...Let me stress that I am not an engineer in any sense of the word.I am actually a special effects artist that is interested in using the pic for servo control.If I could get some input to assist me over what I'm sure is a minor obstacle, I would greatly appreciate it.Thanks
    Shawn

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Shawn,

    If the program is written for PicBasicPro then using PicBasic will not do the same thing. The "Pro" version is actually an upgrade ($250.00US) to the program you have. There's a big difference. I think I have that same book but because we are redoing my office right now I can't get to that box. Considering what you are wanting to do you may want to consider the upgrade. I'm sure later today there will be someone that might possibly be able to convert the program for you back to PicBasic. John Iovine also has a book on programming PICs that has both PBC and PBPro programs.

    Hope some of this helps!

    BobK

  3. #3
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi again Shawn,

    What luck! I stepped back into a corner and the first box I opened had the robotics book right on top. Anyway, looking at the pictures there appears to be a circuit board made by Images SI, Inc. After checking their site, www.imagesco.com, I see they have numerous kits available along with the programmed PIC that will save you alot of hassle if you haven't done any of this stuff before. This IS the great way to learn how to use these chips. The also have tutorials available online for free. I also saw several other models allowing for more than one servo along with a PC interface and windows based software. Check them out.

    You should also check out some of the other suppliers listed in the back of the book.

    Best of luck to you and hope you enjoy working with PICs as much as I have.

    BobK

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by lefthandsh8k
    ... problem I'm having seems to begin with the definition of variables...
    Quote Originally Posted by BobK
    ...I'm sure later today there will be someone that might possibly be able to convert the program for you back to PicBasic
    Shawn, here is an explanation for the question you asked (not the entire code):

    With PBP, you get to pick your variable names and determine their size. In PB a bunch of the variable names are predefined as B0, B1, B2, W0, W1, etc. (read section 4.6 of the PB manual for sure). Converting the definition of variables of your program ....
    Code:
    Symbol v1 = B0  'see section 4.7 for Symbol explanation
    Symbol v2 = B1
    Symbol s1 = B2
    Symbol rv = B3
    Symbol s2 = W2
    Symbol ct = B6
    s1 = 150
    rv = 10
    Also note that the Port pins have been predefined in PB (section 4.6 again). For example, instead of using
    Code:
    PortB.2
    like you can in PBP, PB makes you use
    Code:
    Pin2
    (instead).

    If I were you, I would first try and blink some LEDs before trying to convert your program. There also are a bunch of example programs for PB the MELAB website.

    Good Luck,
    Last edited by paul borgmeier; - 20th August 2006 at 08:57.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    lefthandsh8k's Avatar
    lefthandsh8k Guest


    Did you find this post helpful? Yes | No

    Smile hmmm, that may be it...

    Thanks.I'm going to give this a chance once I get back from work this evening and see how it goes.I'll post and let you know if it fixes my problem.
    Shawn

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts