Who wants to help me balance a segway? ( fun, I hope )

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
So, I've spent the last few weeks writing a threaded control system for my simulation framework, in the approach OSC used for his ThreadedNewton demo, many moons ago. It works beautifully. Having done that, I wrote python bindings and a system whereby the control code for a device ( robot, vehicle, etc ) can be written in python and runs on a separate thread. Again, it seems to work beautifully.

So I figured, I wrote all these dumb, simple tests and they passed. Why not stress the system a little and write something interesting. So I built a simulated segway, and wrote python code to keep it balanced.

[Image: Segway.png]

My balance algorithm works, but is ungainly. There are greater complexities to this system than my crude algorithm can handle. Basically, the segway balances and turns, goes forwards and backwards. But, once it starts moving in any direction, it keeps moving in that direction until you ask it to reverse. Plus, it can sometimes wobble forward and backward in a cycle with a distance of about a meter, sometimes.

There's got to be a more robust control system, and I'm hoping somebody here can help me out a little. This is one of those situations where it's not really important that this is perfect, after all, I've verified my threaded python control system works. But, I'm unhappy leaving it with an unfinished balance algorithm. Also, I'm putting off implementing Rodney Brook's Subsumption Architecture in python. I wrote an implementation a few years back in C++ and it was ugly... I'm excited about writing a new one in python, but I don't want to start hacking until I've thought through a solid design that takes advantage of what python has to offer. So, while I'm navel-gazing, I'd like to make this segway balance like a champ! Cool

http://zakariya.net/shamyl/etc/Segway.zip

The zip file contains the app and a readme, which explains the python API and other details.

Unfortunately, the app is intel only ( I've never once successfully cross compiled ODE ), and requires a real GPU. No GMA950. Maybe the new 3100 will work, I have no idea.

If anybody is interested in lending a hand, please do! Rasp
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #2
I think I broke it. Rasp

http://www.maximile.net/Spinny.mp4

Anyway, I don't think I'll be able to help. But this guy has released the code for his IRL Segway-style unicycle. Maybe there are some nuggets in there.

http://www.tlb.org/eunicycle.html

It's a really cool interface, btw. Nice to finally play with it after seeing it in so many screenshots.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
Actually, my algorithm is derived from another segway hacker who referenced tlb.org as one of his inspirations. Rasp

BTW, the spinning is fun, so long as you don't have the "Chase Camera" enabled. If you do, and you're running full screen ( "Command-F" ) try not to vomit.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #4
I may be able to help, being a mechatronics person, contact me on AIM if you got any particular questions.

As you are using a discrete timestep simulation, that may severely affect the control algorithm, to the point where it completes break down in the simulation but works IRL.

But more importantly, the control algorithm you use seems to be rather too simple; the approach of tuning the controller via those 3 Konstants is a bit random/unscientific for such a system. Complete hogwash, some might say Wink
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #5
Oh, I know it's hogwash ( nice word ) but it got me as far as I got. They're configurable easily enough -- you can add more constants and change their ranges from a config file. It's all documented.

The trouble is, I'm not a mechatronics person ( again, nice word ). I've done some simple stuff with behavioral networks to make ambulatory algorithms, and they worked. But this balancing system is different, it's more math, less behavioral. Which is too bad since I have no education in such systems...
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #6
hmm, could you post the source or a universal binary?

I'm still in the dark ages over here.

Also, how do you integrate the python? Do you load an interpreter at runtime, then call the python at choice moments in the program?

[edit]Ahh, I see. Oh well, I think I can get my hands on an intel machine on monday.

Did anyone tell you your framework is sexy? Because it is.[/edit]

It's not magic, it's Ruby.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #7
It needs a texture-mapped Woz... Sneaky
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #8
Nayr Wrote:hmm, could you post the source or a universal binary?

I'm still in the dark ages over here.

If I can figure out how to cross compile ODE for PPC, then yeah. But ODE's build system is kind of angry, I never got it working. Try as I might, the output was always for the local arch.

Nayr Wrote:Also, how do you integrate the python? Do you load an interpreter at runtime, then call the python at choice moments in the program?

I use boost.python, and yeah, I embed the python interpreter. It works like magic! Plus, it's all running on a separate thread, very smoothly. OSC's ThreadedNewton demo opened my eyes for how to do smooth threading with a minimum of mutex locking. Bascially, I have a graph of proxy objects mirroring simulation state, and those objects are very trivial to expose to python.

Nayr Wrote:Did anyone tell you your framework is sexy? Because it is.[/edit]

Thank you. I know there's a strong anti-c++ feeling around here, but I think it can be great in capable hands. I'm just trying to learn to become one of the capable people, step by step.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
To get output for PPC, you have to pass -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4 to all compilation and linking commands. Generally, that's not difficult to organize.

The ThreadedNewton demo is completely lock-free Wink
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #10
OneSadCookie Wrote:To get output for PPC, you have to pass -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4 to all compilation and linking commands. Generally, that's not difficult to organize.

My configure kung-foo is weak. I'll give it a stab.


OneSadCookie Wrote:The ThreadedNewton demo is completely lock-free Wink

True! But I read your caveat about atomic compare and swap where you said it might be interrupted on multiproc machines. So, well, I just skipped the CAS and used a simple mutex lock on a pointer swap. So, I do use one tiny brief mutex lock.

But anyway, you opened my eyes! My implementation, btw, is pretty cool. Two way synch, using some boost.bind trickery to automagically sync object state to an internal representation, which is published to the other side. Works like crazy, and fast, to boot.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
Yes, CAS can be interrupted, but that's what the do...while loop is for, it's unlikely to be interrupted twice Wink

If ODE is configure/make/install, you might find http://onesadcookie.com/svn/repos/Third-Party interesting (it builds C/M/I programs for all the architectures you have SDKs for)
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #12
OneSadCookie Wrote:Yes, CAS can be interrupted, but that's what the do...while loop is for, it's unlikely to be interrupted twice Wink

I'm embarrassed to admit, I found your source code a little opaque Rasp
My implementation was based on your excellent description of the idea...

OneSadCookie Wrote:If ODE is configure/make/install, you might find http://onesadcookie.com/svn/repos/Third-Party interesting (it builds C/M/I programs for all the architectures you have SDKs for)

That looks wonderful!
Quote this message in a reply
Member
Posts: 78
Joined: 2004.06
Post: #13
Nothing to do with the topic, but is there any good reasons you're using degrees/dps instead of radians? I am a nOOb, but wouldn't this make your math generally simpler (less operations)? Blink

When in doubt ... read the Read Me
10.5.6 | MacBook Pro 2.5x2 | 4 GB RAM | GeForce 8600M GT
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #14
Continuing the OT Radians/Degrees: I've never found working with Radians to generally simplify math. In fact, I've found it to introduce logical errors in algorithms because I don't think in terms of 2 times 3.14159, or multiples and divisions thereof, instead I think in terms of 360 and its cardinal divisions and multiples.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #15
Well, that's your brain that's broken Rasp

Anyway, you shouldn't be thinking in terms of 3.14159, but in terms of π being a half-circle, 2π being a full circle, π/2 being a quarter circle, etc. Much more intuitive to think of 2π/5 being a 5th of a circle than to remember 72º...
Quote this message in a reply
Post Reply