LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware - ARM (https://www.linuxquestions.org/questions/slackware-arm-108/)
-   -   Connecting an accelerometer to a Pi (https://www.linuxquestions.org/questions/slackware-arm-108/connecting-an-accelerometer-to-a-pi-4175495839/)

louigi600 02-22-2014 04:10 AM

Connecting an accelerometer to a Pi
 
When my son is not using my Pi for watching toons I plan to use it to control a model submarine droid. Appart from controlling servos via GPIO pins (to my understanding there's a kernel module [servoblaster] that does that to minimize servo jutter and stop them from overheating dew to task switching timing inaccuracies afflicting userspace) ... but I wanted to give my SUB an accelerometer so that it could correct unwanted accelerations.

This might be a good accelerometer for the job: https://www.modmypi.com/adafruit-tri...-accelerometer

but there's no tutorial for connecting it to Pi and reading data from it.
Any help is appreciated.

Doc CPU 02-22-2014 05:01 PM

Hi there,

Quote:

Originally Posted by louigi600 (Post 5122706)
When my son is not using my Pi for watching toons I plan to use it to control a model submarine droid.

that seems a very interesting, but also a very eager project. I wonder how you're going to control the vessel:
  • Via LAN cable? That would restrict its mobility a lot.
  • Via WiFi? Nearly impossible, the range of 2.4GHz radio waves is mere centimeters under water. Except you have a long rod protruding out of the water.
  • Fully autonomous? That would require a camera and some sophisticated software, and only slow movement so you're still able to catch it if it should go rampant.

Quote:

Originally Posted by louigi600 (Post 5122706)
I wanted to give my SUB an accelerometer so that it could correct unwanted accelerations.

Okay, but think of physics: You can't distinguish between gravitation and acceleration. Therefore, every slight tilt or cant of the vessel would be interpreted as an acceleration in a certain direction. Did you consider that?

Quote:

Originally Posted by louigi600 (Post 5122706)
This might be a good accelerometer for the job: https://www.modmypi.com/adafruit-tri...-accelerometer

but there's no tutorial for connecting it to Pi and reading data from it.

So you'll have to go the investigative way. The page you point to has a link to the data sheet. There are some other projects for the Pi that communicate with I²C devices. I can't see any other way than checking with the data sheet what commands and instructions the chip needs to be sent to, and what its response looks like and how it is to be interpreted. The general way of using I²C communication can be taken from some other project.
That probably means hours, if not days of investigation and testing. But I'm afraid someone has to do it. If nobody else did it for this chip on the Pi yet, you might have to be that pioneer. ;-)

[X] Doc CPU

michaelk 02-22-2014 05:33 PM

Quote:

You can't distinguish between gravitation and acceleration.
Yes you can. It depends on the type of accelerometer. These accelerometer can measure both static and dynamic acceleration.

In a nutshell static measures gravity and dynamic measures shock and motion. http://www.analog.com/static/importe...ts/ADXL345.pdf

louigi600 02-22-2014 05:40 PM

Quote:

Originally Posted by Doc CPU (Post 5122973)
Hi there,



that seems a very interesting, but also a very eager project. I wonder how you're going to control the vessel:
  • Via LAN cable? That would restrict its mobility a lot.
  • Via WiFi? Nearly impossible, the range of 2.4GHz radio waves is mere centimeters under water. Except you have a long rod protruding out of the water.
  • Fully autonomous? That would require a camera and some sophisticated software, and only slow movement so you're still able to catch it if it should go rampant.



Okay, but think of physics: You can't distinguish between gravitation and acceleration. Therefore, every slight tilt or cant of the vessel would be interpreted as an acceleration in a certain direction. Did you consider that?



So you'll have to go the investigative way. The page you point to has a link to the data sheet. There are some other projects for the Pi that communicate with I²C devices. I can't see any other way than checking with the data sheet what commands and instructions the chip needs to be sent to, and what its response looks like and how it is to be interpreted. The general way of using I²C communication can be taken from some other project.
That probably means hours, if not days of investigation and testing. But I'm afraid someone has to do it. If nobody else did it for this chip on the Pi yet, you might have to be that pioneer. ;-)

[X] Doc CPU

I'm going for full auto ... and I'm not targeting millimetric precision so I'm hoping to do without camera ... but I'll be doing maths on the accelerometers to estimate position. I'll not be attempting to make it swim thought a tiny home but just have it follow a pre-calculated path supposing there are no obstacles in the way. If I can get that to work I'll look into handling unexpected obstacles.

I also said "unwanted acceleration": g is constant and practical so I can deal with that as acceleration is a vector and vectors sum (yes it's simple physics).

I found some other interesting sensors with accelerometer, compass and rotation sensor: I might use one of those

michaelk 02-22-2014 06:16 PM

School project?

Yes, look into using Inertial Measurement Units (IMUs) using a fibre optic gyro. They are small and used in drones etc. I think you will find that using acceleration as a sole means for determining position very crude. Also IMUs have a drift factor, if you do not use some external input for speed and depth make sure to take it into account.

louigi600 02-23-2014 02:32 AM

Quote:

Originally Posted by michaelk (Post 5122988)
School project?
Yes, look into using Inertial Measurement Units (IMUs) using a fibre optic gyro. They are small and used in drones etc. I think you will find that using acceleration as a sole means for determining position very crude. Also IMUs have a drift factor, if you do not use some external input for speed and depth make sure to take it into account.

This is the other sensor I found intresting: http://www.allthingsmicro.com/produc...accelmag-board is has all 3 in one neat pcb ... the only snag is that they are not oriented in the same axis which will require software coordinate rearranging. But am an absolure nubi in this field so any suggestions are welcome.

Yeah ... I was guessing that the deceleration caused by drag (and fluid current) would be unmeasurable so I'd haveto account for that somehow, maybe have a small propeller up front attached to an undriven DC motor and measure the tension produced. If I remember correctly the voltage produced is close to linear with angular velocity of the prop, and that should be linear with the speed too.
Water is really dense compared to air so I cal assume any lateral drift is dew to fluid movement, or at worse, the sub changing immersion depth ... so I guess doing full auto might need a means of measuring depth too. How about an accelerometer placed on a tilting surface that is moved by pressure differential between outside and inside ?

Really coarse if fine for a first attempt at a drone ... if I like it I'll look into better accuracy but GPS will not work under water so I'll haveto figure out something else.

Update on the sensors: A friend of mine has a 10DOF left over from is multi-rotor drone chopper ... he's gonna give it to me for some reasonable price so I think I'll go for that.

louigi600 03-13-2014 11:35 PM

Now that I have the IMU I did a littple reserch and play with it. If anyone is intrested I wrote a small article on how I went about reading some information out of my IMU on
docs.slackware.com


All times are GMT -5. The time now is 11:13 PM.