Author Topic: Cheap and simple way to measure distance / absolute position with ~5mm accuracy?  (Read 7281 times)

0 Members and 1 Guest are viewing this topic.

Offline ndictuTopic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: sk
Hey,

I have a height adjustable desk which can be moved up and down to switch between standing and sitting. I like to do that at least few times a day so that I'm not sitting the entire time.

The desk has two buttons - up and down - which move it while held. I would like to change the buttons to be the sitting and standing position and automatically move between them. The driving part is pretty simple - the buttons can be detached from the motor control box, I'll just throw an Arduino in the middle and replace the button press with hold.

The tricky part is how to know what position the desk is at. The motors are just regular DC motors, not steppers, so no feedback there (I can't replace the motors unfortunately). Just sending the pulse for a constant amount of time is not good enough - it can vary by up to 1cm on the length of travel and also depends on weight so if I put things down on the table it goes up less. 1cm might not seem like a lot, but it is enough to make using keyboard/mouse uncomfortable. I would like to avoid getting RSI. I found that +- up to 5mm feels good enough. With short button pulses I can move the desk by about 2-3mm at a time.

So I need to mount some kind of distance measuring thing on the desk. I found ultrasonic/laser distance sensors, but those with required precision are quite expensive and also if I were to put my backpack/something under the desk it might throw it off.

I have considered some kind of strip with optical reader, based on Gray code. The range of travel is about 60cm, so 8 bits would be enough for 2.5mm increments. However I couldn't find any off-the-shelf solution, just rotary encoders. I thought about wrapping a string around a spring-loaded encoder and tying the other end to ground but that just seems silly...

Do you have any suggestions on how to approach this? Are there any good, cheap linear distance sensors from ~60cm to ~120cm with at least 5mm accuracy?

Thanks!

 

Offline ebastler

  • Super Contributor
  • ***
  • Posts: 6677
  • Country: de
Do you really need to measure distance? Wouldn't two simple digital sensors which define the two end positions be enough? If those end stops can be mechanically moved/adjusted by the user, you could even change the desired target heights without programming or teaching anything.

I am thinking about a mechanical (tactile) switch, light sensor, or magnetic sensor (reed contact or hall sensor) which travels up and down with the drive mechanism. Then mount two mechanical notches, light reflectors or interruptors, or magnets on the desk, at heights which are user-adjustable. Depending on how your desk is built, magnets might be easiest since they could hold themselves in place on a metallic leg?

Kind of a low-tech solution... But if the design of your desk accommodates it, it may be simple, reliable, and actually quite user-friendly.
 

Offline daqq

  • Super Contributor
  • ***
  • Posts: 2305
  • Country: sk
    • My site
Quote
I found ultrasonic/laser distance sensors, but those with required precision are quite expensive and also if I were to put my backpack/something under the desk it might throw it off.
You can buy some cheap ones and calibrate them: http://www.dx.com/p/hysrf05-ultrasonic-distance-sensor-module-for-arduino-443899#.WYOB_4jyiMo


Are you sure you are not overcomplicating this? From the description of the problem you don't really need to measure the exact position of the desk but rather switch between two predefined positions. A simple reflective photodector and two marked positions should do the trick just as well.
Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
 

Offline JXL

  • Regular Contributor
  • *
  • Posts: 64
  • Country: us
Quote
I found ultrasonic/laser distance sensors, but those with required precision are quite expensive and also if I were to put my backpack/something under the desk it might throw it off.
You can buy some cheap ones and calibrate them: http://www.dx.com/p/hysrf05-ultrasonic-distance-sensor-module-for-arduino-443899#.WYOB_4jyiMo


Are you sure you are not overcomplicating this? From the description of the problem you don't really need to measure the exact position of the desk but rather switch between two predefined positions. A simple reflective photodector and two marked positions should do the trick just as well.

For 2 predefined positions, daqq's suggestion is perfect.

The system is likely using a screw drive.  For variable and programmable positions, mount a 10-turn or 20-turn pot on the screw.  Use the pot as a voltage divider and read the level (position) with your Arduino.
 

Online DaJMasta

  • Super Contributor
  • ***
  • Posts: 2320
  • Country: us
    • medpants.com
If you know that the drive for the motors are directly linked and isn't slipping, I think an encoder of some sort on the output is the most reliable way to go.  You could even just through in a pushbutton to zero at some point and a simple quadrature output should give you very accurate feedback even if the motor control isn't as reliable.

Ultrasonic is alright, but to get that fine of a resolution and that level or repeatability, you may need to get specialized transducers with temperature compensation or something.

IR reflectance could be a good alternative to an encoder, as you could put something like one of those combined sensor modules and embed it in or partly covered by the legs of the desk, making it more immune to interference.  At that point you'd need to calibrate the output to distance, but it should be reliable provided you're always shining on the same target surface.

Depending on the construction of the desk, there could be a capacitive option too.  Something like a plate attached to the top leg and a plate attached to the bottom leg, and as they approach each other and overlap, the capacitance goes up.  You'd have to protect it and it would be susceptible to changes in environment so it could be difficult to stay really repeatable, but you could at least get good relative readings while you made the adjustment.

Digital sensors, be it mechanical switches or whatever, of course, is the simplest option.  If, for example, you made a mounting bracket to adjust the height of the switches, you could get an extremely repeatable two position sensor that doesn't even require any real logic to drive.
 

Offline ndictuTopic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: sk
Well yes, a simple piece of tape + light sensor is my backup plan. It should work once adjusted properly and hopefully only needs to be done once in a long while (eg. changing chairs).

However I was hoping for some more versatile solution, possibly just for the fun and challenge :)

Quote
I found ultrasonic/laser distance sensors, but those with required precision are quite expensive and also if I were to put my backpack/something under the desk it might throw it off.
You can buy some cheap ones and calibrate them: http://www.dx.com/p/hysrf05-ultrasonic-distance-sensor-module-for-arduino-443899#.WYOB_4jyiMo

Well the issue with the clutter under desk remains - with 30deg FOV from 120cm it captures about 60cm diameter. I would need something with much narrower FOV. Also even if I calibrate it, how stable it is with temperature change for example? I'm afraid ultrasonic isn't a way to go here...

So far the gray code reader with a strip I print seems the best choice to me, but I can't find existing solutions and creating one myself is too much effort.
 

Offline ndictuTopic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: sk
If you know that the drive for the motors are directly linked and isn't slipping, I think an encoder of some sort on the output is the most reliable way to go.  You could even just through in a pushbutton to zero at some point and a simple quadrature output should give you very accurate feedback even if the motor control isn't as reliable.

That is a great point. As JXL said, screw drive is very likely. The mechanism itself is not visible, I'll have to see if there is an easy way to expose it. But if so and if I can mount an encoder on the output that would definitely be a great and accurate solution.
 

Offline ebastler

  • Super Contributor
  • ***
  • Posts: 6677
  • Country: de
[...]
I was hoping for some more versatile solution, possibly just for the fun and challenge :)

[...]
Well the issue with the clutter under desk remains - with 30deg FOV from 120cm it captures about 60cm diameter. I would need something with much narrower FOV. Also even if I calibrate it, how stable it is with temperature change for example? I'm afraid ultrasonic isn't a way to go here...

So far the gray code reader with a strip I print seems the best choice to me, but I can't find existing solutions and creating one myself is too much effort.

Well, you got to make up your mind whether you want a challenge or want to build something practical!  ;)
 

Offline ndictuTopic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: sk
Well, you got to make up your mind whether you want a challenge or want to build something practical!  ;)

There comes a point where it is not worth it :) The encoder on the motor shaft or something like that is still fun, but trying to build a reader more complex than the entire desk probably isn't.

Thank you all for your input! I'll try to take it apart tomorrow and see what can be done.
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 16883
  • Country: 00
So I need to mount some kind of distance measuring thing on the desk. I found ultrasonic/laser distance sensors, but those with required precision are quite expensive and also if I were to put my backpack/something under the desk it might throw it off.

Those cheapass ultrasonic sensors are plenty accurate enough for that.

http://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
 

Offline ebastler

  • Super Contributor
  • ***
  • Posts: 6677
  • Country: de
Those cheapass ultrasonic sensors are plenty accurate enough for that.
http://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/

Yes, but -- as discussed back and forth in the above posts -- they have a wide-angle field of view, which leads to an ill defined response in this application (with clutter below the desk). It sometimes pays off to read beyond the first post before you fire off a reply.  ;)
 

Offline BBBbbb

  • Supporter
  • ****
  • Posts: 289
  • Country: nl
Regarding clutter on the floor and us sensor, he can always point it up not down if he can find a nice way to integrate it visually.
But anyway OP if you decide to go the practical way, I'd go with the magnetic sensors. Cheap and robust. Two small magnets and 2 small magnetic switches. If you wanna go optical I'd isolate it in a tube of some kind. Mechanical micro switches might break if they are frequently engaged.
Whatever you do double it for safety reasons.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12041
  • Country: ch
I wonder how my desk does it. I know there is a procedure to calibrate the end stops, but I don't know whether it uses any sensing in between. It's rather accurate at finding the saved heights.
 

Offline BBBbbb

  • Supporter
  • ****
  • Posts: 289
  • Country: nl
I wonder how my desk does it. I know there is a procedure to calibrate the end stops, but I don't know whether it uses any sensing in between. It's rather accurate at finding the saved heights.
Teardown time!
Who needs warranty...
 

Offline cdev

  • Super Contributor
  • ***
  • !
  • Posts: 7350
  • Country: 00
Digital calipers use a linear optical encoder. You likely can make your own by copying the pattern in one of them. Use something like that.

But you are making it way too complicated, IMHO. You could move it with reduction gearing and two stepper motors, one on each side.
« Last Edit: August 04, 2017, 12:02:30 am by cdev »
"What the large print giveth, the small print taketh away."
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12041
  • Country: ch
I wonder how my desk does it. I know there is a procedure to calibrate the end stops, but I don't know whether it uses any sensing in between. It's rather accurate at finding the saved heights.
Teardown time!
Who needs warranty...
The problem is, I need the desk! :p

I got mine on clearance (showroom demo) for 60% off, I don't have $3K laying around to replace it at full price if I fuck it up! :(

And I have nowhere to put all the stuff that lives on the desk now! :p
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12041
  • Country: ch
Digital calipers use a linear optical encoder. You likely can make your own by copying the pattern in one of them. Use something like that.
No, they don't. They use capacitive sensing, not optical.

That said, I agree that linear optical encoder could be a good solution. (They're common in inkjet printers, which is where I would look for inspiration.)
 

Offline CatalinaWOW

  • Super Contributor
  • ***
  • Posts: 5354
  • Country: us
Since you want creativity and a challenge hang a heavy chain from an inexpensive strain guage.  Measure the weight off floor as a measure of hight.  The chain will tell you where not to put your backpack.
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
The adjustable desks i have seen use a single motor in the middle, and have an index sensor on the shaft. (A microswitch pressing a filed flat spot on the shaft) it relies on the assembler making sure its level before the axel is fitted.

To calibrate it you hold the down button, it reaches the end, doesnt see the index count in 5 seconds then stops the motor. And raises to its default heigh just relying on that index count.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12041
  • Country: ch
On mine, the legs aren't really connected to each other, it's got separate motors in each leg.
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4708
  • Country: gb
What if you got a cheap pair of ultrasonic transducers. Fixing the transmitter to the top of the underside of your bench.
The receiver to the floor, where it WON'T be directly blocked.
Then time how long the transmitted ultrasonic pulse takes, to get to the receiver.

You had problems with the earlier ultrasonic suggestions, because that was trying to "bounce" the signal between the sensors and the floor. But your belongings may have caused incorrect readings.

My suggestion, is a direct, one way path, so even if it is partly blocked. It should still work. The shortest path, should give the first (correct) timing reference (which can be converted to distance, once you know the speed of sound, at your room temperature and pressure).

Obviously you would have to do the circuitry and software. It could be a fun and educational project, even if it does not work out that well.

Downsides: 5mm accuracy may either be impracticable and/or overly complicated for you to achieve. I think the better designs get 1mm resolution. But that might get very complicated.

EDIT: In practice, I expect it is too difficult to do accurately that way and it is still possible that objects stored under the bench, could still affect the readings. Although they probably won't.

Another way would be to put encoder wheels on the motor(s) or gearbox. Which makes it go up and down. You can then count how many rotations, and hence determine the distance traveled.
« Last Edit: August 04, 2017, 07:31:17 am by MK14 »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12981
Hmmm . . .
What about Grey code + some contrasting colour lines outside it to help locate the code, as a vertical strip on the wall behind the desk and a Raspberry Pi Zero + Pi Camera.   Then its just a matter of image processing to pick out the stripes either side of the Grey code (to cope with the desk being moved slightly, and reading the brightness of 16 squares in 2 rows of 8 just above and below the horizontal centerline of the image, then driving the intercepted buttons accordingly via its GPIO port.   

However it would still be worth adding some means of tracking the motor speed by feeding pulses to a GPIO pin so it can release the button if its stalled and also so it can interpolate the position between image captures so it can blip the button for the last fraction of an inch to slow down and avoid overshooting. 
 

Offline alanb

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: gb
I wonder if cheap electronic Vernier callipers could hacked to provide an output?
 

Offline BBBbbb

  • Supporter
  • ****
  • Posts: 289
  • Country: nl
I do believe if we continue giving suggestions sooner or later there will be a suggestion about an AI powered robot that would autonomously and without direct command push the button and move the table to the desired positions after analyzing OPs daily routines.
 
The following users thanked this post: 3db

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Optical limit switches should do the trick unless you want to do some fancy stuff. Two limit switches are good for sitting / standing. Quite easy to adjust mechanically.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf