Let's Make Robots!

Measuring angle of object in front of you

So I have 0 experience in building robots, and so far this robot is just in my head, but when I have money to start buying parts I plan to build, and document the build. Basically I'm making a cheap Tamiya tank-tread based robot. Eventually I want this to be able to go play outdoors semi-autonomously on some local 4-wheeler trails (I say semi-autonomous because said trails are surrounded by river, so I want to keep an eye on it).I want it to be able to decide on its own whether or not it is capable of going up a certain incline. This can be a set number, I can experiment to find what sort of incline it can do safely, but from a lot of reading I can't decide how I want to do this.

I originally throught that maybe I could use an accelerometer to make it back up if it inclined too far, but it turns out that the ability of my phone to tell me what angle it is comes less from raw sensor data and more from complex filtering of data (ie: Kalman filtering). From what I've read using a full IMU is ideal, but this is something I'm trying to do on a very limited budget, and I don't like copy and paste coding, I prefer to understand the code I'm writing and all that code for a Kalman filter is beyond me. 

The second option I thought of was using two distance sensors (likely sonar, since my understanding is that ir is useless in full sunlight), or one that could move up and down on a rack to measure the distance at two different points, and use simple geometry to measure the angle. However from what I have read the sonar signal tends to have trouble returning to the receiver when bouncing off of an angled surface, which defeats the purpose. This also has the issue of only having one axis, which would help only in the ideal situation that I am hitting the hill straight on.

I've also considered maybe using two whiskers at different heights, with their lengths making them form the set angle I mentioned before. If the top one hits first it is unsafe, and I should turn around. If the bottom one hits first, I am safe. This obviously has the same single axis problem as before, and additionally is going to end up bending/breaking thw whiskers (since they have to hit the hill to measure the angle, they will also push against the hill as the robot moves forward until the chassis is at a great enough angle to lift them above the ground). 

I've also considered that maybe I could build two boxes, each with a pendulum having its axis of rotation on a potentiometer, which would essentially give me fairly precisde feedback on both the pitch and yaw of my bot (these would be mounted with one going fore to aft, and the other left to right). This is the one option I've come up with that I could do on the cheap and give me reliable two axis feedback so long as I only made measurements while I was stopped. The primary issue I'm having (in my mind) is that these might be kind of large, and are a decidedly mechanical and non-roboty method of doing things.

I've seen some mechanical tilt sensors, but to my understanding these all use mercury in a glass tube, and I'd rather not have mercury involved (while the bot is running I will be warmly embracing trees in my arms).

So does anyone have any advice? I realize that an IMU could be built relatively cheaply, but I have no PCB experience, and feel that building the entire board might be a bit over my head as a beginner. Is there an easy solution that I've missed in my research? Are my pendulum-pot-boxes a revolutionary invention that will likely change the entire world for the better? Should I just keep my bot indoors, and let it aimlessly wander my house not risking life-and-limb (microprocessor and chassis?) in the wild blue yonder?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I suggest you get a $12 xyz accelerometer breakout from pololu.com and experiment with it.  I think it could work for a basic robot that isn't high speed, and if you decide it is unfit for your robot you can always use it on something else.  The best part is you how much you will learn from it.

a ring that was mounted to be able to move up and down for one side of the 'tilt switch' and a pendulum for the other, but, $12 for 3 axis data in a smaller form factor sounds like a much better plan.

Okay I was doing a bit of reading about Kalman filters, and it seems as if the idea is to always use an accelerometer and a gyro in tandem, so that it can kind of combine the strengths and weaknesses of the two. Can I use a 2-axis gyro with a 3-axis accelerometer, since pitch and roll are really all I need? Or would it be worth it to spring the extra $10 and just get a three-axis gyro, and that way if I ever want to/have the ability to build a quad/tri-copter I already have 2/3rds of an IMU?

Also, won't this eat up a lot of my processor time, and pins (the board I plan to get is the DFRobot Romeo, since I cannot find an Arduino compatible board and motor controller for anywhere near that price). My understanding is that each axis of both the accelerometer and the gyro will need pins to send the data to the microprocessor. Would I be better off getting a Mega, and building/buying a seperate motor controller? Or would I be fine with the Romeo for now? I figure that with this project after I have all the hardware I will probably have minimum a few weeks worth of software writing/tweaking in front of me, which would give me time to save up the extra money for a Mega for future projects, so I would like to use the Romeo at first if at all feasible.

I'm starting to think that this is all above my head, and maybe should be reserved for a version 2 of this robot. 

@Birdmun: I'm having trouble envisioning what you mean about the ring mounted to be able to move up and down. Do you mean mounted around the pendulum, but sidways to it, so that both can operate in the same space? If so, that sounds like something that would at least make this angle measuring unit half the size. If not, well, I'm confused, but I kind of just came up with an idea for how it would work and be half the size. :)

Thank you both for the help, both now and in the future once I actually get some pieces. This is an idea that randomly occured to me a week ago, and I have been obsessively hunting down information from the internet, and I am simply amazed by how much information is available, and how large of a community there is to support people that want try this out.

I didn't see a 3-axis gyro offered at DFRobot.

You are correct you would need at least 5 pins to get data from all 5 devices. The Romeo is fine, just realize that if you smoke the motor driver you are stuck with just an Arduino at best. Worst case, you smoke more than the driver. With a sheild on a basic arduino you could replace the sheild if the driver gets smoked or even better yet maybe the driver is socketed so it can be replaced all by itself.

Sometimes my explanations leave a whole boatload to be desired. :) I will try a quick drawing and hope it is worth a few tens of words.

line art(LOL) of mechanical angular sensor

If the ring is able to be adjusted up or down, you could tune it for more or less angle. Like I mentioned before, attach the ring or pendulum to ground or power and then either the pendulum or ring to a digital input to your controller. As soon as the ring and pendulum cable make contact the input to the micro will change and you will know you are at a given angle. If it is mobile you could then get an idea of what angle if you know the distance of the ring from the pendulum connection point.

yeah, you only need a 2 axis gyroscope if you are going to implement a kalman filter for pitch and roll, which will work best with a dedicated processor.  you can check out an example (not the greatest, but you should get the point) of accelerometer based stabilization here

the simplest thing i can think of, and i do love simplicity, is a simple mercury tilt switch:

very simple: mercury drop makes connection between wires, tilt it over and it drops to the other side
and the connection is broken.

u can get these on ebay dirt cheap.


Sorry I haven't responded in a few days, been busy with family time this weekend. After considering some more things that I would need for outdoor navigation I've decided to put off the outdoor bot for awhile. I figure even with just basic distance sensors my bot won't know the difference between a blade of grass, which it can run over, and a tree, which it cannot. The implementation behind building a bot that can not only go outdoors, but go outdoors and actually "explore" on its own is going to be far too tough for a beginner such as myself.

Instead I have decided my first bot will be a tiny little vacuum bot, using  Ezekiel181's idea amazing find of those little shroom vacuums. This project is primarily to teach me and my girlfriend a bit more about electronics (I've always been into software), and so that she can learn some coding that will actually be fun for her, making a robot run into a wall being more fun than learning how to write cout << "Hello World", print "Hello World", echo "Hello World"; or even, if you prefer,  ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+. (and yeah, I may have cheated on that last one, I have no desire to ever use BF).

I actually found that adafruit sells non-mercury titl sensors that just use a little ball, which is something I will keep in mind as I add improvements to my vacuum bot (which in my mind will kind of be more like an "attachment" bot, with power and sensor cables acting as a tractor's PTO)