Servo and Sonar
Question
I am writing a code to have two sonar mounted back to back on a pole extending from a servo. The servo rotates 180 degress while the sonar pulse.
Right now I am running 5 variables interpersed in the loop for the servo to run the sonar which takes up a lot of code room.
When the servo turns and the sonar pulses, is it better to use a dynamic array, static array, a·preset servo position to trigger sonar·or simply run a half dozen variables to capture data?
·
I am writing a code to have two sonar mounted back to back on a pole extending from a servo. The servo rotates 180 degress while the sonar pulse.
Right now I am running 5 variables interpersed in the loop for the servo to run the sonar which takes up a lot of code room.
When the servo turns and the sonar pulses, is it better to use a dynamic array, static array, a·preset servo position to trigger sonar·or simply run a half dozen variables to capture data?
·
Comments
My opinion is to use an array and increase by the loops.
Example
num = 0
For counter = 1 to 150 step 5
Trigger sonar
capture results
results = results(num)
num=num+1
next
Then compare the results to figure out which one is smallest.
num = 0
if resutls(num) <= results(num)+1 then
if results(num) <= results(num)+2 then
etc...
Course by the time your done it would be as short to simply run multipule variables like you are doing.
How many measurements per rotation? How fast (rpm)?
Show your current code so folks can see why it "takes up a lot of code room".
Without knowing this kind of information, it's kind of difficult to speculate what problem you wish to solve or how best to go about inventing a solution.
PAR
Why not set up a single variable in your servo loop so it triggers an outside equation once the peramiters get tripped?
For example
For counter = 1 to 150 step 5
Servo stuff
Sonar stuff with return pulse saved under distance
Next
If Distance >= saftey area then do something
Follow me?
Thanks AIMan