Actin  Version 5.5.5
Software for Robotics Simulation and Control
ecTimedWaitExampleDirection.cpp

An example that shows how to create a direction as extension
The header file for the EcTimedWaitExampleDirection class

#ifndef ecTimedWaitExampleDirection_H_
#define ecTimedWaitExampleDirection_H_
//------------------------------------------------------------------------------
// Copyright (c) 2014 Energid Technologies. All rights reserved.
//
//
//
//------------------------------------------------------------------------------
{
public:
virtual void registerComponents
(
virtual EcReal waitDuration
(
) const;
virtual void setWaitDuration
(
EcReal duration
);
virtual const EcString descriptor
(
) const EC_OVERRIDE;
virtual EcBoolean init
(
const EcManipulationDirector& director,
const EcString& role,
) const EC_OVERRIDE;
(
EcReal time,
const EcManipulationDirector& director,
const EcString& role,
) const EC_OVERRIDE;
virtual void convert
(
) const EC_OVERRIDE;
(
) const EC_OVERRIDE;
virtual EcReal progress
(
) const EC_OVERRIDE;
(
const EcString& separator
) const EC_OVERRIDE;
protected:
EcXmlReal m_WaitDuration;
};
#endif // ecTimedWaitExampleDirection_H_


The implementation file for the EcTimedWaitExampleDirection class

//------------------------------------------------------------------------------
// Copyright (c) 2014 Energid Technologies. All rights reserved.
//
//
//------------------------------------------------------------------------------
#include "ecManipDirectorExtensionsTokens.h"
#include <ecboost/format.hpp>
EC_XMLOBJECT_PLUGIN_DEFINE(EcTimedWaitExampleDirection, EcManipDirectorExtensionsTokens::EcTimedWaitExampleDirectionToken)
// Functions: Big four and other header functions.
// Description:
// default constructor
(
) :
m_WaitDuration(0.0)
{
}
// default destructor
EcTimedWaitExampleDirection::~EcTimedWaitExampleDirection
(
)
{
}
// copy constructor. Also copies the parent link pointer.
EcTimedWaitExampleDirection::EcTimedWaitExampleDirection
(
) :
{
}
// assignment operator
EcTimedWaitExampleDirection& EcTimedWaitExampleDirection::operator=
(
)
{
// self assignment.
if (this==&orig)
{
return *this;
}
// call parent
// copy data
return *this;
}
// equality operator
EcBoolean EcTimedWaitExampleDirection::operator==
(
) const
{
return
(
EcManipulationDirection::operator==(orig) &&
);
}
//End of header functions.
// Function: registerComponents
// Description: register XML components
(
)
{
registerComponent(EcManipDirectorExtensionsTokens::EcWaitDurationToken, &m_WaitDuration);
}
(
) const
{
}
(
EcReal duration
)
{
}
(
) const
{
if (!m_Tag.value().empty())
{
return m_Tag.value();
}
return str(ecboost::format("Wait %1% seconds") % waitDuration());
}
(
const EcManipulationDirector& director,
const EcString& role,
) const
{
dynamic_cast<EcTimedWaitExampleDirectionState*>(dstateContainer.element());
// here all possible error conditions need to be evaluated
// return EcFalse if the condition has to be met to continue further
// otherwise, add error string pMyState->addErrorString("radius <= 0.0"); set ret as EcFalse and continue
if (m_WaitDuration.value() <= 0.0)
{
pMyState->addErrorString("Wait duration is less than 0; Give valid duration!");
ret = EcFalse;
}
return ret;
}
(
EcReal time,
const EcManipulationDirector& director,
const EcString& role,
) const
{
// call to compute elapsed time
EcManipulationDirection::update(time, director, params, role, dstate, sdstate);
dynamic_cast<EcTimedWaitExampleDirectionState&>(sdstate);
if (!myState.startTimeRecorded())
{
myState.setStartTime(time);
}
const EcReal dt = time - myState.startTime();
const EcReal duration = waitDuration();
if (dt >= duration)
{
myState.setProgress(1.0);
return EcManipulationStatus::SUCCESS;
}
myState.setProgress(dt / duration);
return EcManipulationStatus::IN_PROGRESS;
}
(
) const
{
dynamic_cast<EcBasicDirectionSimpleState*>(sdstateContainer.element());
if (!pBasicState)
{
pBasicState = dynamic_cast<EcBasicDirectionSimpleState*>(sdstateContainer.element());
}
const EcManipulationSceneDirectionState* pState = dstateContainer.element();
pBasicState->setProgress((pState) ? progress(*pState) : 0.0);
pBasicState->setElapsedTime((pState) ? elapsedTime(*pState) : 0.0);
if (pState)
{
pBasicState->setDirectorIssues(pState->directorIssues()); // To display the issues over the block
}
}
(
) const
{
return EcNULL;
}
(
) const
{
dynamic_cast<const EcTimedWaitExampleDirectionState&>(dstate);
return myState.progress();
}
(
const EcString& separator
) const
{
// This method should never be called
return "";
}
//------------------------------------------------------------------------------
// Copyright (c) 2014 Energid Technologies. All rights reserved.
//
//
//------------------------------------------------------------------------------
#include "ecManipDirectorExtensionsTokens.h"
#include <ecboost/format.hpp>
EC_XMLOBJECT_PLUGIN_DEFINE(EcTimedWaitExampleDirection, EcManipDirectorExtensionsTokens::EcTimedWaitExampleDirectionToken)
// Functions: Big four and other header functions.
// Description:
// default constructor
(
) :
m_WaitDuration(0.0)
{
}
// default destructor
EcTimedWaitExampleDirection::~EcTimedWaitExampleDirection
(
)
{
}
// copy constructor. Also copies the parent link pointer.
EcTimedWaitExampleDirection::EcTimedWaitExampleDirection
(
) :
{
}
// assignment operator
EcTimedWaitExampleDirection& EcTimedWaitExampleDirection::operator=
(
)
{
// self assignment.
if (this==&orig)
{
return *this;
}
// call parent
// copy data
return *this;
}
// equality operator
EcBoolean EcTimedWaitExampleDirection::operator==
(
) const
{
return
(
EcManipulationDirection::operator==(orig) &&
);
}
//End of header functions.
// Function: registerComponents
// Description: register XML components
(
)
{
registerComponent(EcManipDirectorExtensionsTokens::EcWaitDurationToken, &m_WaitDuration);
}
(
) const
{
}
(
EcReal duration
)
{
}
(
) const
{
if (!m_Tag.value().empty())
{
return m_Tag.value();
}
return str(ecboost::format("Wait %1% seconds") % waitDuration());
}
(
const EcManipulationDirector& director,
const EcString& role,
) const
{
dynamic_cast<EcTimedWaitExampleDirectionState*>(dstateContainer.element());
// here all possible error conditions need to be evaluated
// return EcFalse if the condition has to be met to continue further
// otherwise, add error string pMyState->addErrorString("radius <= 0.0"); set ret as EcFalse and continue
if (m_WaitDuration.value() <= 0.0)
{
pMyState->addErrorString("Wait duration is less than 0; Give valid duration!");
ret = EcFalse;
}
return ret;
}
(
EcReal time,
const EcManipulationDirector& director,
const EcString& role,
) const
{
// call to compute elapsed time
EcManipulationDirection::update(time, director, params, role, dstate, sdstate);
dynamic_cast<EcTimedWaitExampleDirectionState&>(sdstate);
if (!myState.startTimeRecorded())
{
myState.setStartTime(time);
}
const EcReal dt = time - myState.startTime();
const EcReal duration = waitDuration();
if (dt >= duration)
{
myState.setProgress(1.0);
return EcManipulationStatus::SUCCESS;
}
myState.setProgress(dt / duration);
return EcManipulationStatus::IN_PROGRESS;
}
(
) const
{
dynamic_cast<EcBasicDirectionSimpleState*>(sdstateContainer.element());
if (!pBasicState)
{
pBasicState = dynamic_cast<EcBasicDirectionSimpleState*>(sdstateContainer.element());
}
const EcManipulationSceneDirectionState* pState = dstateContainer.element();
pBasicState->setProgress((pState) ? progress(*pState) : 0.0);
pBasicState->setElapsedTime((pState) ? elapsedTime(*pState) : 0.0);
if (pState)
{
pBasicState->setDirectorIssues(pState->directorIssues()); // To display the issues over the block
}
}
(
) const
{
return EcNULL;
}
(
) const
{
dynamic_cast<const EcTimedWaitExampleDirectionState&>(dstate);
return myState.progress();
}
(
const EcString& separator
) const
{
// This method should never be called
return "";
}