======================================================================= Subject: early version of Matlab GaitBuilder To: Arthur Joseph McClung , Joel D Weingarten , Uluc Saranli Cc: Al Rizzi , Dan Koditschek Date: Wed, 07 Jul 2004 02:37:45 -0400 X-Status: [ warning -- lengthy tutorial below. This e-mail is sent as a first try at "documentation", preceding a proper description on the phone and on paper ] Hi Trey, It sounds like you've given a go at the ClimbingGait.nb Mathematica notebook that Joel and I worked on the other week. After working with that notebook over the week that Joel was here, I realized that we had it all wrong for generating complicated climbing gaits. It was difficult to add multiple strokes to our gaits (such as adding pauses for the metachronal and one-off gaits), and it was extremely difficult to do things like making our attachment be two or more piecewise linear sections, rather than one. So, I set out to make a set of tools in Matlab, rather than Mathematica, that would allow us to have a very large expressiveness for writing gaits. Even though I've not completed these tools yet, I wanted to give you an early warning of their existence, since I hope you'll end up using them, after you've exhausted the Mathematica notebook for its usefulness. The main goal of these tools is the separate the definition of how many strokes can be defined for a gait from the actual generation of the gait. Things like that were extremely difficult in the Mathematica notebook. For example, you should ideally be able to make as many strokes as you want, and just string them together to produce a gait. Since the metachronal gait needs extra pauses it took writing a whole new section of the Mathematica notebook to get it to work. That isn't the case with these tools. If you do a 'cvs update -d' and take a look in RoboDevel/RiSE/Tools/Matlab/GaitBuilder you'll find a large set of functions that I've made over the last couple weeks. I've done my best to document the functions, so always do "help GBxxxx" to see the help info. I've gotten this library to the point where I can take the same parameters used in ClimbingGait.nb and generate an identical RHexLib rc file as what Mathematica produces, but only for the tripod climbing gait so far. Metachronal and One-off are still coming, but should be really easy, loads easier than they were in Mathematica. This is done in the script file "climbing.m". Take a look at it, now that you've hopefully come to understand what the Mathematica notebook produces. So, how are gaits produced using GaitBuilder? Let's just walk through "climbing.m". The first thing to note, and this is also described by type "help GBsection", is the difference between absolute and relative positions when defining sections of a gait. An absolute position means that you want the crank/wing to be at the position [X,Y] at the time T. A relative position means to move the crank/wing by [X,Y] amounts over the time T. GBsection can take either absolute or relative positions, respectively by calling: GBsection([X,Y,T]',1) and GBsection([X,Y,T]'); So, in "climbing.m", we first make an absolute position, the starting position for our gait, right before attachment. preatt1 = GBsection([0,AttBetaOffset,AttWingOffset]',1); This function returns a specially constructed Matlab struct that I've designed for this library. The '1' at the end of the function call tells it we're doing absolute positions. So, at time 0, we want to be positioned at AttBetaOffset and AttWingOffset. Next, we want to define an attachment stroke. att = GBsection([AttDF*P,AttBetaSweep,AttWingSweep]'); Relative positions are assumed, so this gait section means that over time AttDF*P (the time length of the attachment stroke), we want to "sweep" the crank and wing by the amounts specified. Note that the exact time is never specified -- only relative time. Next we do similar things for our stance and detachment strokes. sta = GBsection([StaDF*P,StaBetaSweep,StaWingSweep]'); det = GBsection([DetDF*P,DetBetaSweep,DetWingSweep]'); Finally, rather than defining a section for the flight phase, we simply define an ending point for our gait, since the flight phase is defined implicitly from the other parameters. endfli1 = GBsection([P,AttBetaOffset-1,AttWingOffset]',1); At the end of one period, at time P, we should be at the absolute position AttBetaOffset-1 and AttWingOffset. This is the exact same position as "preatt1", except I've subtracted one from the crank beta, meaning that we've moved one full revolution in the negative beta direction. So, I've now defined a gait, how do I piece it together? tripod1 = GBconcat(preatt1,att,sta,det,endfli1); This function does exactly what it looks like it does. It concatenatives individual sections of a gait into one larger section. One cool thing is that you can call GBconcat on gait sections that you've already concatenated, not just sections outputted from GBsection. So, what's so special about the gaits I've defined here? Well, foremost, the times are relative. Because of this, we can generate our second tripod very easily, simple by defining new start and end times, at times P/2 and P*3/2, rather than 0 and P. Now with "preatt2" and "endfli2", we can concat them together to get our second tripod: tripod2 = GBconcat(preatt2,att,sta,det,endfli2); This is the exact same gait as "tripod1", but it starts and ends at different times. Note that I've reused the attachment, stance, and detachment sections of the gait. [ this next section isn't actually in "climbing.m" -- I'm just explaining it as it's one cool application of this library ] The next cool thing is that, for instance, I can easily split attachment into two sections, without drastically changing the file, like I would have had to in the Mathematica notebook. As an example, let's have our foot move the crank evenly through the whole attachment, but only move the wing in the first third of attachment. We now have a two-section attachment "stroke". att1 = GBsection([AttDF*P*1/3,AttBetaSweep*1/3,AttWingSweep]'); att2 = GBsection([AttDF*P*2/3,AttBetaSweep*2/3,0]'); att = GBconcat(att1,att2); We've now replaced our previous one-section attachment with a two-section version. We can simply call the same GBconcat that we did above, even though "att" is now two sections rather than one: tripod1 = GBconcat(preatt1,att,sta,det,endfli1); tripod2 = GBconcat(preatt2,att,sta,det,endfli2); [ OK, back to stuff that's actually in "climbing.m" ] After you've pieced together a gait using GBsection and GBconcat, you have to compile it. GBcompile will take our relative and absolute positions, and calculate the full list of absolute positions, as needed for a RHexLib rc file. Finally, GBexport is a function that writes this gait out to an rc file, ready for use on the robot. Take a look at "climbing.m" for examples. Lastly some random notes ... I've got a fair bit of error checking in the library so far, so it should keep you from doing anything totally wrong, but I haven't been able to test much. I've also got a gait "plotter" underway, and should have it done soon, which will be a huge boon for generating gaits. Finally, I am planning on adding a simple animation function, which will show you the movement of all six limbs (or just one if you like) at the same time, to give you an idea of what the gait will do, before you put it in simulation or on the robot. Obviously, this is all one big work-in-progress. I just wanted to get word of it out to you, as it's already a lot easier to use than the Mathematica notebook you've been looking at, and will probably be more useful for the kinds of tests you'll be doing with the Stanford Test Track. Good Luck! Let me know if there is anything glaringly confusing right now. Otherwise, I'll keep you updated as I flesh things out here. Clark ======================================================================= Subject: Re: early version of Matlab GaitBuilder To: Arthur Joseph McClung Cc: Joel D Weingarten , Uluc Saranli , Al Rizzi , Dan Koditschek Date: Thu, 08 Jul 2004 16:19:23 -0400 X-Status: Some good progress has been made on the GaitBuilder tools, notably in getting plots to work. Go into the GaitBuilder directory, RoboDevel/RiSE/Tools/Matlab/GaitBuilder, and try running the scripts now. If you run 'climbing' or 'running', you'll see a correct plot of all the various sections of the gait. 'running' shows you a two-stroke sample running gait. 'climbing' will show you the four stroke climbing gait (and actually, the exact same gait that was used in the experiments I conducted yesterday). Now, here's the really cool part. After you run 'running' or 'climbing', there is a gait stored in a Matlab struct 'gait1'. Now do: >> GBanimate(gait1) $ play at full speed -- or, if you want it to be played slowed down >> GBanimate(gait1,3) % play at 1/3 speed This will draw the gait curve, but then animate a position "dot" moving around the curve. Oh, and one other note on the plotting functionality. There are multiple sections to a gait plot. First is a faint yellow line, outlining the whole curve. Second are black circles at all of the "nodes" of the gait, the points at which our linear piecewise sections are defined. Finally, we have 100 dots positioned throughout the gait, and colored depending upon the which gait section they belong to, so you can approximately see how the leg moves during a gait, before you even animate it. In order for the sections to have different names and colors, you need to name the sections before you GBconcat them, using GBname, as I do in climbing: att = GBname(att,'Attachment') sta = GBname(sta,'Stance') det = GBname(det,'Detachment') Now, when you GBconcat these sections, the total gait will retain knowledge of the sections. Thus, when you run GBplot, it can identify the various sections of the gait. Still to-be-done future enhancements include adding a GBplot3 function, so you can see wing movement in addition to beta movement (as well as the corresponding GBanimate3). This will probably be done this evening. As well, I am going to add the ability to plot and animate multiple gaits side-by-side, so you can see them and watch phase relationships, etc. I will most likely do this on wednesday, after I return from a short vacation. Good luck! I will probably be out of e-mail contact starting tomorrow, so get your questions to me today if you can! (I'm heading off to do some climbing of my own!) -- ===================================== Clark Haynes, gch@cs.cmu.edu http://www.cs.cmu.edu/~gch/ 412-268-5860 (W), 412-608-0438 (Cell) Ph.D. Student, The Robotics Institute Carnegie Mellon University ===================================== ======================================================================= Subject: Re: early version of Matlab GaitBuilder To: Arthur Joseph McClung Cc: Joel D Weingarten , Uluc Saranli Date: Thu, 08 Jul 2004 18:43:50 -0400 X-Status: OK, GBplot3.m and GBanimate3.m have been added, and they work really well. We now have nice 3D plots and animations of single-leg gaits. Multi-leg plots and animations will come early next week, as I doubt that I'll have time before I leave tomorrow. Try it out: >> climbing >> GBanimate3(gait1) You can use the standard matlab plot rotation tool to view from different angles during the animation. Let me know if you have any problems. -- G. Clark Haynes =======================================================================