Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
#include <MotionCommand.h>
Inheritance diagram for MotionCommand:
For instructions on how to create:
To create a new type of motion, you'll want to subclass this. You don't need to do anything fancy, but just be sure to override the 3 abstract functions.
When an output is set to a value, that value is retained until it is set to a new value, even if the MotionCommand that set it is pruned or stops using the output. Outputs never "reset" to 0 or some other relatively arbitrary base value.
However, PID values will reset to the default values if pruned or not set since these values do have a base value which you will want to use 99% of the time.
Be aware that there is a delay between when you set a joint to a value and that actually is taken into account by the system - it's on the order of RobotInfo::FrameTime*RobotInfo::NumFrames (currently 8*4 = 32 ms, at most 2*8*4 = 64 ms) This is because the commands are double buffered. PIDs, on the other hand, seem to take effect more quickly. This un-synchronization can sometimes cause annoying jerkiness (mainly on startup, where there's a large difference between desired and target values.)
Here is the cycle of calls made by MotionManager to your command:
So, if you want to hold a joint at a value, each time your updateJointCmds() function is called, you should tell the MotionManager to keep the joint there (using one of MotionManager::setOutput()'s). If you do not set a joint after a call to updateJointCmds, the MotionManager will assume you are no longer using that joint and a lower priority MotionCommand may inherit it.
MotionCommands which generate events should use the inherited postEvent() instead of trying to access a global erouter - the inherited version will properly handle sending the events, trying to access a non-shared global like erouter could cause problems.
Don't store pointers in motion commands!
Since motion commands are in shared memory, and these shared memory regions can have different base pointers in each process, pointers will only be valid in the process from which they were assigned. In other processes, that address may point to something else, especially if it was pointing outside of the shared memory regions.
There are convoluted ways of getting around this. If needed, MotionManager could be modified to hand out shared memory regions upon request. Let's try to avoid this for now. Keep MotionCommands simple, without dynamic memory. Do more complicated stuff with behaviors, which only have to run in Main.
REGIMP
Definition at line 66 of file MotionCommand.h.
*** INHERITED: *** | |
MotionCommand () | |
Constructor: Defaults to kStdPriority and autoprune==true. | |
virtual | ~MotionCommand () |
Destructor. | |
virtual void | DoStart () |
called after this is added to MotionManager | |
virtual void | DoStop () |
called after this is removed from MotionManager | |
virtual bool | isActive () const |
returns true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand) | |
virtual bool | getAutoPrune () |
virtual void | setAutoPrune (bool ap) |
virtual bool | shouldPrune () |
whether this motion should be removed from its motion group automatically ( MotionCommand::autoprune && !isAlive()) | |
void | setQueue (EventTranslator::Queue_t *q) |
only called from MMCombo during process setup, allows MotionCommands to send events | |
double | interpolate (double a, double b, double x) |
this utility function will probably be of use to a lot of MotionCommand's | |
float | interpolate (float a, float b, float x) |
this utility function will probably be of use to a lot of MotionCommand's | |
void | interpolate (const OutputCmd &a, const OutputCmd &b, float x, OutputCmd &r) |
this utility function will probably be of use to a lot of MotionCommand's, see interpolate(double a,double b,double r) | |
Public Member Functions | |
*** ABSTRACT: *** (must be defined by subclasses) | |
virtual int | updateOutputs ()=0 |
is called once per update cycle, can do any processing you need to change your priorities or set output commands on the MotionManager | |
virtual int | isDirty ()=0 |
not used by MotionManager at the moment, but could be used to reduce recomputation, and you may find it useful | |
virtual int | isAlive ()=0 |
used to prune "dead" motions from the MotionManager | |
Static Protected Member Functions | |
void | postEvent (const EventBase &event) |
calls EventTranslator::enqueue directly (avoids needing erouter, which is a non-shared global, causes problems with context, grr, silly OS) | |
Protected Attributes | |
int | autoprune |
default true, autoprune setting, if this is true and isAlive() returns false, MotionManager will attempt to remove the MC automatically | |
bool | started |
true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand) | |
Static Protected Attributes | |
EventTranslator::Queue_t * | queue = NULL |
queue to store outgoing events in - call the MotionCommand::postEvent |
|
Constructor: Defaults to kStdPriority and autoprune==true.
Definition at line 96 of file MotionCommand.h. |
|
Destructor.
Definition at line 98 of file MotionCommand.h. |
|
called after this is added to MotionManager
Reimplemented in WalkMC. Definition at line 101 of file MotionCommand.h. References started. |
|
called after this is removed from MotionManager
Reimplemented in WalkMC. Definition at line 104 of file MotionCommand.h. References started. |
|
Definition at line 110 of file MotionCommand.h. References autoprune. |
|
this utility function will probably be of use to a lot of MotionCommand's, see interpolate(double a,double b,double r) interpolates both value and weights of JointCmd's
Definition at line 149 of file MotionCommand.h. References interpolate(), OutputCmd::set(), OutputCmd::value, and OutputCmd::weight. |
|
this utility function will probably be of use to a lot of MotionCommand's Does a weighted average of a and b, favoring b by x percent (so x==0 results in a, x==1 results in b)
Definition at line 140 of file MotionCommand.h. |
|
this utility function will probably be of use to a lot of MotionCommand's Does a weighted average of a and b, favoring b by x percent (so x==0 results in a, x==1 results in b)
Definition at line 130 of file MotionCommand.h. |
|
returns true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand)
Definition at line 107 of file MotionCommand.h. References started. |
|
used to prune "dead" motions from the MotionManager note that a motion could be "paused" or inactive and therefore not dirty, but still alive, biding its time to "strike" ;)
Implemented in HeadPointerMC, LedMC, MotionSequence, PIDMC, PostureMC, RemoteControllerMC, TailWagMC, and WalkMC. |
|
not used by MotionManager at the moment, but could be used to reduce recomputation, and you may find it useful
Implemented in HeadPointerMC, LedMC, MotionSequence, PIDMC, PostureMC, RemoteControllerMC, TailWagMC, and WalkMC. |
|
calls EventTranslator::enqueue directly (avoids needing erouter, which is a non-shared global, causes problems with context, grr, silly OS)
Definition at line 155 of file MotionCommand.h. References EventTranslator::enqueue(), and queue. |
|
Definition at line 113 of file MotionCommand.h. References autoprune. |
|
only called from MMCombo during process setup, allows MotionCommands to send events
Definition at line 120 of file MotionCommand.h. References queue. |
|
whether this motion should be removed from its motion group automatically ( MotionCommand::autoprune && !isAlive())
Definition at line 117 of file MotionCommand.h. |
|
is called once per update cycle, can do any processing you need to change your priorities or set output commands on the MotionManager
Implemented in DynamicMotionSequence, EmergencyStopMC, HeadPointerMC, LedMC, MotionSequence, MotionSequenceMC< MAXMOVE >, PIDMC, PostureMC, RemoteControllerMC, TailWagMC, and WalkMC. |
|
default true, autoprune setting, if this is true and isAlive() returns false, MotionManager will attempt to remove the MC automatically
Definition at line 159 of file MotionCommand.h. |
|
queue to store outgoing events in - call the MotionCommand::postEvent
Definition at line 3 of file MotionCommand.cc. |
|
true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand)
Definition at line 160 of file MotionCommand.h. |
Tekkotsu v1.4 |
Generated Sat Jul 19 00:09:03 2003 by Doxygen 1.3.2 |