Shop OBEX P1 Docs P2 Docs Learn Events
Bluetooth Code — Parallax Forums

Bluetooth Code

addyaddy Posts: 7
edited 2006-04-27 12:22 in BASIC Stamp
Hello,
I am currently working on my senior design project and I was coding the bluetooth aspect of the project. I want to make the Boe-Bot go straight but I also want to make the Boe-Bot be able to control the direction when I press 1,2, or 3 in the hyperterminal. I have both programs working separetely(regular control of the boe-bot going straight and the bluetooth control program)·but I want to put it together. I am not a programmer and I'm confused on what loop to use to make the two programs work together. Please help, our project is due next wednesday april 26.
addy

Comments

  • virccovircco Posts: 1
    edited 2006-04-20 16:23
    Hi addy,

    You are on the rigth way, you have to make a subroutines that sense in the time what you receiving.

    THIS IS NOT A CODE, Just a logical example:

    CONTROL:
    IF BOE-BOT COMAND DO <RUN SUBROUTING FOR BOE-BOT>
    NEXT
    IF HYPETERMINAL COMAND DO <RUN SUBROUTING TO CONTROL BOE-BOT WITH HYPERTERMINAL COMAND>

    END.

    I hope this could bring you some ligth... if not, just look in other forums, look for: How to ASINCRONOUS program codes.

    Best regards, Vircco. idea.gif
  • addyaddy Posts: 7
    edited 2006-04-21 05:13
    Thank you, I will work on that but I'm confused on how to set up the hyperteminal command after the if statement
  • Pezi_Pink!Pezi_Pink! Posts: 32
    edited 2006-04-21 13:45
    Hello addy,

    I don't have any experience with bluetooth, however I will attempt to help you based on the information given.

    Firsly, you wish to have the hyperterminal input override the boe-bot from moving continuously forward, correct?

    Given this assumption I'm not too sure why you would have a forward command through the hyperterminal? This is an identical action to not sending any command and allowing your boe to just travel forwards?· So that seems sort of pointless.

    Regardless of that, I'll assume that CmdData value 0 or the "Hold" routine·in this statement "BRANCH CmdData,[noparse][[/noparse]Hold, Turn_Right, Turn_Left, Move_Fwd]"· means that no command has been recieved by the hyperterminal, so in this scenario you just want to revert to moving forward? (although you are just doing nothing at the moment)

    If this is the case, it is just a simple matter of including the move forward code into the Hold subroutine, instead of just making it sit there doing nothing whilst waiting for a command.
    So you could try and include the move forward code in your hold routine like this (for ease of future expansion):

    Main:
     SERIN 0,84,[noparse][[/noparse]DEC1 CmdData]
     DEBUG DEC1 CmdData
     BRANCH CmdData,[noparse][[/noparse]Hold, Turn_Right, Turn_Left, Move_Fwd]
     GOTO Main
    Move_Fwd:
     PULSOUT LMotor,LFwdFast
     PULSOUT RMotor,RFwdFast
     SEROUT 1,84,[noparse][[/noparse]"1"]
     GOTO Main
    Turn_Right:
     PULSOUT LMotor,LFwdFast
     PULSOUT RMotor,RRevFast
     SEROUT 1,84,[noparse][[/noparse]"2"]
     GOTO Main
    Turn_Left:
     PULSOUT LMotor,LRevFast
     PULSOUT RMotor,RFwdFast
     SEROUT 1,84,[noparse][[/noparse]"3"]
     GOTO Main
    Hold:
     PULSOUT LMotor,LFwdFast
     PULSOUT RMotor,RFwdFast
     SEROUT 1,84,[noparse][[/noparse]"0"]
     GOTO Main
    
    

    Or, simply dump the Hold routine completely and replace the BRANCH with this?

    BRANCH CmdData,[noparse][[/noparse]Move_Fwd, Turn_Right, Turn_Left, Move_Fwd]
    

    This works, because if you recieve a 0 through the serial port (no command from terminal) the bot will simply keep moving forward as if it was sent a 3 from the terminal.
    Also I'm not too sure about the SEROUT commands in each movement routine. Are they sending back data to display on the terminal?·· I'm assuming you need to send back the command number that was executed?· (I don't really know much about hyperterm)· if this is the case, aren't they around the wrong way?·· CmdData is 0 for hold, 1 for right, 2 for left and 3 for forward, yet in the movement routines you output 1 for forward, 2 for right and 3 for left?

    Anyway I hope I understood what you wanted to do and that this helps in some way!

    Pezi

    wow, this is my third edit in 5 mins.· Im really on the ball today as you can see!!·(more coffee needed) You will need some pauses between movements in there as well to produce the correct pulsetrain the srervos require, so you dont continually send them pulses....· I don't know how long those SEROUTs take to process but I'm guessing not long!

    Post Edited (Pezi_Pink!) : 4/21/2006 2:00:01 PM GMT
  • addyaddy Posts: 7
    edited 2006-04-26 14:02
    Thank you for your help Pezi_Pink! Really appreciate it. I figured how to code it that it will keep running until I connect the bluetooth. But the problem now is that when I press the keys on the keyboard now it doesnt move at all. Did I miss something?
    bs2
    1011B
  • Pezi_Pink!Pezi_Pink! Posts: 32
    edited 2006-04-26 16:58
    Hello addy,

    I think I misunderstood what you were originally asking for, so apologies for that!

    In your code, when you run the connect routine like so....

    Connect:
    PAUSE 1000
    SEROUT 1,84,[noparse][[/noparse]"00:0C:84:00:11:40",CR]
    SERIN 0,84,[noparse][[/noparse]WAIT("ACK",CR)]
    
    Main:
    SERIN 0,84,[noparse][[/noparse]DEC1 CmdData]
    DEBUG DEC1 CmdData
    BRANCH CmdData,[noparse][[/noparse]Hold, Turn_Right, Turn_Left, Move_Bck, Move_Fwd]
    END
    
    



    You are basically switching on the Bluetooth, immediately taking a value from it (which will be 0 most probably) then you branch to the required move routine, but then upon return to the main loop the code simply hits END and stops.

    I take it I didn't assume quite correctly previously. Now from what I can make out you want the boe-bot to move forwards from the outset of the program, and keep moving forward until the Bluetooth connects. Given you have a Forward command, I suppose you want it to go forward until connected, then stop and respond only to your commands. Is this correct?

    If so you can probably do this just by changing the main to this

    Main:
    SERIN 0,84,[noparse][[/noparse]DEC1 CmdData]
    DEBUG DEC1 CmdData
    BRANCH CmdData,[noparse][[/noparse]Hold, Turn_Right, Turn_Left, Move_Bck, Move_Fwd]
    GOTO Main
    
    



    this will work although you still need to make sure you aren't sending continuous pulses to the servo. This modified code will work but the loop will execute so fast the servos may not behave correctly. So you will need a pause in the main loop (or each move routine) for the 20ms or so refresh rate that the servos require. If you want the Hold routine to actually hold the servo positions (so it couldn’t be moved by an external force, say) you will also need to send the servos pulses to hold their current position.

    Pezi
  • addyaddy Posts: 7
    edited 2006-04-27 06:59
    Thanks again.....I finished the code and I also added an IR Detection so when it is running automonously it will stop when something is infront of it. This is going to help me in simulating a transit car on the road·because·I dont want to hit anyone.··I still got to fix some glitches, all that matters is·Yesh!!! I'm happy!!!!!!!!!
  • Pezi_Pink!Pezi_Pink! Posts: 32
    edited 2006-04-27 12:22
    cool beans! I'm glad I could help

    You may still want to change Main: to this though so you dont prematurley kill (or confuse) your servos

    Main:
    SERIN 0,84,[noparse][[/noparse]DEC1 CmdData]
    DEBUG DEC1 CmdData
    BRANCH CmdData,[noparse][[/noparse]Hold, Turn_Right, Turn_Left, Move_Fwd, Move_Bck]
    PAUSE 20    ' or similar
    GOTO Main
    
    
Sign In or Register to comment.