help with hard sums

stan74

Senior Member
I have an ultra-sonic range finder mounted on a servo.
the servo goes 0 to 180 deg say with servo values of 75 to 225.
I want to draw the range in a semi-circle, bit like a radar.
The screen will be x 0 to 63, y 0 to 63. please see diagram.
I need to convert the servo angle to degrees and from the right angle triangle and cos and sine work out the opposite and adjacent sides which will be the x,y end points which will be connected.
I hope someone who didn't spend so much time looking out the window in school as me could help because picaxe sines and cosines aren't normal and sums hurt my head and Wales are playing England where I live right now.
I drew a sketch but can't upload it,720K jpeg?
 

stan74

Senior Member
SAM_1425.JPG
worked then??
It's like a compass. The range being points from the middle joined. If the range was constant it would be a semi-circle.
 

stevesmythe

Senior Member
Formula for a circle radius R (i.e. your range) at origin x=0, y=0 is:
r*r =x*x + y*y
therefore
y*y=r*r-x*x

So, for each value of x,
y = square root of ( (r*r) - (x*x))

If you run a loop where x is incremented each time, you can find the y co-ordinate from the range using the formula

I believe that X1 and X2 Picaxe processors support the SQR (square root) operator.

Does that help?

Are you looking to make a sonar display? If so, you don't need to know the servo angle. Just make it sweep back and forth at constant angular velocity and measure the range every so often then plot using the above formula. I made such a thing once and it wasn't very successful as the servo wasn't very smooth. I had more luck with a reasonably fast stepper motor.
 
Last edited:

stan74

Senior Member
I only know the radius/hypotenuse/range and the angle from 0 so I guess x from centre is sine (90-servo angle)=x from centre/range.
ie x from centre=sine (90-servo angle)*range.
and y from centre is cosine servo angle=y from centre/range. ie cosine servo angle*range.
but if servo angle >=90 ???
I can move the servo smoothly but don't know the minimum step angle ie servopos 100 different to 111 or 99. I thought it would make an interesting display like the Alien radar in er..Alien.
ps thanks hippy you cracked it.
 
Last edited:
Top