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 #include <SimoxUtility/math/convert/mat3f_to_rpy.h>
25 
26 #include "PlatformUnit.h"
27 
35 
36 
37 namespace armarx
38 {
39  // ********************************************************************
40  // observer framework hooks
41  // ********************************************************************
43  {
44  // TODO: check if platformNodeName exists?
45  platformNodeName = getProperty<std::string>("PlatformName").getValue();
46 
47 
48  // register all checks
56 
57  usingTopic(platformNodeName + "State");
58  usingTopic("GlobalRobotPoseLocalization");
59  }
60 
62  {
63  // register all channels
64  offerChannel("platformPose", "Current Position of " + platformNodeName);
65  offerChannel("platformVelocity", "Current velocity of " + platformNodeName);
66  offerChannel("platformOdometryPose", "Current Odometry Position of " + platformNodeName);
67 
68  // register all data fields
69  offerDataField("platformPose", "positionX", VariantType::Float, "Current X position of " + platformNodeName + " in mm");
70  offerDataField("platformPose", "positionY", VariantType::Float, "Current Y position of " + platformNodeName + " in mm");
71  offerDataField("platformPose", "rotation", VariantType::Float, "Current Rotation of " + platformNodeName + " in radian");
72 
73  offerDataField("platformVelocity", "velocityX", VariantType::Float, "Current X velocity of " + platformNodeName + " in mm/s");
74  offerDataField("platformVelocity", "velocityY", VariantType::Float, "Current Y velocity of " + platformNodeName + " in mm/s");
75  offerDataField("platformVelocity", "velocityRotation", VariantType::Float, "Current Rotation velocity of " + platformNodeName + " in radian/s");
76 
77  offerDataField("platformOdometryPose", "positionX", VariantType::Float, "Current Odometry X position of " + platformNodeName + " in mm");
78  offerDataField("platformOdometryPose", "positionY", VariantType::Float, "Current Odometry Y position of " + platformNodeName + " in mm");
79  offerDataField("platformOdometryPose", "rotation", VariantType::Float, "Current Odometry Rotation of " + platformNodeName + " in radian");
80 
81  // odometry pose is always zero in the beginning - set it so that it can be queried
82  reportPlatformOdometryPose(0, 0, 0, Ice::emptyCurrent);
83 
84  }
85 
86  void PlatformUnitObserver::reportGlobalRobotPose(const ::armarx::TransformStamped& transformStamped, const ::Ice::Current&)
87  {
88  const Eigen::Isometry3f global_T_robot(transformStamped.transform);
89 
90  const float x = global_T_robot.translation().x();
91  const float y = global_T_robot.translation().y();
92  const float rotationAroundZ = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
93 
94  nameValueMapToDataFields("platformPose", x, y, rotationAroundZ);
95  updateChannel("platformPose");
96  }
97 
98  void PlatformUnitObserver::reportPlatformVelocity(::Ice::Float currentPlatformVelocityX, ::Ice::Float currentPlatformVelocityY, ::Ice::Float currentPlatformVelocityRotation, const Ice::Current& c)
99  {
100  setDataField("platformVelocity", "velocityX", currentPlatformVelocityX);
101  setDataField("platformVelocity", "velocityY", currentPlatformVelocityY);
102  setDataField("platformVelocity", "velocityRotation", currentPlatformVelocityRotation);
103  updateChannel("platformVelocity");
104  }
105 
106  // ********************************************************************
107  // private methods
108  // ********************************************************************
109  void PlatformUnitObserver::nameValueMapToDataFields(std::string channelName, ::Ice::Float platformPositionX, ::Ice::Float platformPositionY, ::Ice::Float platformRotation)
110  {
111  setDataField(channelName, "positionX", platformPositionX);
112  setDataField(channelName, "positionY", platformPositionY);
113  setDataField(channelName, "rotation", platformRotation);
114  }
115 
117  {
120  }
121 
122 
124  {
125  nameValueMapToDataFields("platformOdometryPose", x, y, angle);
126  updateChannel("platformOdometryPose");
127  }
128 
129 
130 }
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:715
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
ConditionCheckEquals.h
armarx::PlatformUnitObserverPropertyDefinitions
Definition: PlatformUnitObserver.h:48
ConditionCheckInRange.h
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::PlatformUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PlatformUnitObserver.cpp:116
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:109
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:465
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:248
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
PlatformUnit.h
armarx::PlatformUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: PlatformUnitObserver.cpp:61
ConditionCheckSmaller.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ConditionCheckEquals
Definition: ConditionCheckEquals.h:46
angle
double angle(const Point &a, const Point &b, const Point &c)
Definition: point.hpp:100
armarx::PlatformUnitObserver::reportPlatformVelocity
void reportPlatformVelocity(::Ice::Float currentPlatformVelocityX, ::Ice::Float currentPlatformVelocityY, ::Ice::Float currentPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PlatformUnitObserver.cpp:98
armarx::Observer::offerConditionCheck
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition: Observer.cpp:273
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:86
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
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:187
armarx::PlatformUnitObserver::reportPlatformOdometryPose
void reportPlatformOdometryPose(Ice::Float x, Ice::Float y, Ice::Float angle, const Ice::Current &) override
Definition: PlatformUnitObserver.cpp:123
ConditionCheckValid.h
armarx::ConditionCheckValid
Definition: ConditionCheckValid.h:40
armarx::PlatformUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: PlatformUnitObserver.cpp:42
PlatformUnitObserver.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ConditionCheckUpdated.h
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:126