PlatformUnitDynamicSimulation.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2013-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXSimulation::units
19  * @author Manfred Kroehnert (manfred dot kroehnert at kit dot edu)
20  * @date 2013
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
28 
32 
33 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
34 
35 #include <IceUtil/Time.h>
36 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
37 
38 #include <string>
39 #include <cmath>
40 
41 namespace armarx
42 {
43 
44  /**
45  * @class PlatformUnitDynamicSimulation
46  * @brief This unit connects to the physics simulator topic (default: "Simulator") and handles platform movements.
47  *
48  * @ingroup SensorActorUnits
49  * @ingroup ArmarXSimulatorComponents
50  */
52  virtual public PlatformUnit,
53  virtual public PlatformUnitDynamicSimulationInterface
54  {
55  public:
56 
57  // inherited from Component
58  std::string getDefaultName() const override
59  {
60  return "PlatformUnit";
61  }
62 
63  void onInitPlatformUnit() override;
64  void onStartPlatformUnit() override;
65  void onStopPlatformUnit() override;
66  void onExitPlatformUnit() override;
67 
68  void simulationFunction();
69 
70  // proxy implementation
71  void moveTo(Ice::Float targetPlatformPositionX, Ice::Float targetPlatformPositionY, Ice::Float targetPlatformRotation, Ice::Float positionalAccuracy, Ice::Float orientationalAccuracy, const Ice::Current& c = Ice::emptyCurrent) override;
72  void move(float targetPlatformVelocityX, float targetPlatformVelocityY, float targetPlatformVelocityRotation, const Ice::Current& c = Ice::emptyCurrent) override;
73  void moveRelative(float targetPlatformOffsetX, float targetPlatformOffsetY, float targetPlatformOffsetRotation, float positionalAccuracy, float orientationalAccuracy, const Ice::Current& c = Ice::emptyCurrent) override;
74  void setMaxVelocities(float linearVelocity, float angularVelocity, const Ice::Current& c = Ice::emptyCurrent) override;
75 
76  /**
77  * @see PropertyUser::createPropertyDefinitions()
78  */
80 
81  protected:
82  void updateCurrentPose(const PoseBasePtr& newPose);
83  void updateCurrentVelocity(const Vector3BasePtr& translationVel, const Vector3BasePtr& rotationVel);
84 
85  // implement SimulatorRobotListener to receive robot updates from simulator
86  void reportState(SimulatedRobotState const& state, const Ice::Current&) override;
87 
88  //calc acceleration based on distance and current speed
89  Eigen::Vector3f calculateLinearVelocity(Eigen::Vector3f distance, Eigen::Vector3f curV);
90  float calculateAngularVelocity(float source, float target, float curV);
91 
92  float clampf(float x, float min, float max)
93  {
94  return std::max<float>(std::min<float>(x, max), min);
95  }
96 
97  std::mutex currentPoseMutex;
100 
104 
106 
109 
114 
117 
120 
121  std::string referenceFrame;
122  std::string simulatorPrxName;
123  std::string robotName;
124  std::string platformName;
125 
126  ControlMode platformControlMode;
127 
128 
129  SimulatorInterfacePrx simulatorPrx;
130 
132 
133  // PlatformUnitInterface interface
134  public:
135  void stopPlatform(const Ice::Current& current) override;
136  };
137 }
138 
armarx::PlatformUnitDynamicSimulation::positionalAccuracy
::Ice::Float positionalAccuracy
Definition: PlatformUnitDynamicSimulation.h:118
armarx::PlatformUnitDynamicSimulation::updateCurrentVelocity
void updateCurrentVelocity(const Vector3BasePtr &translationVel, const Vector3BasePtr &rotationVel)
Definition: PlatformUnitDynamicSimulation.cpp:317
armarx::PlatformUnitDynamicSimulation::reportState
void reportState(SimulatedRobotState const &state, const Ice::Current &) override
Definition: PlatformUnitDynamicSimulation.cpp:333
armarx::PlatformUnitDynamicSimulation::referenceFrame
std::string referenceFrame
Definition: PlatformUnitDynamicSimulation.h:121
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::PlatformUnitDynamicSimulation::currentPoseMutex
std::mutex currentPoseMutex
Definition: PlatformUnitDynamicSimulation.h:97
armarx::PlatformUnitDynamicSimulation::linearAccelerationMax
::Ice::Float linearAccelerationMax
Definition: PlatformUnitDynamicSimulation.h:112
armarx::PlatformUnitDynamicSimulation::simulatorPrxName
std::string simulatorPrxName
Definition: PlatformUnitDynamicSimulation.h:122
armarx::PlatformUnitDynamicSimulation::onStopPlatformUnit
void onStopPlatformUnit() override
Definition: PlatformUnitDynamicSimulation.cpp:77
armarx::PlatformUnitDynamicSimulation::platformOrientationOffset
::Ice::Float platformOrientationOffset
Definition: PlatformUnitDynamicSimulation.h:113
armarx::PlatformUnitDynamicSimulation::simulationFunction
void simulationFunction()
Definition: PlatformUnitDynamicSimulation.cpp:184
armarx::PlatformUnitDynamicSimulation::stopPlatform
void stopPlatform(const Ice::Current &current) override
Definition: PlatformUnitDynamicSimulation.cpp:173
Pose.h
armarx::PlatformUnitDynamicSimulation::updateCurrentPose
void updateCurrentPose(const PoseBasePtr &newPose)
Definition: PlatformUnitDynamicSimulation.cpp:287
armarx::PlatformUnitDynamicSimulation::simulationTask
PeriodicTask< PlatformUnitDynamicSimulation >::pointer_type simulationTask
Definition: PlatformUnitDynamicSimulation.h:131
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::PlatformUnitDynamicSimulation::calculateAngularVelocity
float calculateAngularVelocity(float source, float target, float curV)
Definition: PlatformUnitDynamicSimulation.cpp:151
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
PeriodicTask.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::PlatformUnitDynamicSimulation::onExitPlatformUnit
void onExitPlatformUnit() override
Definition: PlatformUnitDynamicSimulation.cpp:104
armarx::PlatformUnitDynamicSimulation::currentRotationVelocity
::Ice::Float currentRotationVelocity
Definition: PlatformUnitDynamicSimulation.h:108
armarx::PlatformUnitDynamicSimulation::orientationalAccuracy
::Ice::Float orientationalAccuracy
Definition: PlatformUnitDynamicSimulation.h:119
armarx::PlatformUnitDynamicSimulation
This unit connects to the physics simulator topic (default: "Simulator") and handles platform movemen...
Definition: PlatformUnitDynamicSimulation.h:51
armarx::PlatformUnitDynamicSimulation::angularAccelerationMax
::Ice::Float angularAccelerationMax
Definition: PlatformUnitDynamicSimulation.h:116
armarx::PlatformUnitDynamicSimulation::platformName
std::string platformName
Definition: PlatformUnitDynamicSimulation.h:124
armarx::PlatformUnitDynamicSimulation::move
void move(float targetPlatformVelocityX, float targetPlatformVelocityY, float targetPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PlatformUnitDynamicSimulation.cpp:251
armarx::PlatformUnit
The PlatformUnit class.
Definition: PlatformUnit.h:70
armarx::PlatformUnitDynamicSimulation::moveTo
void moveTo(Ice::Float targetPlatformPositionX, Ice::Float targetPlatformPositionY, Ice::Float targetPlatformRotation, Ice::Float positionalAccuracy, Ice::Float orientationalAccuracy, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PlatformUnitDynamicSimulation.cpp:237
armarx::PlatformUnitDynamicSimulation::simulatorPrx
SimulatorInterfacePrx simulatorPrx
Definition: PlatformUnitDynamicSimulation.h:129
armarx::PlatformUnitDynamicSimulation::linearVelocityMax
::Ice::Float linearVelocityMax
Definition: PlatformUnitDynamicSimulation.h:111
armarx::PlatformUnitDynamicSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PlatformUnitDynamicSimulation.cpp:365
armarx::PlatformUnitDynamicSimulation::currentVelocity
Vector3 currentVelocity
Definition: PlatformUnitDynamicSimulation.h:107
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::PlatformUnitDynamicSimulation::targetRotation
::Ice::Float targetRotation
Definition: PlatformUnitDynamicSimulation.h:105
armarx::PlatformUnitDynamicSimulation::onInitPlatformUnit
void onInitPlatformUnit() override
Definition: PlatformUnitDynamicSimulation.cpp:36
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::PlatformUnitDynamicSimulation::intervalMs
int intervalMs
Definition: PlatformUnitDynamicSimulation.h:99
armarx::PlatformUnitDynamicSimulation::currentRotation
::Ice::Float currentRotation
Definition: PlatformUnitDynamicSimulation.h:103
PlatformUnit.h
armarx::PlatformUnitDynamicSimulation::targetPosition
Vector3 targetPosition
Definition: PlatformUnitDynamicSimulation.h:102
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::PlatformUnitDynamicSimulation::moveRelative
void moveRelative(float targetPlatformOffsetX, float targetPlatformOffsetY, float targetPlatformOffsetRotation, float positionalAccuracy, float orientationalAccuracy, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PlatformUnitDynamicSimulation.cpp:266
armarx::PlatformUnitDynamicSimulation::currentPosition
Vector3 currentPosition
Definition: PlatformUnitDynamicSimulation.h:101
armarx::PlatformUnitDynamicSimulation::lastExecutionTime
IceUtil::Time lastExecutionTime
Definition: PlatformUnitDynamicSimulation.h:98
armarx::PlatformUnitDynamicSimulation::platformControlMode
ControlMode platformControlMode
Definition: PlatformUnitDynamicSimulation.h:126
armarx::PlatformUnitDynamicSimulation::onStartPlatformUnit
void onStartPlatformUnit() override
Definition: PlatformUnitDynamicSimulation.cpp:85
armarx::PlatformUnitDynamicSimulation::setMaxVelocities
void setMaxVelocities(float linearVelocity, float angularVelocity, const Ice::Current &c=Ice::emptyCurrent) override
Definition: PlatformUnitDynamicSimulation.cpp:280
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
armarx::PlatformUnitDynamicSimulation::calculateLinearVelocity
Eigen::Vector3f calculateLinearVelocity(Eigen::Vector3f distance, Eigen::Vector3f curV)
Definition: PlatformUnitDynamicSimulation.cpp:110
armarx::PlatformUnitDynamicSimulation::linearVelocityMin
::Ice::Float linearVelocityMin
Definition: PlatformUnitDynamicSimulation.h:110
armarx::PlatformUnitDynamicSimulation::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: PlatformUnitDynamicSimulation.h:58
armarx::PlatformUnitDynamicSimulation::angularVelocityMax
::Ice::Float angularVelocityMax
Definition: PlatformUnitDynamicSimulation.h:115
armarx::PlatformUnitDynamicSimulation::clampf
float clampf(float x, float min, float max)
Definition: PlatformUnitDynamicSimulation.h:92
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PlatformUnitDynamicSimulation::robotName
std::string robotName
Definition: PlatformUnitDynamicSimulation.h:123
ImportExportComponent.h