Bluetooth Code
addy
Posts: 7
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
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
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.
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):
Or, simply dump the Hold routine completely and replace the BRANCH with this?
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
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....
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
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
You may still want to change Main: to this though so you dont prematurley kill (or confuse) your servos