I have an srf005 ultrasonic range sensor attached to a picaxe 28x1.
When you get too close to the sensor an arm rises, and when you are so far away the arm then lowers.
I want the arm to rise/lower at different speeds depending on how fast your approach it.
Is there anyway to guage speed using the picaxe?
Kind regards,
Luke
Speed = Distance * Time
All you need to do is measure the distance at a regular interval and react accordingly. Put another way, if the Distance changes a great deal over time, react faster.
Its a DC Motor@Birdmun thats
Its a DC Motor
@Birdmun thats what I want to do… but how would I go about storing the distance on the 28x1? I need to write atleast the last two distances to the chip temporarily, calculate its speed and then step up or step down the potentiometer accordingly. At the moment I have it so that if the arm is a certain distance away (8cm) then it steps up the potentiometer, and if its 14cm it steps down the potentiometer but this causes the arm to wander quite rapidly between the two… I want it to say reach 8cm and then step up until it reaches the middle (between 8 and 14cm, so 11cm) and then step down just enough to make them motor have only enough voltage to keep the arm in the middle (the motor will still be turning due to the design of this arm).
So… essentially I need it to step down or up lots until the arm is close to the middle then step in the opposite direction until its found an equilibrium.
I hope ive explained this well enough.
Thank you both for your kind replies.
I will attempt a subroutine.
checkspeed:
gosub getdistance
distance1 = distance ’ there should be a variable in getdistance called distance
'this pause may be required to get useful speed information. Alter it to work.
'pause 500
gosub getdistance
distance2 = distance
'I can’t find the absolute value command for picaxe and time should be fairly
'constant and therefore we don’t need to multiply by it
if distance2 > distance1 then speed = distance2 - distance1
else speed = distance1 - distance2
return
The getdistance subroutine will just need to get the distance from the ultrasonic sensor, and, store the value in a variable called distance.
Thank you Birdmun
Thanks Birdmun!
I’m trying your subroutine as we speak and attempting to get the motor to react in a more exponential fashion… which is proving difficult ha.
I’m going to try changing values to see if I can ge the arm to stay in similar position otherwise I might need to find a way of predicting where the arm will be depending on its speed and then counteract it with the motor going slower/faster.
As far as im aware I would have to use integration for this… but not sure if this is possible on a picaxe. Or how id even go about it.
Will let you know if i get it working using your method, which is greatly appreciated!
Kind regards,
Luke