Sunday, 18 January 2009

Calculating platform angle

Photobucket

I have written arduino code to calculate the platform angle and it works perfectly!

Photobucket

This is a graph made in Processing which is taking the angle calculated by the arduino from the serial port. I am oscillating the board quickly.

I am using the complementary filter approach documented by alot of balancing robots. The actual code is something like:

val = ((((analogRead(xPin)-xZero)/148.48)* 180/3.1415926535897932384626433832795))*-1); //accelerometer angle calculation

valG = valG + ((analogRead(gyroPin) - gZero)*4.8099347014925373134328358208962)/200; //integration of gyro and gyro angle calculation

angle = (val * 0.005) + (valG * 0.995); //complementary filter

valG = angle; //drift correction of gyro integration


I can tell it works as intended, because if i rotate the board flat on the table, the gyro senses it, whilst the accelerometer is still flat, so you see it increase and then decay slowly back to zero, rather like a capacitor discharge curve. This shows the accelerometer correcting the gyro's 'drift'.

16 comments:

  1. looks good mark! integrate gps and some sort of autonavigation intelligence so it can drive you home from the pub by itself!

    ReplyDelete
  2. can you comment on the specific floats you used in your Val and ValG calculations? what is the dt used in the integration. thanks for the clarification!

    ReplyDelete
  3. What sensors are you using? Can you post your pde?

    ReplyDelete
  4. look at this, for similar code and sensor
    http://forums.adafruit.com/viewtopic.php?f=25&t=12352

    ReplyDelete
  5. Nice looking project. I was wondering if you had an idea of the overall cost and the expected speed when its done?

    panikos

    ReplyDelete
  6. Thanking you for sharing the suberp project,

    I wonder you could post the arduino and processing code to calculate the platform angle. It looks like that you used the processing to graph the output.

    Regards,
    Ozhan

    ReplyDelete
  7. Excellent project.

    Why do you multiply by 4.8099347014925373134328358208962 and divide by 200?

    Where does 4.809 and 200 come from?

    Thank you,

    Joaquin

    ReplyDelete
  8. Excellent

    but what are 4.8099... and 200 for the gyro and 148.48 for the acc?

    ReplyDelete
  9. Where does the acceleorometer fit into your code , please help ..
    Lot of money invested

    ReplyDelete
  10. hi,
    how you have connected the XV3500CB?
    have you a wiring diagram?

    ReplyDelete
  11. Do you have the eletric circuit draw?....and the components positions too?...

    ReplyDelete
  12. great thanks for share

    I thing kalman filer is good for segway

    ReplyDelete
  13. I would like to say thanks for sharing this valuable information.
    2 Wheel Self Balancing Scooter

    ReplyDelete

  14. Nice looking project. I was wondering if you had an idea of the overall cost and the expected speed when its done?

    ReplyDelete
  15. thanks for sharing information i like your blog i read it but im searching for a Toronto Limousine
    if you any infornation contact us thanks

    ReplyDelete
  16. Keep sharing more informative posts like this... Segways For Sale UK

    ReplyDelete