Newer
Older
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotComponents::ArmarXObjects::MMMPlayer
* @author Mirko Waechter ( mirko dot waechter at kit dot edu )
* @date 2014
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#ifndef _ARMARX_COMPONENT_RobotComponents_MMMPlayer_H
#define _ARMARX_COMPONENT_RobotComponents_MMMPlayer_H
#include <MMM/Motion/Motion.h>
#include <ArmarXCore/core/Component.h>
#include <RobotAPI/interface/units/KinematicUnitInterface.h>
#include <ArmarXCore/core/services/tasks/PeriodicTask.h>
#include <RobotAPI/libraries/core/PIDController.h>
#include <ArmarXCore/interface/observers/ObserverInterface.h>
#include <RobotComponents/interface/components/MMMPlayerInterface.h>
namespace armarx
{
/**
* \class MMMPlayerPropertyDefinitions
* \brief
*/
class MMMPlayerPropertyDefinitions:
public ComponentPropertyDefinitions
{
public:
MMMPlayerPropertyDefinitions(std::string prefix):
ComponentPropertyDefinitions(prefix)
{
defineRequiredProperty<std::string>("KinematicUnitName", "Name of the KinematicUnit to which the joint values should be sent");
defineRequiredProperty<std::string>("KinematicTopicName", "Name of the KinematicUnit reporting topic");
defineOptionalProperty<std::string>("ArmarXProjects", "", "Comma-separated list with names of ArmarXProjects (e.g. 'Armar3,Armar4'). The MMM XML File can be specified relatively to a data path of one of these projects.");
defineOptionalProperty<std::string>("MMMFile", "", "Path to MMM XML File");
defineOptionalProperty<float>("FPS", 100.0f, "FPS with which the recording should be executed. Velocities will be adapted.");
defineOptionalProperty<bool>("LoopPlayback", false, "Specify whether motion should be repeated after execution")
.setCaseInsensitive(true)
.map("true", true)
.map("yes", true)
.map("1", true)
.map("false", false)
.map("no", false)
.map("0", false);
defineOptionalProperty<bool>("UsePIDController", true, "Specify whether the PID Controller should be used")
.setCaseInsensitive(true)
.map("true", true)
.map("yes", true)
.map("1", true)
.map("false", false)
.map("no", false)
.map("0", false);
defineOptionalProperty<float>("Kp", 1.f, "Proportional gain value of PID Controller");
defineOptionalProperty<float>("Ki", 0.00001f, "Integral gain value of PID Controller");
defineOptionalProperty<float>("Kd", 1.0f, "Differential gain value of PID Controller");
defineOptionalProperty<float>("absMaximumVelocity", 120.0f, "The PID will never set a velocity above this threshold in degree");
defineOptionalProperty<std::string>("RobotNodeSetName", "RobotState", "The name of the robot node set to be used (only need for PIDController mode)");
}
};
/**
* \ingroup RobotComponents-Components
* \brief Replays an MMM trajectory from a file.
*
* MMMPlayer reads an MMM trajectory from an MMM XML file (component property) and replays the motion using the KinematicUnit and its currently loaded robot.
* The trajectory can be replayed using position control or velocity control.
* In the latter case, the control parameters (P, I, D) can be configured via component properties.
*/
/**
* @ingroup Component-MMMPlayer
* @brief The MMMPlayer class
*/
class MMMPlayer :
virtual public armarx::Component,
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
public:
/**
* @see armarx::ManagedIceObject::getDefaultName()
*/
virtual std::string getDefaultName() const
{
return "MMMPlayer";
}
protected:
/**
* @see armarx::ManagedIceObject::onInitComponent()
*/
virtual void onInitComponent();
/**
* @see armarx::ManagedIceObject::onConnectComponent()
*/
virtual void onConnectComponent();
/**
* @see armarx::ManagedIceObject::onDisconnectComponent()
*/
virtual void onDisconnectComponent();
/**
* @see armarx::ManagedIceObject::onExitComponent()
*/
virtual void onExitComponent();
/**
* @see PropertyUser::createPropertyDefinitions()
*/
virtual PropertyDefinitionsPtr createPropertyDefinitions();
void run();
void setJointAngles(int frameNumber);
DebugObserverInterfacePrx debugObserver;
PeriodicTask<MMMPlayer>::pointer_type task;
StringList jointNames;
std::string motionPath;
double currentMotionTime, frameOffset;
bool loopPlayback;
std::map<std::string, PIDControllerPtr> PIDs;
NameValueMap targetPositionValues;
int direction;
NameValueMap jointOffets;
float maxVel;
private:
bool start();
bool pause();
bool stop();
void load(const std::string& filename, const std::string& projects);
void updatePIDController(const NameValueMap& angles);
NameValueMap latestJointAngles;
Mutex jointAnglesMutex;
public:
// MMMPlayerInterface
virtual bool startMMMPlayer(const Ice::Current&);
virtual bool pauseMMMPlayer(const Ice::Current&);
virtual bool stopMMMPlayer(const Ice::Current&);
virtual bool loadTrajectory(const std::string& filename, const std::string& projects, const Ice::Current&);
virtual int getNumberOfFrames(const Ice::Current&);
virtual int getCurrentFrame(const Ice::Current&);
virtual void setCurrentFrame(const int frame, const Ice::Current&);
virtual bool setLoopPlayback(bool loop, const Ice::Current&);
virtual std::string getMotionPath(const Ice::Current&);
virtual StringList getJointNames(const Ice::Current&);
virtual int setUsePID(bool usePID, const Ice::Current&);
virtual void setFPS(float FPS, const Ice::Current&);
virtual bool setJointsInUse(const std::string& jointName, bool inUse, const Ice::Current&);
// KinematicUnitListener interface
public:
void reportControlModeChanged(const NameControlModeMap&, bool, const Ice::Current&) {}
void reportJointAngles(const NameValueMap& angles, bool, const Ice::Current&);
void reportJointVelocities(const NameValueMap&, bool, const Ice::Current&) {}
void reportJointTorques(const NameValueMap&, bool, const Ice::Current&) {}
void reportJointAccelerations(const NameValueMap&, bool, const Ice::Current&) {}
void reportJointCurrents(const NameValueMap&, bool, const Ice::Current&) {}
void reportJointMotorTemperatures(const NameValueMap&, bool, const Ice::Current&) {}
void reportJointStatuses(const NameStatusMap&, bool, const Ice::Current&) {}