Balancing Robot


184 posts   Page 2 of 8   1, 2, 3, 4, 5 ... 8
by maverick7170 » Thu May 10, 2012 3:45 pm
To add another data point, I helped teach an undergraduate engineering course where the students built Lego Segways for their final project. Here is a image of two students driving their segways over an obstacle course using bluetooth control:

http://dl.dropbox.com/u/580506.....gway_2.jpg

An important part of the controller is the loop time/update rate. For our Lego Segways, an update rate of 10 ms or better gave good balancing results (this depends on the dynamics of your system). In each control loop iteration, the students had to do the following:


  • Read sensor information from the gyro sensor and wheel encoder

  • Numerically integrate the gyro sensor reading to get the segway lean angle

  • Differentiate the wheel encoder readings to get the wheel velocity

  • Perform the controller math based on sensor information

  • Output next command to the motors


While the PI certainly has more horse power than the Lego NXT brick, I'm not sure how much tweaking to the Linux kernel would be needed to meet these requirements! Also, inconsistent loop times will certainly hurt your performance or prevent the segway from balancing. In any case, I'm also excited about the possibilities!

Posts: 8
Joined: Mon Nov 21, 2011 1:04 am
by pygmy_giant » Thu May 10, 2012 8:48 pm
Those are impressive looking lego machines – wish I had a job that enabled me to publicly admit to playing with lego in adult company without feeling embarrased. My official excuse for getting a pi is that I'm trying to interest my son in robotics, but to be honest, I'm hoping he'll loose interest so I can build it all myself – kidding.

Your experience is invaluable as I now know to aim for an update speed of 10ms or better. My Pi's due in 18 days time and I anticipate experimenting with a breadboard wires, sensors, modules, motors and code to attain that 10ms response time before starting assembly.

Part of my brain can't help wondering whether a 3 axis magnetometer could be used for spacial orientation in place / alongside a gyro – I note that you don't mention an accelerometer in your lego bots.

This link is not strictly related but makes me laugh: http://laughingsquid.com/sandf.....feet-high/
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by maverick7170 » Sat May 12, 2012 3:44 am
It's always a good day at work when getting paid to play with legos!

I don't have any personal experience with a magnetometer but a combined gyro + accelerometer would definately be better than the gyroscope by itself. Having both of those sensors allow you to do some math tricks (filtering) for better sensor data. Using the gyroscope by itself tends to drift overtime which the students had to keep in mind.

Thanks!
Posts: 8
Joined: Mon Nov 21, 2011 1:04 am
by pygmy_giant » Sun May 13, 2012 7:50 pm
Ahh- filtering... if you could point me to some formulas I would be grateful.

I wonder if magnetometer data could also be used as an additional reference point to factor out drift - useful for navigation regardless.

I read somewhere that its also good to put the accelerometer between the axles to reduce/remove 'data contamination' from linear acceleration caused by the sensor describing a wide arc.

My little boy is 8 in June so I will be taking him to legoland in manchester - I will be interested to see if they have a mindstorms section - his cousin of a similar age is saving up for a mindstorms set - it aint cheap - think I'll stick with the Pi.

I note from another post that the I2C kernal functionality is now a reality and expect it to be widely available soon.

I have seen an affordable I2C utlrasonic sensor module and the I2C motor driver board I like can handle 1 servo as well as 2 DC motors for the wheels. I thought I could combine the ultrasonic sensor and servo to make a sonar for mapping!

The largest banana skin would now seem to be keeping the sonar module level to get accurate data.
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Mon May 14, 2012 7:18 am
Or another engineering challenge would be to make the sonar useable in both horizontal or balancing / vertical mode.
User avatar
Posts: 876
Joined: Mon Mar 05, 2012 3:26 pm
Location: London
by pygmy_giant » Tue May 15, 2012 10:56 pm
Yes - I may be forced to modify my ambitions :¬/

Thinkning maybe some kind of pivoting 'head' with rotating ultrasonic sensor ...?

Guess that's a long way off yet ... still soldering up the battery pack and waiting for my Pi ...

I have been looking at these (ebay) parts for motor control:

200706254077 290692240368 110676648622

... and these for sensor input:

70787530954 (for encoders on wheels) 220925078648 150723212509 260770948278 290703664795

... and this for razzle dazzle:

180845707601 220917800095 / 170834744705
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by pygmy_giant » Thu May 24, 2012 1:12 pm
My Pi should be arriving in a week.

I2C drivers are now a reality with real time bare metal equivelants on the way....
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by pygmy_giant » Fri May 25, 2012 10:18 pm
Note to self - buy one of these: http://www.web4robot.com/files/I2C_FLEXEL.pdf
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Sun May 27, 2012 8:48 am
That's a good find. 20 dollars and to post to the UK is only 5 dollars. Seems to have everything you would need for any small robot... Built in motor control, 12 bit ADC... There might be a bit of fiddling required to get i2c working with the pi. viewtopic.php?f=45&t=2129
User avatar
Posts: 876
Joined: Mon Mar 05, 2012 3:26 pm
Location: London
by pygmy_giant » Sun May 27, 2012 2:17 pm
Ssshh... don't tell everyone - there might not be any left for the rest of us!

Any hoo - have been wondering about speech - would be cute if the bot could talk - there are a number of open source speech libraries for c++ that work on linux that could be a giggle: http://www.cstr.ed.ac.uk/projects/festival/

Buss by name bus by nature - bet he's sick of that joke...
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Sun May 27, 2012 2:39 pm
And to go with the speech synthesis, commands driven by voice recognition. :D
User avatar
Posts: 876
Joined: Mon Mar 05, 2012 3:26 pm
Location: London
by pygmy_giant » Sun May 27, 2012 2:48 pm
http://freespeech.sourceforge.net/ - good find.

is there an open source thinking module to go in between?

Seriously - thought I could use:

Wheel encoders + magnetometer + ultrasonic ranger + sweeping servo/stepper to map environment

and use:

microphones / sound intensity detector modules / IR movement sensors to locate humans.

and use:

speech recognition / synthesizer libraries to communicate.

Robot could request help from humans such as 'please tip me up onto two wheels' and 'please plug me in - my battery is low'.

Humans could request robot presence by saying 'over here!'

voice comands could include:

'Dance for me'

'What time is it?'

'What is the date?'

'What is the temperature?'

'What is the atmospheric pressure?'

'Do you think it will rain?'

... any other ideas anyone - every robot needs a reason to exist ...
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by pygmy_giant » Sun May 27, 2012 3:30 pm
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Sun May 27, 2012 5:34 pm
pygmy_giant wrote:

... any other ideas anyone - every robot needs a reason to exist ...

Perhaps but it might be dependent on size... If its a small robot its fairly limited but as you scale it up in size its usefulness increases. For example it can become a drinks host at a party...
User avatar
Posts: 876
Joined: Mon Mar 05, 2012 3:26 pm
Location: London
by Burngate » Mon May 28, 2012 3:59 pm
morphy_richards wrote:
pygmy_giant wrote:

... any other ideas anyone - every robot needs a reason to exist ...

Perhaps but it might be dependent on size... If its a small robot its fairly limited but as you scale it up in size its usefulness increases. For example it can become a drinks host at a party...

... and a bit larger, you could go for a Borg Hive
Wyszkowski's Second Law: Anything can be made to work if you fiddle with it long enough.
Brain surgery is easier than psychoanalysis
User avatar
Posts: 2931
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
by pygmy_giant » Mon May 28, 2012 11:18 pm
Hmm....

Not sure that serving drinks should be the teritory of 'labour saving devices' - perhaps we as a species should spend more time serving each other rather than finding excuses not to do so.

Although I appreciate the fact that 'the borg' don't wear lycra, I cant think of anything else in their favour.

Think I'll just keep my robot building as a private hobby and curio for my son to enjoy.
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Tue May 29, 2012 7:49 am
Perhaps you could make it into an explorer bot? On 4 wheels it could explore rough terrain and on 2 wheels it could explore halls in your house etc.

There are some really interesting algorithms and systems for developing maps of environments for robots that would make a good project to work on and explore programming and system design with a young 'un once you've got a suitable robot to play with.

(edit - Have a look at SLAM, or Simultaneous Localization And Mapping)
User avatar
Posts: 876
Joined: Mon Mar 05, 2012 3:26 pm
Location: London
by Ravenous » Tue May 29, 2012 8:04 am
The idea of a two-wheeled robot serving drinks is a bit worrying. (There was a comment earlier that a balancing robot isn't critical, but it is for red wine on a cream carpet.)

Even worse if the robot is drinking too.
Posts: 1605
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK
by pygmy_giant » Fri Jun 01, 2012 12:15 am
Yes - I've heard of bars with rolerskating waitresses but I wouldn't like that at home.

At the risk of sounding pretentious, there are some quite deep philosophical questions relating to what a robot is actually for...?

Dishwashers wash dishes, vacuum cleaners suck up dirt, but what should a robot do?

Even dedicated robots like those in car plants which build cars can be re-programmed to build a variety of models, so adaptability alongside obedience would be seem to be at least two defining features.

In popular culture robots often embody the paradox of machines mimicing humans, which by definition they never do perfectly. Robots are often used to pose the question of what it means to be human and what behaviour defines humans and is desirable in them. On an abstract level Robots can be a mirror and a way of defining what an ideal human should be like - tirelessly serving without error... or not - sinister, ruthless, destructive...

The child in me would like to see my robot mimic human behaviour to a degree so I think I will attempt balancing and voice synthesis and perhaps recognition - achievable if a little tricky. The adult in me would the robot to be aware of its surroundings and other beings and to make decisions.

I would therefore like to attempt some mapping via sonar (stepper motor + ultrasonic ranger) and wheel encoders and magnetometer. I would like the robot to be able to diferentiate between its environment and life so I may incorporate PIR and sound detection sensors.

But that said what should it do? I guess it could be entertaining - I spotted an I2C fm radio module on ebay so I guess it could play music and mp3s and maybe even dance(!)

If I ever get it built I guess it could seek out humans and offer to play them music and maybe do a little dance - entertaining at least.

If I ever get voice recognition sorted out, I guess it need only understand 'yes' and 'no' and numbers like those annoying automated telephone interfaces in order to allow humans to select music via a 20 questions sort of interface.

Perhaps thats what I'll do....

... got some bits and bobs ready (stepper motor, optical sensors, etc) and my Pi arrives tomorrow ...

... think sonar will be my first milestone as I see no point in building a robot that is not aware of its surroundings.

... as a long term goal, the raisen d'etre could be:

Explore, map out environment, search for life and offer entertainment via synthesized voice (music/dance).

Regarding the balancing bit it could travel in 3 wheel mode by default and ask to be tipped up onto 2 wheels if dancing is required by an identified human.

Once the enviroment is mapped it could plot a patrol route to look for humans taking into consideration where they are most commonly found at certain times of day.

As good a reason as any to exist I suppose.
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Fri Jun 01, 2012 7:43 am
I think the idea of a robotic wandering minstrel is ... I'm not poetic enough to say what I think it is.
If we can work out some kind if do-able learning / AI system, then perhaps your robot could, in addition to entertaining humans, pick up nuances etc. that it could weave into its own songs and stories?

I wonder if it would be possible to use something like ALICE (source) for grammar and sentence construction.
I wonder if there is some similar set of rules for creation of simple melodies :?
User avatar
Posts: 876
Joined: Mon Mar 05, 2012 3:26 pm
Location: London
by pygmy_giant » Fri Jun 01, 2012 10:34 pm
Think I've made a new friend:

Human: tell me another joke
ALICE: Two vultures boarded a plane, each carrying two dead raccoons. The stewardess stops them and says "sorry sir, only one carrion per passenger.".
Human: would you like to hear my joke?
ALICE: Sure tell me about it.
Human: What did the budhist say to the pizza chef?
ALICE: Is this a joke? What did the budhist say?
Human:'Make me one with everything!'
ALICE: It is better to be silent and be thought a fool, than to open your mouth and remove all doubt.
Human: are you a comedian?
ALICE: Not professionally.
Human: whats orange and sounds like a parrot?
ALICE: Interesting question.
Human: a carrot!
ALICE: Be more specific.
Human: its a joke
ALICE: Oh I get it. Ha ha.
Human: whats orange and sounds like a parrot?
ALICE: I would do a search for it.
Human: you're not just a parroting me then
ALICE: Give me an example of a parroting you.
Human: Give me an example of a parroting you.
ALICE: For example, " Give me an example of a parroting you."?
Human: For example, " Give me an example of a parroting you."
ALICE: For example, " For example, " Give me an example of a parroting you.""?

Thought I better stop there.

Would be interesting combined with speech recognition and synthesis.
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by ctrlbreak » Sun Jun 03, 2012 11:31 am
I've been looking at using an ADXL345 to do this - it's a digital output on I2C or SPI. Here's a chinese made-up breakout board for one:

ebay item: 280889736626
Posts: 1
Joined: Sun Jun 03, 2012 11:30 am
by pygmy_giant » Sun Jun 03, 2012 2:02 pm
thanks for the tip - may order one.

My Pi came yesterday - got it working but am having a teething problems with Frank's I2C enabled boot files - I loose mouse control.
Ostendo ignarus addo scientia.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by beautifulsmall » Mon Jun 04, 2012 10:54 pm
I have made several balancing robots and the faster the loop speed the better the result. Using a Pic33 at 40MHz gave a 1000 loops/sec with gyro/accel / pid loops/ pwm update.
The Pic was good legs but the head was missing. I tried a beagleboard with camera and object recognition and this was almost a solution but the complexity lost me. The Rpi i hope is less complex and more suitable (and its BCM) who do have good data sheets .
the Beagle board took me a month to get as far as i am with the Rpi in 3 days , I2C,SPI,GPIO working in C (uart still to go), Thanks to the community.
I will still use the Pic33 as it has DMA for SPI, Uart and has a HW quadrature encoder but will pass all accel ,gyro and encoder data back to Rpi via uart for mapping which is really the tough nut, the pic will never have enough ram to align old/new map data or shape fit.
O :D ptomistic again.
http://www.youtube.com/watch?v=Kd2kJxBkPmk
Posts: 20
Joined: Mon Jun 04, 2012 9:57 pm
by beautifulsmall » Mon Jun 04, 2012 11:38 pm
ctrlbreak, if your using the ADXL345 i have some setup and read code here, the first 3 lines are the init, the read function is for the vertical calculation, the sensor was set at 45deg to the vertical to avoid divide by 0 errors (me novice) and use the linear region of the x,y ?or z sensor.
I have now moved onto the Bosch BMA180 which gives ~1/16 degree accuracy and works well but i have no price for it .
SPI1BUF = 0x310F; // 13 bit +- 16g write to set justify msb the data out to the SPI peripheral
SPI1BUF = 0x2C0D; // set datarate to 800hz BW 400HZ
SPI1BUF = 0x2D08; // write the data out to the SPI peripheral start conversions

int ADXL345_accel_read()
{
int accel_low,accel_high;
int accel_x,accel_y;
int accel_x_offset=10;
int accel_y_offset=3;
int result;
static int angle[4]={0,0,0,0,};

accel_low=spi_read(0x0200);
accel_high=spi_read(0x0300);
accel_x=((accel_high<<8)|(accel_low & 0x00FF));
accel_low=spi_read(0x0400);
accel_high=spi_read(0x0500);
accel_y=((accel_high<<8)|(accel_low & 0x00FF));
//ACCEL_LOW=READ_SPI_ACCEL(0x3600);
//ACCEL_HIGH=READ_SPI_ACCEL(0x3700);
//ACCEL_Z=((ACCEL_HIGH<<8)|(ACCEL_LOW & 0x00FF));

accel_x=(accel_x/8)-accel_x_offset; // ALIGN FOR 13 BIT IN WORD
accel_y=(accel_y/8)-accel_y_offset; // ALIGN FOR 13 BIT IN WORD
//scaling factors are 264 for both x and y so dont calc

//ATAN2 RETURNS RADIANS , *57.3 for degrees, +45 offset,x4 for max resolution


//****************** average ************
angle[3]=angle[2];
angle[2]=angle[1];
angle[1]=angle[0];
angle[0]=(((atan2(accel_y,accel_x))*57.3)+45)*4;
result=(angle[0]/2)+(angle[1]/4)+(angle[2]/8)+(angle[3]/8);


return (result);
}
Posts: 20
Joined: Mon Jun 04, 2012 9:57 pm