25#include <SimoxUtility/math/convert.h>
33#define STATE_POSITION 0
34#define STATE_VELOCITY 1
35#define STATE_ACCELERATION 2
51 armarx::CollisionModel);
52 debugDrawer->updateRobotColor(
"Preview",
"previewRobot", DrawColor{0, 1, 0, 0.5});
67 return task->isRunning();
79 std::unique_lock lock(motionMutex);
99 std::unique_lock lock(motionMutex);
114 if (
task->isRunning())
123 return !(
task->isRunning());
140 std::unique_lock lock(motionMutex);
144 int maxDerivative = 1;
148 for (
size_t i = 0; i <
jointNames.size(); ++i)
159 targetPosValue += it->second;
162 debugTargetValues[jointName] =
new Variant(targetPosValue);
177 auto pid =
PIDs.find(jointName);
179 if (pid !=
PIDs.end())
182 auto cv = pid->second->getControlValue();
187 targetVel = std::min<double>(
maxVel / 180.0 *
M_PI, targetVel);
188 targetVel = std::max<double>(-1 *
maxVel / 180.0 *
M_PI, targetVel);
189 debugVelocityValues[jointName] =
new Variant(targetVel);
202 Eigen::Vector3f position(pose[0][0], pose[1][0], pose[2][0]);
204 Eigen::Matrix4f p =
offset * simox::math::pos_quat_to_mat4f(position, orientation);
208 localModel->setGlobalPoseForRobotNode(customRootNode, p);
218 debugObserver->setDebugChannel(
"targetJointAngles", debugTargetValues);
219 debugObserver->setDebugChannel(
"targetVelocity", debugVelocityValues);
225 std::unique_lock lock(motionMutex);
228 if (moveToFrameZeroPose)
247 std::unique_lock lock(motionMutex);
253 for (std::string& p : proj)
260 ARMARX_WARNING <<
"ArmarX Package " << p <<
" has not been found!";
271 localModel = VirtualRobot::RobotIO::loadRobot(
272 modelFileName, VirtualRobot::RobotIO::RobotDescription::eStructure);
281 customRootNode.reset();
286 jointTraj = TrajectoryPtr::dynamicCast(trajs);
291 ARMARX_ERROR <<
"Error when loading TrajectoryPlayer: cannot load jointTraj !!!";
304 ARMARX_ERROR <<
"Not all trajectory dimensions are named !!! (would cause problems when "
305 "using kinematicUnit)";
309 NameControlModeMap modes;
310 LimitlessStateSeq limitlessStates;
312 for (
size_t i = 0; i <
jointNames.size(); ++i)
318 modes[jointName] = eVelocityControl;
322 modes[jointName] = ePositionControl;
332 VirtualRobot::RobotNodePtr rn =
localModel->getRobotNode(jointName);
335 ls.enabled = rn->isLimitless();
336 ls.limitLo = rn->getJointLimitLo();
337 ls.limitHi = rn->getJointLimitHi();
340 ARMARX_INFO <<
"limitless status - " << jointName <<
": " << rn->isLimitless();
341 limitlessStates.push_back(ls);
346 if (limitlessStates.size() ==
jointNames.size())
349 jointTraj->setLimitless(limitlessStates);
379 NameControlModeMap modes;
381 for (
size_t i = 0; i <
jointNames.size(); ++i)
387 modes[jointName] = eVelocityControl;
391 modes[jointName] = ePositionControl;
410 std::unique_lock lock(jointAnglesMutex);
411 latestJointAngles = angles;
447 offset = simox::math::pos_rpy_to_mat4f(position, orientation);
547 std::unique_lock lock(motionMutex);
553 int maxDerivative = 1;
555 std::vector<Ice::DoubleSeq> states =
559 for (
size_t i = 0; i <
jointNames.size(); ++i)
571 targetPosValue += it->second;
574 debugTargetValues[jointName] =
new Variant(targetPosValue);
591 auto pid =
PIDs.find(jointName);
593 if (pid !=
PIDs.end())
595 auto cv = pid->second->getControlValue();
611 targetVel = std::min<double>(
maxVel / 180.0 *
M_PI, targetVel);
612 targetVel = std::max<double>(-1 *
maxVel / 180.0 *
M_PI, targetVel);
614 debugVelocityValues[jointName] =
new Variant(targetVel);
627 Eigen::Vector3f position(pose[0][0], pose[1][0], pose[2][0]);
629 Eigen::Matrix4f p =
offset * simox::math::pos_quat_to_mat4f(position, orientation);
633 localModel->setGlobalPoseForRobotNode(customRootNode, p);
664 robotPoseUnitPrx->moveTo(PoseBasePtr::dynamicCast(
targetRobotPose), 0.001f, 0.001f);
691 std::unique_lock lock(jointAnglesMutex);
692 updatePIDController(latestJointAngles);
695 debugObserver->setDebugChannel(
"targetJointAngles", debugTargetValues);
696 debugObserver->setDebugChannel(
"targetVelocity", debugVelocityValues);
701TrajectoryPlayer::updatePIDController(
const NameValueMap& angles)
709 for (
const auto& joint : angles)
711 const std::string& name = joint.first;
718 auto it =
PIDs.find(name);
720 if (it ==
PIDs.end())
725 std::numeric_limits<double>::max(),
726 std::numeric_limits<double>::max(),
729 it =
PIDs.find(name);
744 ARMARX_WARNING <<
"No local model found !!! (No joints limit checked)";
748 std::unique_lock lock(jointAnglesMutex);
751 for (NameValueMap::iterator it = latestJointAngles.begin(); it != latestJointAngles.end(); it++)
753 std::string jointName = it->first;
754 float jointValue = it->second;
756 float lowLimit =
localModel->getRobotNode(jointName)->getJointLimitLow();
757 float highLimit =
localModel->getRobotNode(jointName)->getJointLimitHigh();
758 DrawColor errColor = {1, 0, 0, 1};
759 DrawColor warnColor = {1, 1, 0, 1};
760 DrawColor normColor = {0, 1, 0, 1};
761 if (jointValue < lowLimit || jointValue > highLimit)
763 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, errColor);
767 float dist = highLimit - lowLimit;
769 bool isWarning = ((jointValue < (lowLimit + 0.1 * dist)) && (jointValue >= lowLimit)) ||
770 ((jointValue > (highLimit - 0.1 * dist)) && (jointValue <= highLimit));
774 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, warnColor);
778 debugDrawer->updateRobotNodeColor(
"Preview",
"previewRobot", jointName, normColor);
790 ARMARX_WARNING <<
"No local model found !!! (No joints limit checked)";
794 std::unique_lock lock(jointAnglesMutex);
796 localModel->setJointValues(latestJointAngles);
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static void addDataPaths(const std::string &dataPathList)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getDataDir() const
bool packageFound() const
Returns whether or not this package was found with cmake.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
void updateTargetValues()
KinematicUnitInterfacePrx kinematicUnit
void setIsVelocityControl(bool isVelocity, const ::Ice::Current &=Ice::emptyCurrent) override
void onInitComponent() override
std::map< std::string, PIDControllerPtr > PIDs
Ice::StringSeq jointNames
bool pauseTrajectoryPlayer(const Ice::Current &) override
std::string modelFileName
void reportJointAngles(const NameValueMap &angles, Ice::Long, bool, const Ice::Current &) override
void onDisconnectComponent() override
bool setJointsInUse(const std::string &jointName, bool inUse, const Ice::Current &) override
NameValueMap targetPositionValues
bool resetTrajectoryPlayer(bool moveToFrameZeroPose, const Ice::Current &) override
bool checkSelfCollision()
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
NameValueMap nullVelocities
void loadJointTraj(const TrajectoryBasePtr &trajs, const ::Ice::Current &=Ice::emptyCurrent) override
std::string armarxProject
bool startTrajectoryPlayer(const Ice::Current &) override
DebugObserverInterfacePrx debugObserver
void onConnectComponent() override
NameValueMap targetVelocityValues
std::map< std::string, bool > jointNamesUsed
std::map< std::string, bool > limitlessMap
void setLoopPlayback(bool loop, const Ice::Current &) override
VirtualRobot::RobotPtr localModel
bool stopTrajectoryPlayer(const Ice::Current &) override
PeriodicTask< TrajectoryPlayer >::pointer_type task
void onExitComponent() override
void loadBasePoseTraj(const TrajectoryBasePtr &trajs, const ::Ice::Current &=Ice::emptyCurrent) override
bool robotPoseUnitEnabled
DebugDrawerInterfacePrx debugDrawer
::armarx::TrajectoryPtr basePoseTraj
::armarx::TrajectoryPtr jointTraj
The Variant class is described here: Variants.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Quaternion< float, 0 > Quaternionf
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
std::shared_ptr< PIDController > PIDControllerPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.