PlatformUnitObserver.cpp
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 ArmarX::Core
17 * @author Kai Welke (welke _at_ kit _dot_ edu)
18 * @date 2011 Kai Welke
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "PlatformUnitObserver.h"
24 
25 #include <SimoxUtility/math/convert/mat3f_to_rpy.h>
26 
34 
35 #include "PlatformUnit.h"
36 
37 namespace armarx
38 {
39  // ********************************************************************
40  // observer framework hooks
41  // ********************************************************************
42  void
44  {
45  // TODO: check if platformNodeName exists?
46  platformNodeName = getProperty<std::string>("PlatformName").getValue();
47 
48 
49  // register all checks
57 
58  usingTopic(platformNodeName + "State");
59  usingTopic("GlobalRobotPoseLocalization");
60  }
61 
62  void
64  {
65  // register all channels
66  offerChannel("platformPose", "Current Position of " + platformNodeName);
67  offerChannel("platformVelocity", "Current velocity of " + platformNodeName);
68  offerChannel("platformOdometryPose", "Current Odometry Position of " + platformNodeName);
69 
70  // register all data fields
71  offerDataField("platformPose",
72  "positionX",
74  "Current X position of " + platformNodeName + " in mm");
75  offerDataField("platformPose",
76  "positionY",
78  "Current Y position of " + platformNodeName + " in mm");
79  offerDataField("platformPose",
80  "rotation",
82  "Current Rotation of " + platformNodeName + " in radian");
83 
84  offerDataField("platformVelocity",
85  "velocityX",
87  "Current X velocity of " + platformNodeName + " in mm/s");
88  offerDataField("platformVelocity",
89  "velocityY",
91  "Current Y velocity of " + platformNodeName + " in mm/s");
92  offerDataField("platformVelocity",
93  "velocityRotation",
95  "Current Rotation velocity of " + platformNodeName + " in radian/s");
96 
97  offerDataField("platformOdometryPose",
98  "positionX",
100  "Current Odometry X position of " + platformNodeName + " in mm");
101  offerDataField("platformOdometryPose",
102  "positionY",
104  "Current Odometry Y position of " + platformNodeName + " in mm");
105  offerDataField("platformOdometryPose",
106  "rotation",
108  "Current Odometry Rotation of " + platformNodeName + " in radian");
109 
110  // odometry pose is always zero in the beginning - set it so that it can be queried
111  reportPlatformOdometryPose(0, 0, 0, Ice::emptyCurrent);
112  }
113 
114  void
115  PlatformUnitObserver::reportGlobalRobotPose(const ::armarx::TransformStamped& transformStamped,
116  const ::Ice::Current&)
117  {
118  const Eigen::Isometry3f global_T_robot(transformStamped.transform);
119 
120  const float x = global_T_robot.translation().x();
121  const float y = global_T_robot.translation().y();
122  const float rotationAroundZ = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
123 
124  nameValueMapToDataFields("platformPose", x, y, rotationAroundZ);
125  updateChannel("platformPose");
126  }
127 
128  void
130  ::Ice::Float currentPlatformVelocityY,
131  ::Ice::Float currentPlatformVelocityRotation,
132  const Ice::Current& c)
133  {
134  setDataField("platformVelocity", "velocityX", currentPlatformVelocityX);
135  setDataField("platformVelocity", "velocityY", currentPlatformVelocityY);
136  setDataField("platformVelocity", "velocityRotation", currentPlatformVelocityRotation);
137  updateChannel("platformVelocity");
138  }
139 
140  // ********************************************************************
141  // private methods
142  // ********************************************************************
143  void
145  ::Ice::Float platformPositionX,
146  ::Ice::Float platformPositionY,
147  ::Ice::Float platformRotation)
148  {
149  setDataField(channelName, "positionX", platformPositionX);
150  setDataField(channelName, "positionY", platformPositionY);
151  setDataField(channelName, "rotation", platformRotation);
152  }
153 
156  {
157  return PropertyDefinitionsPtr(
159  }
160 
161  void
163  Ice::Float y,
165  const Ice::Current&)
166  {
167  nameValueMapToDataFields("platformOdometryPose", x, y, angle);
168  updateChannel("platformOdometryPose");
169  }
170 
171 
172 } // namespace armarx
armarx::Observer::updateChannel
void updateChannel(const std::string &channelName, const std::set< std::string > &updatedDatafields=std::set< std::string >())
Update all conditions for a channel.
Definition: Observer.cpp:788
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
ConditionCheckEquals.h
armarx::PlatformUnitObserverPropertyDefinitions
Definition: PlatformUnitObserver.h:47
ConditionCheckInRange.h
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::PlatformUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PlatformUnitObserver.cpp:155
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
armarx::PlatformUnitObserver::nameValueMapToDataFields
void nameValueMapToDataFields(std::string channelName, ::Ice::Float platformPositionX, ::Ice::Float platformPositionY, ::Ice::Float platformRotation)
Definition: PlatformUnitObserver.cpp:144
armarx::ConditionCheckEqualsWithTolerance
Definition: ConditionCheckEqualsWithTolerance.h:41
armarx::Observer::setDataField
void setDataField(const std::string &channelName, const std::string &datafieldName, const Variant &value, bool triggerFilterUpdate=true)
set datafield with datafieldName and in channel channelName
Definition: Observer.cpp:508
ConditionCheckEqualsWithTolerance.h
armarx::ConditionCheckInRange
Definition: ConditionCheckInRange.h:41
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:254
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
PlatformUnit.h
armarx::PlatformUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: PlatformUnitObserver.cpp:63
ConditionCheckSmaller.h
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::ConditionCheckEquals
Definition: ConditionCheckEquals.h:46
angle
double angle(const Point &a, const Point &b, const Point &c)
Definition: point.hpp:109
armarx::PlatformUnitObserver::reportPlatformVelocity
void reportPlatformVelocity(::Ice::Float currentPlatformVelocityX, ::Ice::Float currentPlatformVelocityY, ::Ice::Float currentPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PlatformUnitObserver.cpp:129
armarx::Observer::offerConditionCheck
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition: Observer.cpp:301
ConditionCheckLarger.h
armarx::ConditionCheckLarger
Definition: ConditionCheckLarger.h:40
armarx::PlatformUnitObserver::reportGlobalRobotPose
void reportGlobalRobotPose(const ::armarx::TransformStamped &, const ::Ice::Current &=::Ice::emptyCurrent) override
Definition: PlatformUnitObserver.cpp:115
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::Observer::offerDataField
void offerDataField(std::string channelName, std::string datafieldName, VariantTypeId type, std::string description)
Offer a datafield without default value.
Definition: Observer.cpp:201
armarx::PlatformUnitObserver::reportPlatformOdometryPose
void reportPlatformOdometryPose(Ice::Float x, Ice::Float y, Ice::Float angle, const Ice::Current &) override
Definition: PlatformUnitObserver.cpp:162
ConditionCheckValid.h
armarx::ConditionCheckValid
Definition: ConditionCheckValid.h:40
armarx::PlatformUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: PlatformUnitObserver.cpp:43
PlatformUnitObserver.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ConditionCheckUpdated.h
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:131