FrameTracking.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::FrameTracking
17  * @author Adrian Knobloch ( adrian dot knobloch at student dot kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
26 #include <Eigen/Core>
27 
31 
32 #include <ArmarXGui/interface/RemoteGuiInterface.h>
34 
36 #include <RobotAPI/interface/components/FrameTrackingInterface.h>
37 #include <RobotAPI/interface/core/RobotState.h>
38 #include <RobotAPI/interface/observers/KinematicUnitObserverInterface.h>
39 #include <RobotAPI/interface/units/KinematicUnitInterface.h>
41 
42 namespace armarx
43 {
44  /**
45  * @class FrameTrackingPropertyDefinitions
46  * @brief
47  */
49  {
50  public:
53  {
54  defineOptionalProperty<std::string>(
55  "RobotStateComponentName",
56  "RobotStateComponent",
57  "Name of the robot state component that should be used");
58  defineOptionalProperty<std::string>("KinematicUnitName",
59  "KinematicUnit",
60  "Name of the kinematic unit that should be used");
61  defineOptionalProperty<std::string>(
62  "KinematicUnitObserverName",
63  "KinematicUnitObserver",
64  "Name of the kinematic unit observer that should be used");
65  defineRequiredProperty<std::string>("HeadYawJoint",
66  "Name of the yaw joint of the head.");
67  defineRequiredProperty<std::string>("HeadPitchJoint",
68  "Name of the pitch joint of the head.");
69  defineRequiredProperty<std::string>("CameraNode", "Name of the camera node.");
70  defineOptionalProperty<bool>(
71  "EnableTrackingOnStartup",
72  true,
73  "Start Tracking on startup. This needs a frame to be defined.");
74  defineOptionalProperty<std::string>(
75  "FrameOnStartup", "", "Name of the frame that should be tracked.");
76  defineOptionalProperty<std::string>(
77  "RemoteGuiName",
78  "RemoteGuiProvider",
79  "Name of the remote gui. Remote gui is disabled if empty.");
80  defineOptionalProperty<float>(
81  "MaxYawVelocity",
82  0.8f,
83  "The maximum velocity the yaw joint while tracking objects.");
84  defineOptionalProperty<float>(
85  "YawAcceleration",
86  4.f,
87  "The acceleration of the yaw joint while tracking objects.");
88  defineOptionalProperty<float>(
89  "MaxPitchVelocity",
90  0.8f,
91  "The maximum velocity the pitch joint while tracking objects.");
92  defineOptionalProperty<float>(
93  "PitchAcceleration",
94  4.f,
95  "The acceleration of the pitch joint while tracking objects.");
96  }
97  };
98 
99  /**
100  * @defgroup Component-FrameTracking FrameTracking
101  * @ingroup RobotAPI-Components
102  * A description of the component FrameTracking.
103  *
104  * @class FrameTracking
105  * @ingroup Component-FrameTracking
106  * @brief Brief description of class FrameTracking.
107  *
108  * Detailed description of class FrameTracking.
109  */
110  class FrameTracking : virtual public armarx::Component, public FrameTrackingInterface
111  {
112  private:
113  struct HeadState
114  {
115  HeadState() = default;
116 
117  HeadState(bool stop,
118  float currentYawPos,
119  float currentYawVel,
120  float desiredYawPos,
121  float currentPitchPos,
122  float currentPitchVel,
123  float desiredPitchPos) :
124  stop{stop},
125  currentYawPos{currentYawPos},
126  currentYawVel{currentYawVel},
127  desiredYawPos{desiredYawPos},
128  currentPitchPos{currentPitchPos},
129  currentPitchVel{currentPitchVel},
130  desiredPitchPos{desiredPitchPos}
131  {
132  }
133 
134  bool stop = false;
135  float currentYawPos;
136  float currentYawVel;
137  float desiredYawPos;
138  float currentPitchPos;
139  float currentPitchVel;
140  float desiredPitchPos;
141  };
142 
143  public:
144  /**
145  * @see armarx::ManagedIceObject::getDefaultName()
146  */
147  std::string
148  getDefaultName() const override
149  {
150  return "FrameTracking";
151  }
152 
153  protected:
154  /**
155  * @see armarx::ManagedIceObject::onInitComponent()
156  */
157  void onInitComponent() override;
158 
159  /**
160  * @see armarx::ManagedIceObject::onConnectComponent()
161  */
162  void onConnectComponent() override;
163 
164  /**
165  * @see armarx::ManagedIceObject::onDisconnectComponent()
166  */
167  void onDisconnectComponent() override;
168 
169  /**
170  * @see armarx::ManagedIceObject::onExitComponent()
171  */
172  void onExitComponent() override;
173 
174  /**
175  * @see PropertyUser::createPropertyDefinitions()
176  */
178 
179  // FrameTrackingInterface interface
180  public:
181  void enableTracking(bool enable, const Ice::Current& = Ice::emptyCurrent) override;
182  void setFrame(const std::string& frameName,
183  const Ice::Current& = Ice::emptyCurrent) override;
184  std::string getFrame(const Ice::Current& = Ice::emptyCurrent) const override;
185 
186  void lookAtFrame(const std::string& frameName,
187  const Ice::Current& = Ice::emptyCurrent) override;
188  void lookAtPointInGlobalFrame(const Vector3f& point,
189  const Ice::Current& = Ice::emptyCurrent) override;
190  bool isLookingAtPointInGlobalFrame(const Vector3f& point,
191  float max_diff,
192  const Ice::Current& = Ice::emptyCurrent) override;
193  void lookAtPointInRobotFrame(const Vector3f& point,
194  const Ice::Current& = Ice::emptyCurrent) override;
195 
196  void scanInConfigurationSpace(float yawFrom,
197  float yawTo,
198  const ::Ice::FloatSeq& pitchValues,
199  float velocity,
200  const Ice::Current& = Ice::emptyCurrent) override;
201  void scanInWorkspace(const ::armarx::Vector3fSeq& points,
202  float maxVelocity,
203  float acceleration,
204  const Ice::Current& = Ice::emptyCurrent) override;
205  void moveJointsTo(float yaw, float pitch, const Ice::Current& = Ice::emptyCurrent) override;
206 
207  protected:
208  void process();
209 
210  void syncronizeLocalClone();
211  void _lookAtFrame(const std::string& frame);
212  void _lookAtPoint(const Eigen::Vector3f& point);
213  bool _looksAtPoint(const Eigen::Vector3f& point, float max_diff);
214  HeadState _calculateJointAnglesContinously(const std::string& frame);
215  HeadState _calculateJointAngles(const Eigen::Vector3f& point);
216  void _doVelocityControl(const HeadState& headstate,
217  float maxYawVelocity,
218  float yawAcceleration,
219  float maxPitchVelocity,
220  float pitchAcceleration);
221  void _doPositionControl(const HeadState& headstate);
222  void _enableTracking(bool enable);
223 
225  KinematicUnitInterfacePrx kinematicUnitInterfacePrx; // send commands to kinematic unit
227  KinematicUnitObserverInterfacePrx kinematicUnitObserverInterfacePrx;
228 
229  std::atomic<bool> enabled;
230  std::string frameName;
235 
237  VirtualRobot::RobotNodePtr headYawJoint;
238  VirtualRobot::RobotNodePtr headPitchJoint;
239  VirtualRobot::RobotNodePtr cameraNode;
240 
241  RemoteGuiInterfacePrx _remoteGui;
244  };
245 } // namespace armarx
armarx::FrameTracking::enabled
std::atomic< bool > enabled
Definition: FrameTracking.h:229
RemoteRobot.h
armarx::FrameTracking::_guiTask
SimplePeriodicTask ::pointer_type _guiTask
Definition: FrameTracking.h:242
armarx::FrameTracking::_looksAtPoint
bool _looksAtPoint(const Eigen::Vector3f &point, float max_diff)
Definition: FrameTracking.cpp:619
armarx::FrameTracking::scanInWorkspace
void scanInWorkspace(const ::armarx::Vector3fSeq &points, float maxVelocity, float acceleration, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:539
armarx::FrameTracking::processorTask
PeriodicTask< FrameTracking >::pointer_type processorTask
Definition: FrameTracking.h:226
armarx::FrameTracking::lookAtPointInRobotFrame
void lookAtPointInRobotFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:418
armarx::FrameTracking::onInitComponent
void onInitComponent() override
Definition: FrameTracking.cpp:38
armarx::FrameTracking::enableTracking
void enableTracking(bool enable, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:352
armarx::FrameTracking::onConnectComponent
void onConnectComponent() override
Definition: FrameTracking.cpp:59
armarx::FrameTracking::_remoteGui
RemoteGuiInterfacePrx _remoteGui
Definition: FrameTracking.h:241
armarx::FrameTracking::frameName
std::string frameName
Definition: FrameTracking.h:230
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
PeriodicTask.h
armarx::FrameTracking::_doPositionControl
void _doPositionControl(const HeadState &headstate)
Definition: FrameTracking.cpp:735
armarx::FrameTrackingPropertyDefinitions
Definition: FrameTracking.h:48
armarx::FrameTracking::kinematicUnitObserverInterfacePrx
KinematicUnitObserverInterfacePrx kinematicUnitObserverInterfacePrx
Definition: FrameTracking.h:227
armarx::FrameTracking
Brief description of class FrameTracking.
Definition: FrameTracking.h:110
armarx::FrameTracking::scanInConfigurationSpace
void scanInConfigurationSpace(float yawFrom, float yawTo, const ::Ice::FloatSeq &pitchValues, float velocity, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:471
BasicControllers.h
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
armarx::FrameTracking::yawAcceleration
float yawAcceleration
Definition: FrameTracking.h:232
armarx::FrameTrackingPropertyDefinitions::FrameTrackingPropertyDefinitions
FrameTrackingPropertyDefinitions(std::string prefix)
Definition: FrameTracking.h:51
armarx::FrameTracking::getFrame
std::string getFrame(const Ice::Current &=Ice::emptyCurrent) const override
Definition: FrameTracking.cpp:369
armarx::FrameTracking::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FrameTracking.cpp:345
armarx::FrameTracking::lookAtFrame
void lookAtFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:375
armarx::FrameTracking::_lookAtFrame
void _lookAtFrame(const std::string &frame)
Definition: FrameTracking.cpp:605
armarx::FrameTracking::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Definition: FrameTracking.h:224
armarx::FrameTracking::_lookAtPoint
void _lookAtPoint(const Eigen::Vector3f &point)
Definition: FrameTracking.cpp:613
WidgetProxy.h
armarx::FrameTracking::headPitchJoint
VirtualRobot::RobotNodePtr headPitchJoint
Definition: FrameTracking.h:238
armarx::FrameTracking::maxYawVelocity
float maxYawVelocity
Definition: FrameTracking.h:231
armarx::FrameTracking::process
void process()
Definition: FrameTracking.cpp:582
armarx::FrameTracking::cameraNode
VirtualRobot::RobotNodePtr cameraNode
Definition: FrameTracking.h:239
TaskUtil.h
armarx::FrameTracking::_doVelocityControl
void _doVelocityControl(const HeadState &headstate, float maxYawVelocity, float yawAcceleration, float maxPitchVelocity, float pitchAcceleration)
Definition: FrameTracking.cpp:694
armarx::FrameTracking::syncronizeLocalClone
void syncronizeLocalClone()
Definition: FrameTracking.cpp:599
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::FrameTracking::pitchAcceleration
float pitchAcceleration
Definition: FrameTracking.h:234
armarx::FrameTracking::onExitComponent
void onExitComponent() override
Definition: FrameTracking.cpp:340
armarx::FrameTracking::getDefaultName
std::string getDefaultName() const override
Definition: FrameTracking.h:148
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::FrameTracking::_calculateJointAnglesContinously
HeadState _calculateJointAnglesContinously(const std::string &frame)
Definition: FrameTracking.cpp:628
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::FrameTracking::kinematicUnitInterfacePrx
KinematicUnitInterfacePrx kinematicUnitInterfacePrx
Definition: FrameTracking.h:225
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::FrameTracking::setFrame
void setFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:358
armarx::FrameTracking::maxPitchVelocity
float maxPitchVelocity
Definition: FrameTracking.h:233
armarx::FrameTracking::headYawJoint
VirtualRobot::RobotNodePtr headYawJoint
Definition: FrameTracking.h:237
armarx::FrameTracking::_calculateJointAngles
HeadState _calculateJointAngles(const Eigen::Vector3f &point)
Definition: FrameTracking.cpp:643
armarx::FrameTracking::lookAtPointInGlobalFrame
void lookAtPointInGlobalFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:392
armarx::FrameTracking::localRobot
VirtualRobot::RobotPtr localRobot
Definition: FrameTracking.h:236
armarx::FrameTracking::_enableTracking
void _enableTracking(bool enable)
Definition: FrameTracking.cpp:754
armarx::FrameTracking::moveJointsTo
void moveJointsTo(float yaw, float pitch, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:430
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::FrameTracking::isLookingAtPointInGlobalFrame
bool isLookingAtPointInGlobalFrame(const Vector3f &point, float max_diff, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:404
armarx::FrameTracking::_guiTab
RemoteGui::TabProxy _guiTab
Definition: FrameTracking.h:243
armarx::FrameTracking::onDisconnectComponent
void onDisconnectComponent() override
Definition: FrameTracking.cpp:329