Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

The abstract base class for motions, provides common interface. All motions should inherit from this. More...

#include <MotionCommand.h>

Inheritance diagram for MotionCommand:

Detailed Description

The abstract base class for motions, provides common interface. All motions should inherit from this.

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, updateOutputs(), isAlive(), and isDirty().

There is a quick-start boilerplate included in the distribution: project/templates/motioncommand.h:

When an output is set to a value, that output is held at that value 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 if all the MotionCommands are removed.

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 FrameTime*NumFrames (currently 8*4 = 32 ms, so worse case 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 a bit of 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:

  1. shouldPrune() (by default, this will return !isAlive() iff autoprune==true)
  2. updateOutputs() (assuming the MC wasn't pruned after the previous step)

So, if you want to hold a joint at a value, each time your updateOutputs 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 updateOutputs, 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 MotionCommand::postEvent() instead of trying to access a global erouter - the inherited version will properly handle sending the events regardless of the current process context, but trying to access a non-shared global like erouter could cause problems otherwise.

Warning
Be careful what you call in MotionManager
Some functions are marked MotionCommand-safe - this is another issue due to our "fake" fork. In short, when a function is called on a MotionCommand, it uses the context of whatever process created it, not the process that actually made the function call. Thus, when Motion calls updateOutputs(), calls that the MotionCommand makes are indistinguishable from concurrent calls from Main. This can cause deadlock if a function is called which locks the MotionManager. To get around this, we need to pass the 'this' parameter on functions that require a lock, namely MotionManager::setOutputs(). This allows the MotionManager to figure out that it's the same MotionCommand it previously called updateOutputs() on, and thus avoid trying to lock itself again.
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 worry about running in Main.

Definition at line 92 of file MotionCommand.h.

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 More...
 
virtual int isDirty ()=0
 not used by MotionManager at the moment, but could be used to reduce recomputation, and you may find it useful More...
 
virtual int isAlive ()=0
 used to prune "dead" motions from the MotionManager More...
 
- Public Member Functions inherited from MotionManagerMsg
 MotionManagerMsg ()
 constructor More...
 
virtual ~MotionManagerMsg ()
 virtual destructor More...
 
MC_ID getID () const
 Accessor for the id number, set by MotionManager::addMotion() More...
 

Protected Member Functions

void postEvent (const EventBase &event)
 calls EventTranslator::trapEvent() directly (avoids needing erouter, which is a non-shared global, causes problems with context, grr, silly OS) More...
 

Protected Attributes

EventTranslatorqueue
 send events using this, instead of posting to the erouter More...
 
int autoprune
 default true, autoprune setting, if this is true and isAlive() returns false, MotionManager will attempt to remove the MC automatically More...
 
bool started
 true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand) More...
 

Private Member Functions

 MotionCommand (const MotionCommand &)
 don't call More...
 
MotionCommandoperator= (const MotionCommand &)
 don't call More...
 

*** INHERITED: ***

 MotionCommand ()
 Constructor: Defaults to kStdPriority and autoprune==true. More...
 
virtual ~MotionCommand ()
 Destructor. More...
 
virtual void start ()
 called after this is added to MotionManager; don't override this, use doStart instead More...
 
virtual void stop ()
 called after this is removed from MotionManager; don't override this, use doStop instead More...
 
virtual bool isActive () const
 returns true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand) More...
 
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()) More...
 
void setTranslator (EventTranslator *q)
 only called from MMCombo during process setup, allows MotionCommands to send events More...
 
virtual void doStart ()
 Override this if you want to run some startup code after being added to the MotionManager. More...
 
virtual void doStop ()
 Override this if you want to clean up after removal from MotionManager. More...
 
static double interpolate (double a, double b, double x)
 this utility function will probably be of use to a lot of MotionCommand's More...
 
static float interpolate (float a, float b, float x)
 this utility function will probably be of use to a lot of MotionCommand's More...
 
static 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) More...
 

Additional Inherited Members

- Public Types inherited from MotionManagerMsg
typedef unsigned short MC_ID
 the type to use when referring to MotionCommand ID's More...
 
- Static Public Attributes inherited from MotionManagerMsg
static const MC_ID invalid_MC_ID =static_cast<MC_ID>(-1)
 for errors and undefined stuff More...
 

Constructor & Destructor Documentation

MotionCommand::MotionCommand ( )

Constructor: Defaults to kStdPriority and autoprune==true.

Definition at line 124 of file MotionCommand.h.

virtual MotionCommand::~MotionCommand ( )
virtual

Destructor.

Definition at line 130 of file MotionCommand.h.

MotionCommand::MotionCommand ( const MotionCommand )
private

don't call

Member Function Documentation

virtual void MotionCommand::doStart ( )
protectedvirtual

Override this if you want to run some startup code after being added to the MotionManager.

Reimplemented in HeadPointerMC, ArmMC, PostureMC, PIDMC, GaitedFootstepMC, and LedMC.

Definition at line 161 of file MotionCommand.h.

Referenced by LedMC::doStart(), PIDMC::doStart(), PostureMC::doStart(), ArmMC::doStart(), HeadPointerMC::doStart(), and start().

virtual void MotionCommand::doStop ( )
protectedvirtual

Override this if you want to clean up after removal from MotionManager.

The old MotionManagerMsg::mc_id will still be available, but this value is no longer valid within the MotionManager. Only use it if you need to clean up associated values stored elsewhere.

Reimplemented in GaitedFootstepMC.

Definition at line 165 of file MotionCommand.h.

Referenced by stop().

virtual bool MotionCommand::getAutoPrune ( )
virtual
Returns
current setting of autopruning - used to remove motion from groups when !isAlive()

Definition at line 142 of file MotionCommand.h.

Referenced by PostureMC::isAlive(), ArmMC::isAlive(), and MotionManager::RemoveAccess().

static double MotionCommand::interpolate ( double  a,
double  b,
double  x 
)
staticprotected

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)

Parameters
afirst value
bsecond value
xweight of second value as opposed to first
Returns
$ a*(1.0-x)+b*x $
Todo:
  • replace with a more fancy spline based thing?

Definition at line 174 of file MotionCommand.h.

Referenced by interpolate().

static float MotionCommand::interpolate ( float  a,
float  b,
float  x 
)
staticprotected

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)

Parameters
afirst value
bsecond value
xweight of second value as opposed to first
Returns
$ a*(1.0-x)+b*x $
Todo:
  • replace with a more fancy spline based thing?

Definition at line 184 of file MotionCommand.h.

static void MotionCommand::interpolate ( const OutputCmd a,
const OutputCmd b,
float  x,
OutputCmd r 
)
staticprotected

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

Parameters
afirst joint cmd
bsecond joint cmd
xweight to favor b's value and weight
rjoint cmd to store the result

Definition at line 193 of file MotionCommand.h.

virtual bool MotionCommand::isActive ( ) const
virtual

returns true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand)

Definition at line 139 of file MotionCommand.h.

virtual int MotionCommand::isAlive ( )
pure virtual

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" ;)

Returns
zero if the motion is still processing, non-zero otherwise

Implemented in HeadPointerMC, SineMC, ArmMC, CMPackWalkMC, PostureMC, PIDMC, TailWagMC, WheeledWalkMC, XWalkMC, LedMC, DynamicMotionSequence, MotionSequenceMC< MAXMOVE >, UPennWalkMC, GaitedFootstepMC, and RemoteControllerMC.

Referenced by shouldPrune().

virtual int MotionCommand::isDirty ( )
pure virtual

not used by MotionManager at the moment, but could be used to reduce recomputation, and you may find it useful

Returns
zero if none of the commands have changed since last getJointCmd(), else non-zero

Implemented in HeadPointerMC, SineMC, ArmMC, CMPackWalkMC, PostureMC, PIDMC, TailWagMC, WheeledWalkMC, LedMC, XWalkMC, DynamicMotionSequence, MotionSequenceMC< MAXMOVE >, UPennWalkMC, and GaitedFootstepMC.

MotionCommand& MotionCommand::operator= ( const MotionCommand )
private

don't call

virtual void MotionCommand::setAutoPrune ( bool  ap)
virtual
Parameters
apbool representing requested autopruning setting

Definition at line 145 of file MotionCommand.h.

Referenced by MotionManager::doAddMotion().

void MotionCommand::setTranslator ( EventTranslator q)

only called from MMCombo during process setup, allows MotionCommands to send events

Definition at line 152 of file MotionCommand.h.

Referenced by MotionManager::checkinMotion(), and MotionManager::convertMotion().

virtual bool MotionCommand::shouldPrune ( )
virtual

whether this motion should be removed from its motion group automatically ( MotionCommand::autoprune && !isAlive())

Returns
(MotionCommand::autoprune && !isAlive())

Definition at line 149 of file MotionCommand.h.

Referenced by MotionManager::getOutputs().

virtual void MotionCommand::start ( )
virtual

called after this is added to MotionManager; don't override this, use doStart instead

Reimplemented in CMPackWalkMC, WheeledWalkMC, and XWalkMC.

Definition at line 133 of file MotionCommand.h.

Referenced by SineMC::getAcceleration(), SineMC::getCount(), SineMC::getOffsetTime(), SineMC::getSpeed(), SineMC::setParams(), XWalkMC::start(), SineMC::sync(), SineMC::syncAll(), and SineMC::updateOutputs().

virtual void MotionCommand::stop ( )
virtual

called after this is removed from MotionManager; don't override this, use doStop instead

Reimplemented in CMPackWalkMC, WheeledWalkMC, and XWalkMC.

Definition at line 136 of file MotionCommand.h.

Referenced by MotionManager::removeMotion(), and XWalkMC::stop().

virtual int MotionCommand::updateOutputs ( )
pure virtual

is called once per update cycle, can do any processing you need to change your priorities or set output commands on the MotionManager

Returns
zero if no changes were made, non-zero otherwise
See Also
RobotInfo::NumFrames
RobotInfo::FrameTime

Implemented in HeadPointerMC, ArmMC, CMPackWalkMC, SineMC, PostureMC, PIDMC, WheeledWalkMC, DynamicMotionSequence, XWalkMC, MotionSequenceMC< MAXMOVE >, LedMC, WaypointWalkMC, EmergencyStopMC, TailWagMC, GaitedFootstepMC, UPennWalkMC, and RemoteControllerMC.

Referenced by MotionManager::getOutputs().

Member Data Documentation

int MotionCommand::autoprune
protected

default true, autoprune setting, if this is true and isAlive() returns false, MotionManager will attempt to remove the MC automatically

Definition at line 203 of file MotionCommand.h.

Referenced by getAutoPrune(), setAutoPrune(), and shouldPrune().

EventTranslator* MotionCommand::queue
protected

send events using this, instead of posting to the erouter

Definition at line 201 of file MotionCommand.h.

Referenced by setTranslator().

bool MotionCommand::started
protected

true if the MotionCommand is currently running (although it may be overridden by a higher priority MotionCommand)

Definition at line 204 of file MotionCommand.h.

Referenced by isActive(), start(), and stop().


The documentation for this class was generated from the following files:

Tekkotsu v5.1CVS
Generated Thu Jul 21 2016 22:26:12 by Doxygen 1.8.6