Time Required to Read Memsic Accelerometer
I'm building my second balancing robot (I posted the first under Completed Projects on January 1, 07).
For this one I'm using as sensors·the Parallax MX2125 accelerometer and the ADXRS300 angular rate sensor, along with a BS2px. I'd like to read both sensors and do all calculations·within each cycle of·motor pulses so I'm looking carefully at the exact time each taken up by each routine.
I set up a Parallax USB Oscilloscope to measure the time between motor pulses as I progressively isolate each routine. Reading the ADXRS300 (via an 0831 ADC chip to convert the voltage output of the sensor to a digital byte)·takes 2.5 msec. No problem.
The time required to read the MX2125 is surprising - it takes much longer to read the x axis than the·y axis, and the order in which they are read also makes a big difference. The routine is very simple:
Memsic:
· PULSIN MemX, 1, memsicX
· PULSIN MemY, 1, memsicY
RETURN
The time it takes to complete variations of this routine are:
Reading both x and y, as above...· 17.8 msec
Reading both, but y first...··········· 28.0 msec
Reading just x...··························17.8 msec (same as both, starting with x)
Reading just y...·························· 8.1 msec
Does this make sense? Might these results be an artifact of how I set up the test? If these results are accurate then I will see if I can orient the device so I can get a good reading just from the Y axis. But I wonder if anyone has any insights about what's going on.
/John
For this one I'm using as sensors·the Parallax MX2125 accelerometer and the ADXRS300 angular rate sensor, along with a BS2px. I'd like to read both sensors and do all calculations·within each cycle of·motor pulses so I'm looking carefully at the exact time each taken up by each routine.
I set up a Parallax USB Oscilloscope to measure the time between motor pulses as I progressively isolate each routine. Reading the ADXRS300 (via an 0831 ADC chip to convert the voltage output of the sensor to a digital byte)·takes 2.5 msec. No problem.
The time required to read the MX2125 is surprising - it takes much longer to read the x axis than the·y axis, and the order in which they are read also makes a big difference. The routine is very simple:
Memsic:
· PULSIN MemX, 1, memsicX
· PULSIN MemY, 1, memsicY
RETURN
The time it takes to complete variations of this routine are:
Reading both x and y, as above...· 17.8 msec
Reading both, but y first...··········· 28.0 msec
Reading just x...··························17.8 msec (same as both, starting with x)
Reading just y...·························· 8.1 msec
Does this make sense? Might these results be an artifact of how I set up the test? If these results are accurate then I will see if I can orient the device so I can get a good reading just from the Y axis. But I wonder if anyone has any insights about what's going on.
/John
Comments
/John
When I wrote a Propeller object for the MemSic2125, I scoped both channels from the MX2125 first to see what kind of signal I was dealing with. Both X and Y pulses start out at the same time, but depending on the orientation/acceleration, one pulse will usually finish before the other. Only when the orientation and/or acceleration between channels are Equal will X and Y be the same. At room temperature and 0g/0acc, the value
for X and Y should both be close to 5mS.
Depending on the orientation and/or acceleration, the Pulse width for each channel can vary from 1.25mS to 8.75mS indicating a value from -3g to 3g with a repetition rate every 10mS.
Since the BS2 can not read both axis simultaneously, a value of 17.8 is not out of the question..... (8.75mS + 8.75mS = 17.5mS) ...Although I would think it unlikely to sustain 3g. <--This should be a worst case scenario. 28mS is extremely high unless you have other delays in your program causing you to "miss" the pulse, requiring PULSIN to wait for the next interval in which case it would take an additional 10mS. This brings the 17.5mS worst case scenario to 27.5mS.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/24/2007 4:17:26 AM GMT
/John
I think you wrote a very cool routine to balance your first Bot, using the PING sensor. I've built a similar Boe-Bot as yours, but using the MX2125. I'd like to try to use your routine but with the MX2125 and I am not sure what changes would have to made. All I know is that the reading values for y axis are min 1875 and max 3125. Could you help me please. Thanks a lot.
//Ray
I have not gotten my MX2125/gyro robot to balance yet so I don't have an answer. By the way, the Smart Sensors text (which you can download from Parallax) has an excellent discussion on processing the raw readings from the MX2125.
For a balancing robot, the main problem with the MX2125 is that its tilt readings are confounded by horozontal acceleration as the motors try to stay under the center of gravity. A forward acceleration reads the same as a backward tilt and vice versa. The symptom of this is that you should be able to get the robot's wheels to move correctly if you hold the robot in the air and tilt it forward and back. But the moment you set it on the floor the motors begin a rapid oscillation that does not balance the robot.
What's happening on the floor is that if the robot starts to tilt forward the motors drive forward which makes the MX2125 think its tilting backward so the motors drive backward which makes the MX2125 think it's tilting forward, etc., many times per second.
I know its possible to filter out this noise (because others have done it!) but I have not succeeded yet. A common strategy is to use a Kalman filter (a routine the estimates the true state by cancelling out opposing errors over time) and I also have an idea for another filter strategy.
I came to the conclusion that both the Kalman filter and my own idea were just too processor and math intensive for any version of basic stamp. I'm sure an SX could do it, but instead I've jumped right to the latest thing -- I've taken a break from the balancing robot to learn spin and some prop ASM and then I plan to rebuild the robot around the propeller.
I'd love to hear if anyone else is working along similar lines, particularly any attemps to implement a Kalman filter using a Propeller.
Sorry I can't help more.
/John
Thanks a lot for your answer. It does help me a lot. I tried (today) to modify your program to use MX2125 variables and I am getting exactly the result you are describing. The bottom line - robot does not balance. Instead it wobbles too much back and forth. I am ordering the PING and the SX chip (I was using the BS2 chip before), so I can have the Boe-Bot balance like yours. Please e-mail me on radem2@comcast.net, as I would like to exchange more ideas with you. Thank you so much. I am sure you will succeed with the Propeller, it is just matter of how long it will take you. I also have a VEX kit, which has quite powerful Microchip controller, so I am sure that is a way forward to build more sophisticated robots, but I need to get the basics work first.
brgds //ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
/John
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Problems are the "roads" of life,
solutions are only "onramps" to the next problem
············································· "Brad Smith"
·