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
42namespace armarx
43{
44 /**
45 * @class FrameTrackingPropertyDefinitions
46 * @brief
47 */
49 {
50 public:
53 {
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");
62 "KinematicUnitObserverName",
63 "KinematicUnitObserver",
64 "Name of the kinematic unit observer that should be used");
66 "Name of the yaw joint of the head.");
68 "Name of the pitch joint of the head.");
69 defineRequiredProperty<std::string>("CameraNode", "Name of the camera node.");
71 "EnableTrackingOnStartup",
72 true,
73 "Start Tracking on startup. This needs a frame to be defined.");
75 "FrameOnStartup", "", "Name of the frame that should be tracked.");
77 "RemoteGuiName",
78 "RemoteGuiProvider",
79 "Name of the remote gui. Remote gui is disabled if empty.");
81 "MaxYawVelocity",
82 0.8f,
83 "The maximum velocity the yaw joint while tracking objects.");
85 "YawAcceleration",
86 4.f,
87 "The acceleration of the yaw joint while tracking objects.");
89 "MaxPitchVelocity",
90 0.8f,
91 "The maximum velocity the pitch joint while tracking objects.");
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
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
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
FrameTrackingPropertyDefinitions(std::string prefix)
Brief description of class FrameTracking.
void onInitComponent() override
void setFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
void lookAtFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
VirtualRobot::RobotPtr localRobot
void onDisconnectComponent() override
RobotStateComponentInterfacePrx robotStateComponent
void _enableTracking(bool enable)
void enableTracking(bool enable, const Ice::Current &=Ice::emptyCurrent) override
void scanInWorkspace(const ::armarx::Vector3fSeq &points, float maxVelocity, float acceleration, const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void lookAtPointInGlobalFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
void scanInConfigurationSpace(float yawFrom, float yawTo, const ::Ice::FloatSeq &pitchValues, float velocity, const Ice::Current &=Ice::emptyCurrent) override
RemoteGui::TabProxy _guiTab
void _doPositionControl(const HeadState &headstate)
std::string getFrame(const Ice::Current &=Ice::emptyCurrent) const override
std::atomic< bool > enabled
HeadState _calculateJointAnglesContinously(const std::string &frame)
bool isLookingAtPointInGlobalFrame(const Vector3f &point, float max_diff, const Ice::Current &=Ice::emptyCurrent) override
bool _looksAtPoint(const Eigen::Vector3f &point, float max_diff)
void lookAtPointInRobotFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
VirtualRobot::RobotNodePtr headYawJoint
KinematicUnitObserverInterfacePrx kinematicUnitObserverInterfacePrx
void _lookAtFrame(const std::string &frame)
VirtualRobot::RobotNodePtr cameraNode
RemoteGuiInterfacePrx _remoteGui
SimplePeriodicTask ::pointer_type _guiTask
void _doVelocityControl(const HeadState &headstate, float maxYawVelocity, float yawAcceleration, float maxPitchVelocity, float pitchAcceleration)
void onExitComponent() override
PeriodicTask< FrameTracking >::pointer_type processorTask
void _lookAtPoint(const Eigen::Vector3f &point)
HeadState _calculateJointAngles(const Eigen::Vector3f &point)
VirtualRobot::RobotNodePtr headPitchJoint
KinematicUnitInterfacePrx kinematicUnitInterfacePrx
std::string getDefaultName() const override
void moveJointsTo(float yaw, float pitch, const Ice::Current &=Ice::emptyCurrent) override
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)
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx