WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

GaitRunner.h

Allows you to embed the gait produced by Gait Designer into your program so that it can be used without the Gait Designer application.
You will need to make the following changes to the code example shown in :-
#include the gait file produced by Gait Designer using the File | Export menu option.
Looking at this file you will that it defines a constant (G8_ANIM_xxxx) for each animation in the gait and these number are used when you want to play a gait. Equally it defines a constant (G8_LIMB_xxxx) for each limb/joint/servo in your model.
Replace this line of code:
GAIT_DESIGNER gait = MAKE_GAIT_DESIGNER(all, UART1, (BAUD_RATE)115200);
with the following:
G8_RUNNER gait = MAKE_G8_RUNNER(all,animations);
The last parameter is the list of animations in the H file produced from Gait Designer.
In appInitHardware replace this line of code:
gaitDesignerInit(&gait);
with the following:
gaitRunnerInit(&gait);
In appControl replace this line of code:
gaitDesignerProcess(&gait);
with the following:
gaitRunnerProcess(&gait);
Alternatively you may choose to use the scheduler to call gaitRunnerProcess at regular intervals via interrupts.
The only missing code is the use of gaitRunnerPlay (described later) to start playing a given animation.

 

Function

 


G8_RUNNER MAKE_G8_RUNNER

Create a standalone gait runner.
The first parameter is the ACTUATOR_LIST containing all of the servos you want to control.
The second parameter is the list of possible animations in the gait file exported from Gait Designer. This is called 'animations' - unless you have modified the file by hand.

gaitRunnerInit(G8_RUNNER* runner)

Initialise the G8_RUNNER object.
This is normally called in appInitHardware.

boolean gaitRunnerProcess(G8_RUNNER* runner)

Tell the servos to move to their next position.
You can call this from your main loop (appControl) or you may use the scheduler to call it at regular intervals in the background. Note that since servos are only sent a pulse every 20ms then there is no point in using the scheduler to call this function more frequently than every 20ms.
The function will return TRUE if an animation is still playing or FALSE if it has stopped.

gaitRunnerPlay(G8_RUNNER* runner, uint8_t animation, int16_t loopSpeed, DRIVE_SPEED speed, int16_t repeatCount

Start playing a given animation.
The 'animation' parameter selects the animation you want to play. These are defined at the top of the file created by Gait Designer and all start with G8_ANIM_.
The 'loopSpeed' sets the overall speed of the animation. It must be a value greater than 'speed' and up to 32,767.
The 'speed' parameter is the animation playback speed and can be between -127 and 127. A negative speed will playback the animation in reverse. The higher the value then the faster the animation will play back. A value of zero will cause the animation to freeze at its current position. The speed can be changed at any time.
The 'repeatCount' parameter specifies how many loops of the animation you want to play. A value of zero will cause the animation to play continuously until you tell it to stop. Note that if the 'speed' is negative then the repeat count should also be negative.
The precise relationship between 'loopSpeed' and 'speed' is that one loop of the animation will take:
((65.536 * loopSpeed) / speed) milliseconds
A loopSpeed of 32767 and a speed of 1 will mean that a single loop of the animation will take about 35.8 minutes !!
A loopSpeed of 5000 will mean you can vary the loop time from 327 seconds (speed=1) to 2.58 seconds (speed=127).

boolean gaitRunnerIsPlaying(const G8_RUNNER* runner)

Return TRUE if an animation is still playing or FALSE if it has stopped.
NB if you set the animation to play at a speed of zero then the animation is still playing - but the servos will be frozen at their current position.

gaitRunnerStop(G8_RUNNER* runner)

Force the current animation to stop once it has reached the last frame of the animation.

int16_t gaitRunnerRepeatCount(const G8_RUNNER* runner)

Returns the number of loops remaining before the animation ends.
A return value of zero means that the animation will keep playing until you call gaitRunnerStop.

gaitRunnerSetSpeed(G8_RUNNER* runner, DRIVE_SPEED speed )

Sets the current playback speed of the animation. See gaitRunnerPlay for a description

DRIVE_SPEED gaitRunnerGetSpeed(const G8_RUNNER* runner )

Returns the current playback speed for the animation.

gaitRunnerSetDelta(G8_RUNNER* runner, uint8_t limbNumber, DRIVE_SPEED speed )

Allows you to modify the gait in real time.
The second parameter is the limb number. These are defined in the file exported by Gait Designer and all start with G8_LIMB_.
The third parameter allows you to adjust the value for this limb. The default value is zero.
This command can be used, for example, to take the values from an accelerometer and adjust the value of, say, the ankles of our walking robot so that if it is on a slope then the ankles move to compensate.
If a gait is currently playing then this new value will be picked up automatically when you next call gaitRunnerProcess. If no gait is running and the robot is just standing still then the servos are updated immediately.

DRIVE_SPEED gaitRunnerGetDelta(const G8_RUNNER* runner, uint8_t limbNumber)

Returns the last value set by

Valid XHTML 1.0 Transitional