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 
29 
30 #include <RobotAPI/interface/components/FrameTrackingInterface.h>
31 #include <RobotAPI/interface/core/RobotState.h>
32 #include <RobotAPI/interface/units/KinematicUnitInterface.h>
33 #include <RobotAPI/interface/observers/KinematicUnitObserverInterface.h>
36 
37 #include <ArmarXGui/interface/RemoteGuiInterface.h>
39 
40 #include <Eigen/Core>
41 
42 namespace armarx
43 {
44  /**
45  * @class FrameTrackingPropertyDefinitions
46  * @brief
47  */
50  {
51  public:
54  {
55  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
56  defineOptionalProperty<std::string>("KinematicUnitName", "KinematicUnit", "Name of the kinematic unit that should be used");
57  defineOptionalProperty<std::string>("KinematicUnitObserverName", "KinematicUnitObserver", "Name of the kinematic unit observer that should be used");
58  defineRequiredProperty<std::string>("HeadYawJoint", "Name of the yaw joint of the head.");
59  defineRequiredProperty<std::string>("HeadPitchJoint", "Name of the pitch joint of the head.");
60  defineRequiredProperty<std::string>("CameraNode", "Name of the camera node.");
61  defineOptionalProperty<bool>("EnableTrackingOnStartup", true, "Start Tracking on startup. This needs a frame to be defined.");
62  defineOptionalProperty<std::string>("FrameOnStartup", "", "Name of the frame that should be tracked.");
63  defineOptionalProperty<std::string>("RemoteGuiName", "RemoteGuiProvider", "Name of the remote gui. Remote gui is disabled if empty.");
64  defineOptionalProperty<float>("MaxYawVelocity", 0.8f, "The maximum velocity the yaw joint while tracking objects.");
65  defineOptionalProperty<float>("YawAcceleration", 4.f, "The acceleration of the yaw joint while tracking objects.");
66  defineOptionalProperty<float>("MaxPitchVelocity", 0.8f, "The maximum velocity the pitch joint while tracking objects.");
67  defineOptionalProperty<float>("PitchAcceleration", 4.f, "The acceleration of the pitch joint while tracking objects.");
68  }
69  };
70 
71  /**
72  * @defgroup Component-FrameTracking FrameTracking
73  * @ingroup RobotAPI-Components
74  * A description of the component FrameTracking.
75  *
76  * @class FrameTracking
77  * @ingroup Component-FrameTracking
78  * @brief Brief description of class FrameTracking.
79  *
80  * Detailed description of class FrameTracking.
81  */
82  class FrameTracking :
83  virtual public armarx::Component,
84  public FrameTrackingInterface
85  {
86  private:
87  struct HeadState
88  {
89  HeadState() = default;
90  HeadState(bool stop, float currentYawPos, float currentYawVel, float desiredYawPos, float currentPitchPos, float currentPitchVel, float desiredPitchPos)
91  :
92  stop {stop},
93  currentYawPos {currentYawPos },
94  currentYawVel {currentYawVel },
95  desiredYawPos {desiredYawPos },
96  currentPitchPos {currentPitchPos},
97  currentPitchVel {currentPitchVel},
98  desiredPitchPos {desiredPitchPos}
99  {}
100 
101  bool stop = false;
102  float currentYawPos;
103  float currentYawVel;
104  float desiredYawPos;
105  float currentPitchPos;
106  float currentPitchVel;
107  float desiredPitchPos;
108  };
109  public:
110  /**
111  * @see armarx::ManagedIceObject::getDefaultName()
112  */
113  std::string getDefaultName() const override
114  {
115  return "FrameTracking";
116  }
117 
118  protected:
119  /**
120  * @see armarx::ManagedIceObject::onInitComponent()
121  */
122  void onInitComponent() override;
123 
124  /**
125  * @see armarx::ManagedIceObject::onConnectComponent()
126  */
127  void onConnectComponent() override;
128 
129  /**
130  * @see armarx::ManagedIceObject::onDisconnectComponent()
131  */
132  void onDisconnectComponent() override;
133 
134  /**
135  * @see armarx::ManagedIceObject::onExitComponent()
136  */
137  void onExitComponent() override;
138 
139  /**
140  * @see PropertyUser::createPropertyDefinitions()
141  */
143 
144  // FrameTrackingInterface interface
145  public:
146  void enableTracking(bool enable, const Ice::Current& = Ice::emptyCurrent) override;
147  void setFrame(const std::string& frameName, const Ice::Current& = Ice::emptyCurrent) override;
148  std::string getFrame(const Ice::Current& = Ice::emptyCurrent) const override;
149 
150  void lookAtFrame(const std::string& frameName, const Ice::Current& = Ice::emptyCurrent) override;
151  void lookAtPointInGlobalFrame(const Vector3f& point, const Ice::Current& = Ice::emptyCurrent) override;
152  bool isLookingAtPointInGlobalFrame(const Vector3f& point, float max_diff, const Ice::Current& = Ice::emptyCurrent) override;
153  void lookAtPointInRobotFrame(const Vector3f& point, const Ice::Current& = Ice::emptyCurrent) override;
154 
155  void scanInConfigurationSpace(float yawFrom, float yawTo, const ::Ice::FloatSeq& pitchValues, float velocity, const Ice::Current& = Ice::emptyCurrent) override;
156  void scanInWorkspace(const ::armarx::Vector3fSeq& points, float maxVelocity, float acceleration, const Ice::Current& = Ice::emptyCurrent) override;
157  void moveJointsTo(float yaw, float pitch, const Ice::Current& = Ice::emptyCurrent) override;
158 
159  protected:
160  void process();
161 
162  void syncronizeLocalClone();
163  void _lookAtFrame(const std::string& frame);
164  void _lookAtPoint(const Eigen::Vector3f& point);
165  bool _looksAtPoint(const Eigen::Vector3f& point, float max_diff);
166  HeadState _calculateJointAnglesContinously(const std::string& frame);
167  HeadState _calculateJointAngles(const Eigen::Vector3f& point);
168  void _doVelocityControl(const HeadState& headstate, float maxYawVelocity, float yawAcceleration, float maxPitchVelocity, float pitchAcceleration);
169  void _doPositionControl(const HeadState& headstate);
170  void _enableTracking(bool enable);
171 
173  KinematicUnitInterfacePrx kinematicUnitInterfacePrx;// send commands to kinematic unit
175  KinematicUnitObserverInterfacePrx kinematicUnitObserverInterfacePrx;
176 
177  std::atomic<bool> enabled;
178  std::string frameName;
183 
185  VirtualRobot::RobotNodePtr headYawJoint;
186  VirtualRobot::RobotNodePtr headPitchJoint;
187  VirtualRobot::RobotNodePtr cameraNode;
188 
189  RemoteGuiInterfacePrx _remoteGui;
192  };
193 }
armarx::FrameTracking::enabled
std::atomic< bool > enabled
Definition: FrameTracking.h:177
RemoteRobot.h
armarx::FrameTracking::_guiTask
SimplePeriodicTask ::pointer_type _guiTask
Definition: FrameTracking.h:190
armarx::FrameTracking::_looksAtPoint
bool _looksAtPoint(const Eigen::Vector3f &point, float max_diff)
Definition: FrameTracking.cpp:526
armarx::FrameTracking::scanInWorkspace
void scanInWorkspace(const ::armarx::Vector3fSeq &points, float maxVelocity, float acceleration, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:458
armarx::FrameTracking::processorTask
PeriodicTask< FrameTracking >::pointer_type processorTask
Definition: FrameTracking.h:174
armarx::FrameTracking::lookAtPointInRobotFrame
void lookAtPointInRobotFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:348
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:290
armarx::FrameTracking::onConnectComponent
void onConnectComponent() override
Definition: FrameTracking.cpp:59
armarx::FrameTracking::_remoteGui
RemoteGuiInterfacePrx _remoteGui
Definition: FrameTracking.h:189
armarx::FrameTracking::frameName
std::string frameName
Definition: FrameTracking.h:178
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
armarx::FrameTracking::_doPositionControl
void _doPositionControl(const HeadState &headstate)
Definition: FrameTracking.cpp:624
armarx::FrameTrackingPropertyDefinitions
Definition: FrameTracking.h:48
armarx::FrameTracking::kinematicUnitObserverInterfacePrx
KinematicUnitObserverInterfacePrx kinematicUnitObserverInterfacePrx
Definition: FrameTracking.h:175
armarx::FrameTracking
Brief description of class FrameTracking.
Definition: FrameTracking.h:82
armarx::FrameTracking::scanInConfigurationSpace
void scanInConfigurationSpace(float yawFrom, float yawTo, const ::Ice::FloatSeq &pitchValues, float velocity, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:396
BasicControllers.h
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
armarx::FrameTracking::yawAcceleration
float yawAcceleration
Definition: FrameTracking.h:180
armarx::FrameTrackingPropertyDefinitions::FrameTrackingPropertyDefinitions
FrameTrackingPropertyDefinitions(std::string prefix)
Definition: FrameTracking.h:52
armarx::FrameTracking::getFrame
std::string getFrame(const Ice::Current &=Ice::emptyCurrent) const override
Definition: FrameTracking.cpp:305
armarx::FrameTracking::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FrameTracking.cpp:285
armarx::FrameTracking::lookAtFrame
void lookAtFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:310
armarx::FrameTracking::_lookAtFrame
void _lookAtFrame(const std::string &frame)
Definition: FrameTracking.cpp:514
armarx::FrameTracking::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Definition: FrameTracking.h:172
armarx::FrameTracking::_lookAtPoint
void _lookAtPoint(const Eigen::Vector3f &point)
Definition: FrameTracking.cpp:521
WidgetProxy.h
armarx::FrameTracking::headPitchJoint
VirtualRobot::RobotNodePtr headPitchJoint
Definition: FrameTracking.h:186
armarx::FrameTracking::maxYawVelocity
float maxYawVelocity
Definition: FrameTracking.h:179
armarx::FrameTracking::process
void process()
Definition: FrameTracking.cpp:493
armarx::FrameTracking::cameraNode
VirtualRobot::RobotNodePtr cameraNode
Definition: FrameTracking.h:187
TaskUtil.h
armarx::FrameTracking::_doVelocityControl
void _doVelocityControl(const HeadState &headstate, float maxYawVelocity, float yawAcceleration, float maxPitchVelocity, float pitchAcceleration)
Definition: FrameTracking.cpp:594
armarx::FrameTracking::syncronizeLocalClone
void syncronizeLocalClone()
Definition: FrameTracking.cpp:509
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::FrameTracking::pitchAcceleration
float pitchAcceleration
Definition: FrameTracking.h:182
armarx::FrameTracking::onExitComponent
void onExitComponent() override
Definition: FrameTracking.cpp:280
armarx::FrameTracking::getDefaultName
std::string getDefaultName() const override
Definition: FrameTracking.h:113
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::FrameTracking::_calculateJointAnglesContinously
HeadState _calculateJointAnglesContinously(const std::string &frame)
Definition: FrameTracking.cpp:534
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::FrameTracking::kinematicUnitInterfacePrx
KinematicUnitInterfacePrx kinematicUnitInterfacePrx
Definition: FrameTracking.h:173
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::FrameTracking::setFrame
void setFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:295
armarx::FrameTracking::maxPitchVelocity
float maxPitchVelocity
Definition: FrameTracking.h:181
armarx::FrameTracking::headYawJoint
VirtualRobot::RobotNodePtr headYawJoint
Definition: FrameTracking.h:185
armarx::FrameTracking::_calculateJointAngles
HeadState _calculateJointAngles(const Eigen::Vector3f &point)
Definition: FrameTracking.cpp:547
armarx::FrameTracking::lookAtPointInGlobalFrame
void lookAtPointInGlobalFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:326
armarx::FrameTracking::localRobot
VirtualRobot::RobotPtr localRobot
Definition: FrameTracking.h:184
armarx::FrameTracking::_enableTracking
void _enableTracking(bool enable)
Definition: FrameTracking.cpp:639
armarx::FrameTracking::moveJointsTo
void moveJointsTo(float yaw, float pitch, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:359
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::FrameTracking::isLookingAtPointInGlobalFrame
bool isLookingAtPointInGlobalFrame(const Vector3f &point, float max_diff, const Ice::Current &=Ice::emptyCurrent) override
Definition: FrameTracking.cpp:337
armarx::FrameTracking::_guiTab
RemoteGui::TabProxy _guiTab
Definition: FrameTracking.h:191
armarx::FrameTracking::onDisconnectComponent
void onDisconnectComponent() override
Definition: FrameTracking.cpp:269