The 1st part of this thread is here:http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282384853/0Please make sure you read it before going any furtherThe previous thread's name was not relevant any more, so I decided to create this new topic.

I have been fascinated by balancing robots since yearsMy first implementation is here http://forums.parallax.com/showthread.php?t=103850&highlight=balancingThe bot used an IR sensor to maintain a constant distance to the floorSince then, any attemp to make an IMU based robot, failed miserably I read a lot and realized that I had taken the wrong path (Continuous rotation servos, sensor position, integer math, single power supply...)

I started again from scratch, ... and here it is

See it live: http://www.youtube.com/v/pC6yeyDunJg?

In this thread, I intend to step by step describe this project in an attemp to help newbys and save time in their quest for balance.Describing and sharing projects is also the best way to learn from others. The second objective is to implement and propose various potential improvement: 12 bit ADC, wheel encoding, moving bot with RC control

Well, I have just spent about 2 hours getting my angle estimations to graph on processing. Got it working and it is beautiful to see your data in a graph. My angle estimation is quick, accurate but still easily subject to translations.

This is the IMU (Inertial Measurement Unit), 5DOF (5 Degrees Of Freedom) from Sparkfunhttp://www.sparkfun.com/commerce/product_info.php?products_id=9268This breakboard incorporates a IDG-500 dual-axis gyroscope and a triple axis ADXL335 accelerometer Datasheets:http://www.sparkfun.com/datasheets/Components/SMD/adxl335.pdfhttp://www.sparkfun.com/datasheets/Components/SMD/Datasheet_IDG500.pdfWe actually need only 3DOF (2 Acc and 1 Gyro axis)I got an older model with a ADXL330/IDG-300 combo (remember I have been wandering around this project for two years )

You should read "2,10"The first number is the real time needed to go through the loopThe second one is the final time loop, including the variable added delay

Next Part: data aquisition, zeroing and scaling

This presentation is rather time consuming; English is not my native language (you may have notice the accent français in my writing)I will pursue if sufficient interest is shownalso, if I go too slow, too fast or if I am just boring, just let me know

[size=14]2 - Zeroing sensor[/size]Before aquiring data in the loop, sensors should be zeroedThis means that when the bot is stricly still and vertical, sensors should read "0"except for the vertical axis (Acc_Z), which is sensing gravity (1g) Zero mesurement is performed in setup:

Before going further, make sure you get that type of symetrical data(this is one pitfall in this project )It is now time to adjust sensorZero[ACC_Z] by adjusting "sensorZero[ACC_Z] -= 102"in order to have opposite/symetrical values (ie +103 and - 103) when going from 0 to 512 Quids (O° to 180°).

[size=14]5 - angle and rate calculation[/size]ACC_angle = getAccAngle();the angle is obtained by using the arctangent of the two accelerometers readings. The accelerometer values do not need to be scaled into actual units, but must be zeroed and have the same scale.

You can check the (noisy) Acc angle and Gyro rate within the serial monitora better option is to display graphical data using LabView or ProcessingI can share my code with Labview ownersGybby623, would you please post your Processing code ??

I wouldnt say that... it does make sense. These are inverse pendulum's after all, so when you think about say a clocks pendulum, the weight is at the bottom. Since these are inverse the weight should be at the top. The motors weight is effectively null as its on the axis of rotation about the axle's.Not debating anything you said obviously, but it does make sense.

Very good writeup - keep it up

I have had all the bits of make one of these for about a year now, but I just havent gotten around to starting - too many other projects on the go sadly.

keep going this post is great and verry usefull i plan on making a quad copter and was wonderuing how i would do the self balancing function as i never messed around gyro and accelerometer so your explaination are quite a good start

This sketch takes ASCII values from the serial port at 9600 bps and graphs them. The values should be comma-delimited, with a newline at the end of every set of values. The expected range of the values is between 0 and 1023.

void setup () { // set up the window to whatever size you want: size(800, 600); // List all the available serial ports: println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Arduino or Wiring module, so I open Serial.list()[0]. // Open whatever port is the one you're using. String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); myPort.clear(); // don't generate a serialEvent() until you get a newline (\n) byte: myPort.bufferUntil('\n'); // create a font with the fourth font available to the system: myFont = createFont(PFont.list()[3], 14); textFont(myFont); fontInitialized = true; // set inital background: background(0); // turn on antialiasing: smooth();}

void draw () { // nothing happens in the draw loop, // but it's needed to keep the program running}

However now I get a value too small, approximately 1/3 of the right angle. I am using a simple if statement which waits until the dt > 0.01, which in my case is 0.011 and that is my constant dt. What am I doing wrong?