Switching accelerameters question for dancebot
crazyrobotgirl
Posts: 32
Hello everyone,
Im new to the world of microcontrollers. I have been studying the dancebot by Hanno Sander, and I decided to make his dance bot my learning platform. I bought all the parts except for the LIS3LV02DQ accelerameter he uses. I cant seem to find this chip. But I do have the Memsic 2125 Dual-axis Accelerometer from parallax.
My question is how would I go about replacing the LIS3LV02DQ with the Memsic 2125 I have a looked over the code but do not know where to start?
Im new to the world of microcontrollers. I have been studying the dancebot by Hanno Sander, and I decided to make his dance bot my learning platform. I bought all the parts except for the LIS3LV02DQ accelerameter he uses. I cant seem to find this chip. But I do have the Memsic 2125 Dual-axis Accelerometer from parallax.
My question is how would I go about replacing the LIS3LV02DQ with the Memsic 2125 I have a looked over the code but do not know where to start?
spin
8K
Comments
I looked at Hanno's code you attached, and my guess it the accelerometer is read by the "updateBias" method.
If I were trying to do this, I think I'd find out what kind of value the line
produces and then try to get the same range of values from the Memsic. IIRC, the Memsic outputs a pulse. So I'd try to come up with a formula to convert this pulse length to a value similar to the "a" value in the code above.
The alternative is to understand the code Hanno uses and modify it use a pulse length as a parameter.
You'll probably need to read the datasheet on the accelerometer Hanno is using to know what values it returns.
Edit: It looks like the code reads two bytes and combines them to make a 16-bit value.
It looks like this sensor is a close replacement:
https://www.sparkfun.com/products/9836?
It was referenced from a breakout board for the sensor originally used on the project:
https://www.sparkfun.com/products/758
If you haven't done much with the Propeller yet I would suggest some simple examples like Duane suggested just to ensure you can program the Propeller and get familiar with the Programming environment.
Robert
I have been blinking leds, messing with ping, and other sensers.I have been toying with the propeller for about 6 months Mr. funny guy. But thanks alot for the info Duane. I have downloaded both datasheets and plan to study them.
RobotWorkshop, thank you also I will look at that part from Sparkfun.
Thanks guys!
Good to know this isn't your first project.
I'm a big fan of Hanno's stuff. I've tried his method of machine vision but I haven't tried to make a balancing bot yet.
I do plan to work on this sometime soon myself since I've recently gotten interested in quadcopters and I think making a ground robot balance on two wheels would be useful in my attempt to understand making a quadcopter stable.
I looked at the LIS3LV02DQ datasheet and at Hanno's code a little more.
I think Hanno is checking to see if the sensor returned a negative acceleration and sign extending it (the hard way) to 32 bits with this code:
[CODE if a>32000
accel:=800*(a-65536)
[/code]
I think he could have changed this section:
to:
I just learned the "~~" (sign extend 16-bit to 32-bit) trick from someone on the forum.
Based on the datasheet, it looks like the expected values returned from the accelerometer are between -2047 and 2047.
So if you could change the pulse received from Memsic device to a similar range of numbers, the code could be made to work.
I think the Memsic will output a pulse of 3333us for -1g and 6667us for 1g (with a 5000us pulse at 0g).
I'd think a linear equation should be able to convert one set of numbers to the other.
I was looking over the main code for the dance bot. It seems the (to me) the only way to get the bot to move forward or backwards would be to trick the motor encoder into believing its some where its not.
I could be wrong. But I had a mentos (candy) moment. But before I go further with controlling it. Maybe I need to get it to balance.
I hope my assumptions are correct. I think I have both of the accelerometers in question, so if needed I could make the comparison directly.
The constant "ZERO_G_MEMSIC" may need to be adjusted based on your own device.
The method "Memsic.GetPulse" does not exist (that I know of). This has been left as "an exersize for the reader" as they say.
Let me know if you have trouble getting a pulse from the Memsic in microseconds. Besides the Memsic objects, the code for the Ping could also be used to get the pulse length.
I think the 20ms of the loop should be enough time to read from the Memsic. If not, the Memsic could be read from a different cog.
EDIT: See below for code using the Memsic2125_v1.2 object.
CONVERSION_FACTOR = (2047 * 800) / 1667 ' assumes one G on original accelerometer
' returns "2047" and the pulse on the Memsic
' varies by 1667µs at one G.
' The "800" is included from Hanno's code.
is replacing "msec=80_000" in the tilt object ?
Will I need to change the ACC3D_Addr = %0011_1010 for the Mesmic 2125 address? Or is it a drop in conversion?
of rc truck parts I used including gears. I bought a breadboard from radio shack that is housing the electronics. Hopefully this weekend I will have videos to share.
Here are some pics of my bot with the motors, and the modified encoder to fit on the back of one of the two 540 motors. I got the parts from my brothers monster truck r/c grave yard collection.
Bottom may look alittle sloppy but the wheels are parallel, and they move with out friction. I bought a bread board from radio shack to house the electronics. hopefully I wil have a video to post this weekend.
The constants I used are just to be added to the "CON" section. Nothing needs to be removed but the following don't look like they get used so could be removed.
Extra constants don't actually make the code size any larger (just the spin file).
The Memsic isn't an I2C device. It isn't read the same way as the other accelerometer so there isn't an address for it. It's read a lot like a Ping sensor. You need to have a pin to read from the sensor and a method to read from it.
So while my "updateBias" method should replace the original "updateBias " method, it's not exactly a drop in replacement. My method calls a non-existing method "Memsic.GetPulse". I haven't written such a method (I wanted to leave some of the fun to you). If you need help with it, let me know.
I really like your robot. I love the monster wheels.
Do you have an h-bridge curcuit yet? Which Propeller board are you using to control it?
I took a look at the Memsic2125_v1.2 object. It looks like it returns values in clock cycles. The Memsic2125_v1.2 runs in its own cog so it should return results very quickly. If you're out of cogs, it should be possible to read from the device a different way but I used the Memsic object since it was easy to use.
Here's some updated code.
The above code replaces the original "CON" section, the original "OBJ" section and the original "updateBias" method.
You can adjust the "ZERO_G_MEMSIC" by running "Memsic2125v2_Serial_Demo.spin" and seeing what your sensor outputs for the raw x value when level. This value should be somewhere around 400,000. Use this value for your "ZERO_G_MEMSIC" constant.
I don't know what kind of encoders Hanno used. My guess is using the #27906 on the final drive shaft will likely not give you enough resolution to balance the bot.
You'll probably be better off with an encoder on the motor shaft. From the pictures, it looks like you may be able to attach an encoder disk to the shaft coming from the motor. You'll get much better resolution if you can attach the encoder to the motor.
Do your motors already have the QME-01 encoders? If so, do the work? If they work, leave them! They'll be much more precise than the other encoders which will help in balancing the robot.
Do you know what the voltage and current requirements are for the motors?
If you post a picture of your H-bridges someone around here will likely know what the are.
You mention:
I assume you're using the Propeller chip but there are lots of different boards with a Propeller chip on it. There are the Propeller Protoboards (two kinds), QuickStart and a bunch of others. Just about any Propeller board should work fine for controlling your robot but some are more robot friendly than others. Is there a part number or name on the board(s) you're using?
Do you have a gyro for your bot? The dance bot needs both an acclerometer and a gyro to balance.
Single sourced from one supplier.
I agree with Duane. The 27906 position encoders work well for the original application they were intended for but I don't think they would work well for a balancing robot. The QME-01 encoders or even a hacked mouse encoder would probably be a better option.
If the motors have an exposed shaft for the armature then you should probably leave them. Motors like that are getting harder to find and I prefer motors like that whenever I can get them since it makes fitting an encoder much easier if you want to use one. Having the encoder on the armature can not only help with accuracy but is extremely useful to regulate the speed of the motor.
Sounds like you got a fantastic deal on all the equipment and it is good to hear that it all went to someone who will appreciate it and learn with it. The sad part is that if it was someone with a large cache of Parallax stuff we may have lost a forum member....
Robert
I wished I would have opened up to you guys months ago for questions. This is fun!
Thanks all
You can make them from the older (Non-optical) mice. Those mice are usually cheap now (sometimes free) and most have decent encoders in them. Here are just a couple examples:
http://members.shaw.ca/swstuff/mouse.html
http://retrointerfacing.com/?tag=mouse-encoder
Also, if you want to make your own I have a thread I started that has some great tools for printing your own:
http://forums.parallax.com/showthread.php?138597-Encoder-generators-Quadrature-etc.&highlight=encoder