Choreonoid  1.8
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
cnoid::SimulatorItem Class Referenceabstract

#include <SimulatorItem.h>

Inheritance diagram for cnoid::SimulatorItem:
cnoid::Item cnoid::Referenced cnoid::AISTSimulatorItem cnoid::KinematicSimulatorItem

Public Types

enum  RecordingMode {
  FullRecording, TailRecording, NoRecording, NumRecordingModes,
  REC_FULL = FullRecording, REC_TAIL = TailRecording, REC_NONE = NoRecording, N_RECORDING_MODES = NumRecordingModes
}
 
enum  TimeRangeMode {
  UnlimitedTime, SpecifiedTime, TimeBarTime, NumTimeRangeModes,
  ActiveControlTime, TR_UNLIMITED = UnlimitedTime, TR_ACTIVE_CONTROL = ActiveControlTime, TR_SPECIFIED = SpecifiedTime,
  TR_TIMEBAR = TimeBarTime, N_TIME_RANGE_MODES = NumTimeRangeModes
}
 
- Public Types inherited from cnoid::Item
enum  Attribute {
  SubItem, Attached, Temporal, LoadOnly,
  NumAttributes, SUB_ITEM = SubItem, TEMPORAL = Temporal, LOAD_ONLY = LoadOnly
}
 
enum  CheckId { LogicalSumOfAllChecks = -1, PrimaryCheck = 0 }
 
typedef std::function< bool(Item *item)> ItemPredicate
 

Public Member Functions

virtual ~SimulatorItem ()
 
WorldItemworldItem ()
 
virtual double worldTimeStep ()
 
void setTimeStep (double step)
 
bool startSimulation (bool doReset=true)
 
void stopSimulation (bool isForced=false)
 
void pauseSimulation ()
 
void restartSimulation ()
 
bool isRunning () const
 
bool isPausing () const
 
bool isActive () const
 isRunning() && !isPausing() More...
 
int currentFrame () const
 This can only be called from the simulation thread. More...
 
double currentTime () const
 This can only be called from the simulation thread. More...
 
int simulationFrame () const
 This can be called from non simulation threads. More...
 
double simulationTime () const
 This can be called from non simulation threads. More...
 
SignalProxy< void()> sigSimulationStarted ()
 
SignalProxy< void()> sigSimulationPaused ()
 
SignalProxy< void()> sigSimulationResumed ()
 
SignalProxy< void(bool isForced)> sigSimulationFinished ()
 
void setRecordingMode (int selection)
 
int recordingMode () const
 
void setTimeRangeMode (int selection)
 
void setTimeLength (double length)
 
void setSpecifiedRecordingTimeLength (double length)
 
void setActiveControlTimeRangeMode (bool on)
 
bool isActiveControlTimeRangeMode () const
 
void setRealtimeSyncMode (bool on)
 
void setDeviceStateOutputEnabled (bool on)
 
bool isRecordingEnabled () const
 
bool isDeviceStateOutputEnabled () const
 
bool isAllLinkPositionOutputMode ()
 
virtual void setAllLinkPositionOutputMode (bool on)
 
const std::string & controllerOptionString () const
 
const std::vector< SimulationBody * > & simulationBodies ()
 
SimulationBodyfindSimulationBody (BodyItem *bodyItem)
 
SimulationBodyfindSimulationBody (const std::string &name)
 
int addPreDynamicsFunction (std::function< void()> func)
 
int addMidDynamicsFunction (std::function< void()> func)
 
int addPostDynamicsFunction (std::function< void()> func)
 
void removePreDynamicsFunction (int id)
 
void removeMidDynamicsFunction (int id)
 
void removePostDynamicsFunction (int id)
 
CloneMapcloneMap ()
 
SignalProxy< void(const std::vector< SimulationBodyPtr > &simulationBodies)> sigSimulationBodyListUpdated ()
 
virtual Vector3 getGravity () const
 
virtual void setExternalForce (BodyItem *bodyItem, Link *link, const Vector3 &point, const Vector3 &f, double time=0.0)
 
virtual void clearExternalForces ()
 
virtual void setVirtualElasticString (BodyItem *bodyItem, Link *link, const Vector3 &attachmentPoint, const Vector3 &endPoint)
 
virtual void clearVirtualElasticStrings ()
 
virtual void setForcedPosition (BodyItem *bodyItem, const Isometry3 &T)
 
virtual bool isForcedPositionActiveFor (BodyItem *bodyItem) const
 
virtual void clearForcedPositions ()
 
- Public Member Functions inherited from cnoid::Item
virtual ~Item ()
 
Itemoperator= (const Item &rhs)=delete
 
int classId () const
 
ItemcreateNewInstance () const
 
void assign (Item *srcItem)
 Copy item properties as much as possible like the assignment operator. More...
 
Itemduplicate (Item *duplicatedParentItem=nullptr) const
 
ItemduplicateSubTree () const
 This function creates a copy of the item including its descendant items. More...
 
ItemduplicateAll () const
 
const std::string & name () const
 
virtual bool setName (const std::string &name)
 
virtual std::string displayName () const
 
void setDisplayNameModifier (std::function< std::string(const Item *item)> modifier)
 
SignalProxy< void(const std::string &oldName)> sigNameChanged ()
 
void notifyNameChange ()
 This function notifies the system of a displayName change. More...
 
void setAttribute (Attribute attribute)
 
void unsetAttribute (Attribute attribute)
 
bool hasAttribute (Attribute attribute) const
 
bool isSubItem () const
 
void setSubItemAttributes ()
 
bool isTemporal () const
 
void setTemporal (bool on=true)
 
bool isSelected () const
 
void setSelected (bool on, bool isCurrent=false)
 
void setSubTreeItemsSelected (bool on)
 
bool isChecked (int checkId=PrimaryCheck) const
 
void setChecked (bool on)
 
void setChecked (int checkId, bool on)
 
int numCheckStates () const
 
int numChildren () const
 
int countDescendantItems () const
 
ItemchildItem () const
 
ItemprevItem () const
 
ItemnextItem () const
 
ItemlastChildItem () const
 
ItemparentItem () const
 
ItemheadItem () const
 
RootItemfindRootItem () const
 
bool isConnectedToRoot () const
 
ItemlocalRootItem () const
 
bool addChildItem (Item *item, bool isManualOperation=false)
 
bool insertChildItem (Item *item, Item *nextItem, bool isManualOperation=false)
 
bool insertChild (Item *position, Item *item, bool isManualOperation=false)
 
bool addSubItem (Item *item)
 
bool insertSubItem (Item *item, Item *nextItem)
 
void removeFromParentItem ()
 
void detachFromParentItem ()
 
void clearChildren ()
 
template<class ItemType >
ItemType * find (const std::string &path="")
 
ItemfindItem (const std::string &path) const
 
template<class ItemType >
ItemType * findItem (const std::string &path) const
 
template<class ItemType >
ItemType * findItem (std::function< bool(ItemType *item)> pred=nullptr) const
 
ItemfindChildItem (const std::string &path, std::function< bool(Item *item)> pred=nullptr) const
 
template<class ItemType >
ItemType * findChildItem (const std::string &path, std::function< bool(ItemType *item)> pred=nullptr) const
 
template<class ItemType >
ItemType * findChildItem (std::function< bool(ItemType *item)> pred=nullptr) const
 
ItemfindSubItem (const std::string &path) const
 
template<class ItemType >
ItemType * findSubItem (const std::string &path="") const
 
template<class ItemType >
ItemType * findOwnerItem (bool includeSelf=false) const
 
bool isOwnedBy (Item *item) const
 
ItemList childItems (std::function< bool(Item *item)> pred=nullptr) const
 
template<class ItemType >
ItemList< ItemType > childItems (std::function< bool(ItemType *item)> pred=nullptr) const
 
ItemList descendantItems (std::function< bool(Item *item)> pred=nullptr) const
 
template<class ItemType >
ItemList< ItemType > descendantItems (std::function< bool(ItemType *item)> pred=nullptr) const
 
ItemList selectedDescendantItems (std::function< bool(Item *item)> pred=nullptr) const
 
template<class ItemType >
ItemList< ItemType > selectedDescendantItems (std::function< bool(Item *item)> pred=nullptr) const
 
bool traverse (std::function< bool(Item *)> pred)
 
template<class ItemType >
bool traverse (std::function< bool(ItemType *item)> pred=nullptr)
 
SignalProxy< void()> sigTreePathChanged ()
 
SignalProxy< void()> sigTreePositionChanged ()
 
SignalProxy< void(Item *topItem, Item *prevTopParentItem)> sigTreePositionChanged2 ()
 
SignalProxy< void()> sigPositionChanged ()
 
SignalProxy< void()> sigSubTreeChanged ()
 
SignalProxy< void()> sigDisconnectedFromRoot ()
 
SignalProxy< void()> sigDetachedFromRoot ()
 
SignalProxy< void(bool on)> sigSelectionChanged ()
 
SignalProxy< void(int checkId, bool on)> sigAnyCheckToggled ()
 
SignalProxy< void(bool on)> sigCheckToggled (int checkId=PrimaryCheck)
 
virtual void notifyUpdate ()
 
SignalProxy< void()> sigUpdated ()
 
bool setAddon (ItemAddon *addon)
 
void removeAddon (ItemAddon *addon)
 
template<class AddonType >
AddonType * findAddon ()
 
template<class AddonType >
AddonType * getAddon ()
 
std::vector< ItemAddon * > addons ()
 
bool load (const std::string &filename, const std::string &format=std::string(), const Mapping *options=nullptr)
 
bool load (const std::string &filename, Item *parent, const std::string &format=std::string(), const Mapping *options=nullptr)
 
bool save (const std::string &filename, const std::string &format=std::string(), const Mapping *options=nullptr)
 
bool overwrite (bool forceOverwrite=false, const std::string &format=std::string())
 
const std::string & filePath () const
 Full path file name. More...
 
std::string fileName () const
 File name without the directory. More...
 
const std::string & fileFormat () const
 
const MappingfileOptions () const
 
std::time_t fileModificationTime () const
 
bool isConsistentWithFile () const
 
void updateFileInformation (const std::string &filename, const std::string &format, Mapping *options=nullptr)
 
void setConsistentWithFile (bool isConsistent)
 
void suggestFileUpdate ()
 
void clearFileInformation ()
 Use this function to disable the implicit overwrite next time. More...
 
bool reload ()
 
bool replace (Item *originalItem)
 
ItemfindOriginalItem () const
 
ItemfindReplacementItem () const
 
void putProperties (PutPropertyFunction &putProperty)
 
- Public Member Functions inherited from cnoid::Referenced
virtual ~Referenced ()
 

Static Public Member Functions

static void initializeClass (ExtensionManager *ext)
 
static SimulatorItemfindActiveSimulatorItemFor (Item *item)
 
- Static Public Member Functions inherited from cnoid::Item
template<class ItemType >
static ItemPredicate getItemPredicate ()
 
template<class ItemType >
static ItemPredicate getItemPredicate (std::function< bool(ItemType *item)> pred)
 
static Itemfind (const std::string &path)
 

Protected Member Functions

 SimulatorItem ()
 
 SimulatorItem (const std::string &name)
 
 SimulatorItem (const SimulatorItem &org)
 
virtual void onTreePathChanged () override
 
virtual void onDisconnectedFromRoot () override
 
virtual void clearSimulation ()
 
virtual SimulationBodycreateSimulationBody (Body *orgBody, CloneMap &cloneMap)
 
virtual SimulationBodycreateSimulationBody (Body *orgBody)
 
CollisionDetectorgetOrCreateCollisionDetector ()
 
CollisionDetectorcollisionDetector ()
 
virtual bool initializeSimulation (const std::vector< SimulationBody * > &simBodies)=0
 
virtual bool completeInitializationOfSimulation ()
 
virtual void initializeSimulationThread ()
 
virtual void finalizeSimulationThread ()
 
virtual bool stepSimulation (const std::vector< SimulationBody * > &activeSimBodies)=0
 
virtual void finalizeSimulation ()
 
virtual std::shared_ptr< CollisionLinkPairListgetCollisions ()
 
virtual void doPutProperties (PutPropertyFunction &putProperty) override
 
virtual bool store (Archive &archive) override
 
virtual bool restore (const Archive &archive) override
 
- Protected Member Functions inherited from cnoid::Item
 Item ()
 
 Item (const std::string &name)
 
 Item (const Item &item)
 
virtual void doAssign (Item *srcItem)
 Implement the code to copy properties like the assingment operator. More...
 
virtual ItemdoDuplicate () const
 Override this function to allow duplication of an instance. More...
 
virtual ItemdoDuplicate (Item *duplicatedParentItem) const
 
virtual bool onNewTreePositionCheck (bool isManualOperation, std::function< void()> &out_callbackWhenAdded)
 
virtual void onAddedToParent ()
 
virtual void onTreePositionChanged ()
 
virtual void onPositionChanged ()
 
virtual void onConnectedToRoot ()
 
virtual void onRemovedFromParent (Item *parentItem, bool isParentBeingDeleted)
 
virtual bool onChildItemAboutToBeAdded (Item *childItem, bool isManualOperation)
 
- Protected Member Functions inherited from cnoid::Referenced
 Referenced ()
 
 Referenced (const Referenced &)
 
int refCount () const
 

Friends

class SimulationBody
 
class SimulatedMotionEngineManager
 

Member Enumeration Documentation

◆ RecordingMode

Enumerator
FullRecording 
TailRecording 
NoRecording 
NumRecordingModes 
REC_FULL 
REC_TAIL 
REC_NONE 
N_RECORDING_MODES 

◆ TimeRangeMode

Enumerator
UnlimitedTime 
SpecifiedTime 
TimeBarTime 
NumTimeRangeModes 
ActiveControlTime 
TR_UNLIMITED 
TR_ACTIVE_CONTROL 
TR_SPECIFIED 
TR_TIMEBAR 
N_TIME_RANGE_MODES 

Constructor & Destructor Documentation

◆ ~SimulatorItem()

SimulatorItem::~SimulatorItem ( )
virtual

◆ SimulatorItem() [1/3]

SimulatorItem::SimulatorItem ( )
protected

◆ SimulatorItem() [2/3]

SimulatorItem::SimulatorItem ( const std::string &  name)
protected

◆ SimulatorItem() [3/3]

SimulatorItem::SimulatorItem ( const SimulatorItem org)
protected

Member Function Documentation

◆ addMidDynamicsFunction()

int SimulatorItem::addMidDynamicsFunction ( std::function< void()>  func)

◆ addPostDynamicsFunction()

int SimulatorItem::addPostDynamicsFunction ( std::function< void()>  func)

◆ addPreDynamicsFunction()

int SimulatorItem::addPreDynamicsFunction ( std::function< void()>  func)
Returns
The registration id of the function. The id can be used for removing the function.

◆ clearExternalForces()

void SimulatorItem::clearExternalForces ( )
virtual

◆ clearForcedPositions()

void SimulatorItem::clearForcedPositions ( )
virtual

Reimplemented in cnoid::AISTSimulatorItem.

◆ clearSimulation()

void SimulatorItem::clearSimulation ( )
protectedvirtual

Reimplemented in cnoid::KinematicSimulatorItem.

◆ clearVirtualElasticStrings()

void SimulatorItem::clearVirtualElasticStrings ( )
virtual

◆ cloneMap()

CloneMap & SimulatorItem::cloneMap ( )

◆ collisionDetector()

CollisionDetector * SimulatorItem::collisionDetector ( )
protected

◆ completeInitializationOfSimulation()

bool SimulatorItem::completeInitializationOfSimulation ( )
protectedvirtual

This function is called after all the initializetion processes including those of controllers and sub simulators to complete the initialization of simulation.

Note
This function is called from the main thread.

Reimplemented in cnoid::AISTSimulatorItem.

◆ controllerOptionString()

const std::string & SimulatorItem::controllerOptionString ( ) const

◆ createSimulationBody() [1/2]

SimulationBody * SimulatorItem::createSimulationBody ( Body orgBody)
protectedvirtual

◆ createSimulationBody() [2/2]

SimulationBody * SimulatorItem::createSimulationBody ( Body orgBody,
CloneMap cloneMap 
)
protectedvirtual
Note
orgBody should not owned by the SimulationBody instance. Instead it must clone a body instance using cloneMap and use it for the simulation.
This function should be a pure virtual function when the old function is removed.

Reimplemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ currentFrame()

int SimulatorItem::currentFrame ( ) const

This can only be called from the simulation thread.

◆ currentTime()

double SimulatorItem::currentTime ( ) const

This can only be called from the simulation thread.

◆ doPutProperties()

void SimulatorItem::doPutProperties ( PutPropertyFunction putProperty)
overrideprotectedvirtual

This function is used to put a standard properties of the item. You can implement the standard properties by overriding this function.

Note
The overridden function should call the same function of the parent class.

Reimplemented from cnoid::Item.

Reimplemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ finalizeSimulation()

void SimulatorItem::finalizeSimulation ( )
protectedvirtual
Note
This function is called from the main thread.

Reimplemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ finalizeSimulationThread()

void SimulatorItem::finalizeSimulationThread ( )
protectedvirtual

◆ findActiveSimulatorItemFor()

SimulatorItem * SimulatorItem::findActiveSimulatorItemFor ( Item item)
static

◆ findSimulationBody() [1/2]

SimulationBody * SimulatorItem::findSimulationBody ( BodyItem bodyItem)

◆ findSimulationBody() [2/2]

SimulationBody * SimulatorItem::findSimulationBody ( const std::string &  name)

◆ getCollisions()

std::shared_ptr< CollisionLinkPairList > SimulatorItem::getCollisions ( )
protectedvirtual

Reimplemented in cnoid::AISTSimulatorItem.

◆ getGravity()

Vector3 SimulatorItem::getGravity ( ) const
virtual
Note
This function should be a pure virtual function

Reimplemented in cnoid::AISTSimulatorItem.

◆ getOrCreateCollisionDetector()

CollisionDetector * SimulatorItem::getOrCreateCollisionDetector ( )
protected

◆ initializeClass()

void SimulatorItem::initializeClass ( ExtensionManager ext)
static

◆ initializeSimulation()

virtual bool cnoid::SimulatorItem::initializeSimulation ( const std::vector< SimulationBody * > &  simBodies)
protectedpure virtual
Parameters
simBodiesSimulatorBody objects which have a valid body
Note
This function is called from the main thread.

Implemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ initializeSimulationThread()

void SimulatorItem::initializeSimulationThread ( )
protectedvirtual

◆ isActive()

bool SimulatorItem::isActive ( ) const

isRunning() && !isPausing()

◆ isActiveControlTimeRangeMode()

bool SimulatorItem::isActiveControlTimeRangeMode ( ) const

◆ isAllLinkPositionOutputMode()

bool SimulatorItem::isAllLinkPositionOutputMode ( )

◆ isDeviceStateOutputEnabled()

bool SimulatorItem::isDeviceStateOutputEnabled ( ) const

◆ isForcedPositionActiveFor()

bool SimulatorItem::isForcedPositionActiveFor ( BodyItem bodyItem) const
virtual

Reimplemented in cnoid::AISTSimulatorItem.

◆ isPausing()

bool SimulatorItem::isPausing ( ) const

◆ isRecordingEnabled()

bool SimulatorItem::isRecordingEnabled ( ) const

◆ isRunning()

bool SimulatorItem::isRunning ( ) const

◆ onDisconnectedFromRoot()

void SimulatorItem::onDisconnectedFromRoot ( )
overrideprotectedvirtual

Reimplemented from cnoid::Item.

◆ onTreePathChanged()

void SimulatorItem::onTreePathChanged ( )
overrideprotectedvirtual

This function is called at the same time as sigTreePathChanged. The order in which it is called precedes the signal. By overriding this function in a derived item class, you can implement the necessary processing when the path in the item tree is changed.

Reimplemented from cnoid::Item.

◆ pauseSimulation()

void SimulatorItem::pauseSimulation ( )

◆ recordingMode()

int SimulatorItem::recordingMode ( ) const

◆ removeMidDynamicsFunction()

void SimulatorItem::removeMidDynamicsFunction ( int  id)

◆ removePostDynamicsFunction()

void SimulatorItem::removePostDynamicsFunction ( int  id)

◆ removePreDynamicsFunction()

void SimulatorItem::removePreDynamicsFunction ( int  id)

◆ restartSimulation()

void SimulatorItem::restartSimulation ( )

◆ restore()

bool SimulatorItem::restore ( const Archive archive)
overrideprotectedvirtual

Reimplemented from cnoid::Item.

Reimplemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ setActiveControlTimeRangeMode()

void SimulatorItem::setActiveControlTimeRangeMode ( bool  on)

◆ setAllLinkPositionOutputMode()

void SimulatorItem::setAllLinkPositionOutputMode ( bool  on)
virtual

◆ setDeviceStateOutputEnabled()

void SimulatorItem::setDeviceStateOutputEnabled ( bool  on)

◆ setExternalForce()

void SimulatorItem::setExternalForce ( BodyItem bodyItem,
Link link,
const Vector3 point,
const Vector3 f,
double  time = 0.0 
)
virtual
Parameters
pointlink local position to apply the force
flinear force to apply in global coordinate

◆ setForcedPosition()

void SimulatorItem::setForcedPosition ( BodyItem bodyItem,
const Isometry3 T 
)
virtual

Reimplemented in cnoid::AISTSimulatorItem.

◆ setRealtimeSyncMode()

void SimulatorItem::setRealtimeSyncMode ( bool  on)

◆ setRecordingMode()

void SimulatorItem::setRecordingMode ( int  selection)

◆ setSpecifiedRecordingTimeLength()

void cnoid::SimulatorItem::setSpecifiedRecordingTimeLength ( double  length)
inline

◆ setTimeLength()

void SimulatorItem::setTimeLength ( double  length)

◆ setTimeRangeMode()

void SimulatorItem::setTimeRangeMode ( int  selection)

◆ setTimeStep()

void SimulatorItem::setTimeStep ( double  step)

◆ setVirtualElasticString()

void SimulatorItem::setVirtualElasticString ( BodyItem bodyItem,
Link link,
const Vector3 attachmentPoint,
const Vector3 endPoint 
)
virtual
Parameters
attachmentPointlink local position

◆ sigSimulationBodyListUpdated()

SignalProxy<void(const std::vector<SimulationBodyPtr>& simulationBodies)> cnoid::SimulatorItem::sigSimulationBodyListUpdated ( )
Note
This signal is emitted in the simulation thread

◆ sigSimulationFinished()

SignalProxy< void(bool isForced)> SimulatorItem::sigSimulationFinished ( )

◆ sigSimulationPaused()

SignalProxy< void()> SimulatorItem::sigSimulationPaused ( )

◆ sigSimulationResumed()

SignalProxy< void()> SimulatorItem::sigSimulationResumed ( )

◆ sigSimulationStarted()

SignalProxy< void()> SimulatorItem::sigSimulationStarted ( )

◆ simulationBodies()

const std::vector< SimulationBody * > & SimulatorItem::simulationBodies ( )

For sub simulators

◆ simulationFrame()

int SimulatorItem::simulationFrame ( ) const

This can be called from non simulation threads.

◆ simulationTime()

double SimulatorItem::simulationTime ( ) const

This can be called from non simulation threads.

◆ startSimulation()

bool SimulatorItem::startSimulation ( bool  doReset = true)

◆ stepSimulation()

virtual bool cnoid::SimulatorItem::stepSimulation ( const std::vector< SimulationBody * > &  activeSimBodies)
protectedpure virtual

This function is called from the simulation loop thread.

Parameters
activeSimBodiesSimulatorBody objects which are non-static ones.

Implemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ stopSimulation()

void SimulatorItem::stopSimulation ( bool  isForced = false)

◆ store()

bool SimulatorItem::store ( Archive archive)
overrideprotectedvirtual

Reimplemented from cnoid::Item.

Reimplemented in cnoid::AISTSimulatorItem, and cnoid::KinematicSimulatorItem.

◆ worldItem()

WorldItem * SimulatorItem::worldItem ( )

◆ worldTimeStep()

double SimulatorItem::worldTimeStep ( )
virtual

Friends And Related Function Documentation

◆ SimulatedMotionEngineManager

friend class SimulatedMotionEngineManager
friend

◆ SimulationBody

friend class SimulationBody
friend

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