Raspberry pi plus accelerometer to measure height?

Hi,

I was thinking of using my Raspberry pi plus an accelerometer / gyro located next to the router to measure what is going on. You can get them for $4 or something from China, think it’s l2c which is available on the pi pins. Maybe too much vibration during cutting (or is it? Filter?) , but for if the Z is lowered to the surface very slowly, shouldn’t it register a bump that could be used to set the surface level height? Alternative to the tiny touch plate idea, since there is a variable height in the bits used, maybe something along these lines might work. Thought of poximity sensor, inductive ones and capacitive ones, but they are fixed height ideas or too exposed to flying debris, a tiny board like this could be located anywhere near the router really, and it could probably be a simple octoprint plugin.

You would have to be very very quiet though.

Cheers!

Accelerometers and gyros measure the rate, and you’re interested in measuring the absolute. So if you want to know the height, you need to integrate it twice, and any noise ends up accumulating. Typically, in something like a car, you would adjust the estimate from these accelerometers with absolute measurements, like GPS or wheel encoders. Someone told me once, “A $10 wheel encoder is going to be more accurate than a $10k accerometer at measuring position”.

Add to that the fact that the mems accelerometers are very small, and the router vibration will end up really affecting their measurements.

It would be hard to make a traditional position estimate with this, nearly impossible.

But the advantage we have is that the Z (when it’s working) should only have three accelerations. If your Marlin config for Z is to accelerate at 1000mm/s^2, we should either see +1000mm/s^2, -1000mm/s^2, or zero (after compensating for gravity).

If you were able to get really crisp start and stop times for when it was accelerating at those values, you could estimate the height.

If you knew what Marlin was trying to do (what height it was supposed to be heading), you could even detect big problems sooner. If it was trying to raise the bit, and instead, you saw no acceleration, or negative accelerations, then clearly, it is sinking.

At the end of the day, I think it would be nice, but really, you need to stay with your CNC anyway. This can’t detect every problem, and it wouldn’t be reliable enough to not have to sit with you machine. Most problems this can detect are pretty obvious to the human ear.

It would be interesting to experiment with though.

Also, right there in my comment is a better solution. Just put an encoder on the Z axis.

1 Like

There have been things done with HelioS printer that seem interesting.

YouTube video

His idea is to to test for a collision like you would when seeing if something is hot, jab closer and closer until something happens, would proably be a noisy sine wave with a random jump. That is probably easier with such a low momentum device rather than something that weighs 20 pounds like the gantry in a lowrider 2.

I have never thought of using a wheel encoder, not sure how I would apply it in this case to detect contact vs measuring height. Something to keep in mind though, all ideas appreciated.

I will play with the accelerometer regardless, if I can stream the results to a file using the pi, either I can create artwork or analyze it for larger jumps and tweak gcode. There are all those io pins on the pi waiting to be used for something more than just a gcode sender to an arduino board. :slight_smile:

Cheers!

My 3d printer (Rostock Max) uses an acceleromter on the print head in its calibration routine.

The sudden stop when the print head hits the glass is an “acceleration”. 8^)

It works great, but I do think there was a lot of trial and error involved in filtering the data to get consistent repeatable results.

The variability in bit length is accounted for because you use the bit itself to “touch” the touch plate.

So, there someone got it to work, so that’s promising. If I want to get really stupid I could try add some sort of AI learning to the data so it could get a feel for what it is doing. And then probably create a bunch of wooden terminators.

My language skills need work, I was mixing thoughts in one sentence, happens in forums for me, if I get 50% understanding of what I mean I’m doing well. :slight_smile:

The touch plate is the simplist method and no doubt works great, and I will probably use one, just playing with ideas at this point to get more use out of my pi’s io. When thinking of a fixed position head on a 3d printer, using an inductive or capacitve probe is OK but has to be close to the same height as the tip, but no so much if the print head is at random heights (router bits), there are pi things like proximity sensors for pi projects little robots but I am pretty sure they would be toast is 5 minutes from wood debris.

Cheers!

There was a crap ton of trial and error with the accelerometer. I’ve seen some of the fails, they were awesome to watch, but really hard on the hotend and glass bed.

1 Like

Probably not an issue with a bed of foam… :slight_smile:

Oh, I misunderstood. I thought you wanted to measure the height during a job. And then detect skipped steps. Apparently miscommunication in the forums is due to writing and reading…

The Z on the mpcnc has a lot of torque (and a big weight to use as a hammer). I would be worried it wouldn’t stop it enough to trip the accelerometer.

Also, at the end of that video he says, “0.1mm should be good enough for bed levelling”…

That’s quite a mountain on my printer…

It won’t be hard on the machine, but…

I think it will be MUCH harder to sense a router bit hitting foam (or even wood) than a brass printer nozzle hitting glass. It may be possible to get it to work, but I would think it’s going to be very difficult.

If I were looking for something interesting to do with the Rpi GPIO, I would try adding strain gauges somewhere on the machine to measure the loads generated by the milling process.

See
https://forum.v1e.com/t/logging-for-data-analytics/17693/18

If it doesn’t work with something like foam, I wouldn’t want to do that anway,. I am thinking if it is sensitive enough to detect a tap it may work, but who knows, only one way to find out. :slight_smile:

It would be interesting to have some kind of touch plate on a servo swing down… marlin has gcode commands to control a servo that are easy to setup. I can’t figure out a simple mechanism to swing one into place that won’t get in the way or snagged on things.

Another angle, if you put a small speaker or vibrating element, you can pick up the vibration with the accelerometer and when it touches something the amplitude of the vibration should change. Especially if you can find resonance, a small damping can make a big change in amplitude.

Interesting idea, first thought is that the sound or vibration may be supplied by the machine itself in the form of noise, I think it wouldn’t have to be perfectly resonant for a paticular material, just a change in amplitude.

As for servos, they are trivial (pulse width), but I think it would be the same problem, you have a fixed height or are probing for contact. Might do something with a servo or two, but for something else (pop up a lolli when a job is done?).

I am not thinking of firmware changes or messing with the cnc controller, but using a raspberry pi as a supervisor, for functions that are not timing critical, somewhere you can do more loose programming and rapidly reiterate code via ssh. Tthe part that would be interacting with the job is the gcode sender, like octoprint or cncjs. If I just sent a G1 somewhere, what is the accleration graph for 1 inch vs 1 foot (the same hopefully), or I am having a problem with an arc because the speed is too fast, etc.

Cheers!

Why not leverage the scales used for machine shop DRO’s?

Why not indeed, probably because I just had to google what that was. :slight_smile: I am in the head space of thinking about the battlefield conditions involved where nothing is in a fixed place, or not easily repeatable, and it has to be at least as easy as the tiny touch plate, with a few geek points added for the fun factor.

Cheers!