TrajectoryControllerSubUnit.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::TrajectoryControllerSubUnit
17 * @author Stefan Reither ( stef dot reither at web dot de )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <mutex>
26
27#include <RobotAPI/interface/components/TrajectoryPlayerInterface.h>
28
30#include "../RobotUnit.h"
31#include "KinematicSubUnit.h"
32#include "RobotUnitSubUnit.h"
33
34namespace armarx
35{
38 {
39 public:
42 {
43 defineRequiredProperty<std::string>("KinematicUnitName",
44 "Name of the KinematicUnit. Only needed for "
45 "returning to zeroFramePose while resetting.");
47 1.f,
48 "Proportional gain value of PID Controller",
51 0.0f,
52 "Integral gain value of PID Controller",
55 0.0f,
56 "Differential gain value of PID Controller",
59 "absMaximumVelocity",
60 80.0f,
61 "The PID will never set a velocity above this threshold (degree/s)");
63 "",
64 "If this value is set, the root pose of the motion "
65 "is set for this node instead of the root joint.");
66
67 defineOptionalProperty<bool>("EnableRobotPoseUnit",
68 false,
69 "Specify whether RobotPoseUnit should be used to move the "
70 "robot's position. Only useful in simulation.");
72 "RobotPoseUnitName",
73 "RobotPoseUnit",
74 "Name of the RobotPoseUnit to which the robot position should be sent");
75 }
76 };
77
79
81 virtual public RobotUnitSubUnit,
82 virtual public TrajectoryPlayerInterface,
83 virtual public Component
84 {
85 // TrajectoryControllerSubUnitInterface interface
86 public:
87 bool startTrajectoryPlayer(const Ice::Current& = Ice::emptyCurrent) override;
88 bool pauseTrajectoryPlayer(const Ice::Current& = Ice::emptyCurrent) override;
89 bool stopTrajectoryPlayer(const Ice::Current& = Ice::emptyCurrent) override;
90 bool resetTrajectoryPlayer(bool moveToFrameZeroPose,
91 const Ice::Current& = Ice::emptyCurrent) override;
92
93 void loadJointTraj(const TrajectoryBasePtr& jointTraj,
94 const Ice::Current& = Ice::emptyCurrent) override;
95 void loadBasePoseTraj(const TrajectoryBasePtr& basePoseTraj,
96 const Ice::Current& = Ice::emptyCurrent) override;
97
98 void setLoopPlayback(bool loop, const Ice::Current& = Ice::emptyCurrent) override;
99 Ice::Double getEndTime(const Ice::Current& = Ice::emptyCurrent) override;
100 Ice::Double getTrajEndTime(const Ice::Current& = Ice::emptyCurrent) override;
101 Ice::Double getCurrentTime(const Ice::Current& = Ice::emptyCurrent) override;
102 void setEndTime(Ice::Double, const Ice::Current& = Ice::emptyCurrent) override;
103
104 // Within the RobotUnit the NJointTrajectoryController is always in VelocityControl
105 void
106 setIsVelocityControl(bool, const Ice::Current& = Ice::emptyCurrent) override
107 {
108 }
109
110 void setIsPreview(bool, const Ice::Current& = Ice::emptyCurrent) override;
111 bool
112 setJointsInUse(const std::string&, bool, const Ice::Current& = Ice::emptyCurrent) override;
113 void enableRobotPoseUnit(bool, const Ice::Current& = Ice::emptyCurrent) override;
114
115 void considerConstraints(bool, const Ice::Current& = Ice::emptyCurrent) override;
116
117 // RobotUnitSubUnit interface
118 void update(const SensorAndControl& sc, const JointAndNJointControllers& c) override;
119
120 void setup(RobotUnit* rUnit);
121
122 // KinematicUnitListener interface
123 void
124 reportControlModeChanged(const NameControlModeMap&,
125 Ice::Long,
126 bool,
127 const Ice::Current&) override
128 {
129 }
130
131 void
132 reportJointAngles(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
133 {
134 }
135
136 void
137 reportJointVelocities(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
138 {
139 }
140
141 void
142 reportJointTorques(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
143 {
144 }
145
146 void
147 reportJointAccelerations(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
148 {
149 }
150
151 void
152 reportJointCurrents(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
153 {
154 }
155
156 void
157 reportJointMotorTemperatures(const NameValueMap&,
158 Ice::Long,
159 bool,
160 const Ice::Current&) override
161 {
162 }
163
164 void
165 reportJointStatuses(const NameStatusMap&, Ice::Long, bool, const Ice::Current&) override
166 {
167 }
168
169 void
170 setOffset(const ::Eigen::Matrix4f&, const ::Ice::Current& = ::Ice::emptyCurrent) override
171 {
172 }
173
174 // ManagedIceObject interface
175 protected:
176 void onInitComponent() override;
177 void onConnectComponent() override;
178 void onDisconnectComponent() override;
179
180 std::string
181 getDefaultName() const override
182 {
183 return "TrajectoryPlayer";
184 }
185
186 /**
187 * @see PropertyUser::createPropertyDefinitions()
188 */
195
196 private:
197 NJointTrajectoryControllerPtr
198 createTrajectoryController(std::vector<std::string>& jointNames, bool deleteIfAlreadyExist);
199 void assureTrajectoryController();
200 bool controllerExists();
201 void previewRun();
202
203 RobotUnit* robotUnit = NULL;
204 NJointTrajectoryControllerPtr jointTrajController;
205 std::string controllerName = this->getName() + "_" + "JointTrajectory";
206
207 TrajectoryPtr jointTraj;
208
209 // so far no usage -> need to implement usage of robotPoseUnit (only for simulation) -> does it really belong here?
210 TrajectoryPtr basePoseTraj;
211 bool robotPoseUnitEnabled;
212 std::string robotPoseUnitName;
213
214 double endTime;
215 double trajEndTime;
216 std::vector<std::string> usedJoints;
217
218 std::string kinematicUnitName;
219 KinematicUnitInterfacePrx kinematicUnit;
220 std::string customRootNode;
221
222 float kp;
223 float ki;
224 float kd;
225 float maxVelocity;
226 bool considerConstraintsForTrajectoryOptimization = false;
227
228 bool isPreview = false;
229 DebugDrawerInterfacePrx debugDrawer;
231
232 std::mutex dataMutex;
233 std::recursive_mutex controllerMutex;
234 bool recreateController = true;
235
236 // Component interface
237 public:
238 virtual void
239 componentPropertiesUpdated(const std::set<std::string>& changedProperties) override;
240 };
241} // namespace armarx
#define TYPEDEF_PTRS_HANDLE(T)
constexpr T c
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
std::string getName() const
Retrieve name of object.
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
PropertyDefinition< PropertyType > & defineRequiredProperty(const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
The RobotUnit class manages a robot and its controllers.
Definition RobotUnit.h:192
Ice::Double getTrajEndTime(const Ice::Current &=Ice::emptyCurrent) override
void considerConstraints(bool, const Ice::Current &=Ice::emptyCurrent) override
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void onInitComponent() override
Pure virtual hook for the subclass.
void setOffset(const ::Eigen::Matrix4f &, const ::Ice::Current &=::Ice::emptyCurrent) override
void setIsVelocityControl(bool, const Ice::Current &=Ice::emptyCurrent) override
bool startTrajectoryPlayer(const Ice::Current &=Ice::emptyCurrent) override
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &) override
Ice::Double getCurrentTime(const Ice::Current &=Ice::emptyCurrent) override
virtual void componentPropertiesUpdated(const std::set< std::string > &changedProperties) override
Implement this function if you would like to react to changes in the properties.
void loadBasePoseTraj(const TrajectoryBasePtr &basePoseTraj, const Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
Hook for subclass.
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
bool stopTrajectoryPlayer(const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
bool pauseTrajectoryPlayer(const Ice::Current &=Ice::emptyCurrent) override
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &) override
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Ice::Double getEndTime(const Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
Pure virtual hook for the subclass.
bool resetTrajectoryPlayer(bool moveToFrameZeroPose, const Ice::Current &=Ice::emptyCurrent) override
void setIsPreview(bool, const Ice::Current &=Ice::emptyCurrent) override
void reportJointAngles(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void enableRobotPoseUnit(bool, const Ice::Current &=Ice::emptyCurrent) override
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void setEndTime(Ice::Double, const Ice::Current &=Ice::emptyCurrent) override
bool setJointsInUse(const std::string &, bool, const Ice::Current &=Ice::emptyCurrent) override
void setLoopPlayback(bool loop, const Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void loadJointTraj(const TrajectoryBasePtr &jointTraj, const Ice::Current &=Ice::emptyCurrent) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.