Running two parts of a program at the same time
Mario
Posts: 1
·I'm building a very simple robot that goes forward and when there is an object less than 30 cm away, it turns. I'll add some more things later on, but for now, how can I make the servos work without pulsing them, i mean having a smooth motion? I'm using PULSOUT as a command and I'm using a PING))) SENSOR. To fix the problem I tried taking away the PAUSE line in the Pinging section but now the servos work, but the Ping is checking for object 200 times a second.... I would like to check just like twice or so a second. In other words, i'd like for Address1 to run WHILE Address2 is running so that I can run two parts of the program at the same time. How can I do that?
EDITS::
Couch-pilot I can't use this because then for a fraction of a second the actions in the loop won't run. It would be fine for the servos, but I also implemented another piece that checks for a remote control button to be pressed to activate a servo. I need for the check to be always run, WHILE running the rest of the program.
Attached is my program so far. I added comments for easier readability...
2 EDIT::
Thank you all for ur help... I'll try to fix up my code. I was just wondering, do you guys think that using the ping sensor like 500 times a second to eliminate the pulses as an alternative to couch-pilot's code would break the sensor or heat it up??
Post Edited (Mario) : 12/19/2006 7:03:38 PM GMT
EDITS::
Couch-pilot I can't use this because then for a fraction of a second the actions in the loop won't run. It would be fine for the servos, but I also implemented another piece that checks for a remote control button to be pressed to activate a servo. I need for the check to be always run, WHILE running the rest of the program.
Attached is my program so far. I added comments for easier readability...
2 EDIT::
Thank you all for ur help... I'll try to fix up my code. I was just wondering, do you guys think that using the ping sensor like 500 times a second to eliminate the pulses as an alternative to couch-pilot's code would break the sensor or heat it up??
Post Edited (Mario) : 12/19/2006 7:03:38 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lets see what this does... KA BOOM (note to self do not cross red and black)
PingDelay VAR word
PingTimeOut CON 500 'This is an arbritrary number, and has to be adjusted depending on the number of pbasic statements executed in the loop
DO
<PULSOUT Right_motor>
<PULSOUT Left_motor>
PingDelay = PingDelay +1
IF PingDelay > PingTimeOut THEN
'Do the PING thing
PingDelay=0
ENDIF
LOOP
-Ben
·1)Servorun 2)PINGsensor 3)Obstacle 4)Turn 5)Forward and 6)Remote
Then get rid of the GOTO statements and call the subroutines as required. Unfortunately you can't run 2 routines at the same time so you have to try and overcome your problem with timing/speed. If you need to constantly monitor the remote increase the number of calls to that sub and nest the call within the other subs. Reducing the call to the PING to once or twice a second then Ben's solution is ideal, adjust the PingDelay to fine tune until you get the timing desired.
hope this helps
Jeff T.
First, run your Sonar loop as a nested loop. Example - Do servo·if servo >= 100 revolutions·run sonar end if loop
Second - if you prefer not to do that consider simply inserting a pause between sub routines. I mean pausing the program for the sonar to run after the servo goes a set time. You will have a slight hickup in movment but it will be minor.
Third - reverse number 1 so that the sonar loop always runs and the servo is a do While loop.Example - Do sonar - do while sonar >= 10 inches end while loop.
Fourth - run a Propeller and do both at once. Kidding [noparse]:)[/noparse] If you now how to link stamps or have a coprocessor you could hook up one to the master and the other to the slave.
The problem appears to be the way the program is checking for an incoming IR message from the remote - with the RCTIME command. Instead, check for a low signal from the IR detector first, and if it's low, then do the RCTIME command, and don't let the program check the Ping))) until it's done with the IR message and a refreshing pulse to the servo. You may need to check the IR output several times in order to make sure you don't miss the message, but just check for the low signal. If it's low, then do the RCTIME command.
Another thing to do is set it up so that it check's the Ping))) sensor between one set of servo pulses, and then checks for IR messages between the next set of servo pulses.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
WARNING!!!
One of my robots ran 3 sonar within the·serov's loop. If you get to many sonar·within a servo loop·the servo will jitter at the start and end of its movment. If you take the sonar out of the loop then the servo's won't jitter. This robot had only·2 servo's and they started to jitter when there was that much within the loop. I was supposed to run 4 servo's ...