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
27#include <cmath>
28#include <string>
29
30#include <IceUtil/Time.h>
31
34
37
38#include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
39
40#include <MemoryX/interface/components/WorkingMemoryInterface.h>
41
42namespace armarx
43{
44
45 /**
46 * @class PlatformUnitDynamicSimulation
47 * @brief This unit connects to the physics simulator topic (default: "Simulator") and handles platform movements.
48 *
49 * @ingroup SensorActorUnits
50 * @ingroup ArmarXSimulatorComponents
51 */
53 virtual public PlatformUnit,
54 virtual public PlatformUnitDynamicSimulationInterface
55 {
56 public:
57 // inherited from Component
58 static std::string GetDefaultName();
59 std::string
60 getDefaultName() const override
61 {
62 return GetDefaultName();
63 }
64
65 void onInitPlatformUnit() override;
66 void onStartPlatformUnit() override;
67 void onStopPlatformUnit() override;
68 void onExitPlatformUnit() override;
69
70 void simulationFunction();
71
72 // proxy implementation
73 void moveTo(Ice::Float targetPlatformPositionX,
74 Ice::Float targetPlatformPositionY,
75 Ice::Float targetPlatformRotation,
76 Ice::Float positionalAccuracy,
77 Ice::Float orientationalAccuracy,
78 const Ice::Current& c = Ice::emptyCurrent) override;
79 void move(float targetPlatformVelocityX,
80 float targetPlatformVelocityY,
81 float targetPlatformVelocityRotation,
82 const Ice::Current& c = Ice::emptyCurrent) override;
83 void moveRelative(float targetPlatformOffsetX,
84 float targetPlatformOffsetY,
85 float targetPlatformOffsetRotation,
88 const Ice::Current& c = Ice::emptyCurrent) override;
89 void setMaxVelocities(float linearVelocity,
90 float angularVelocity,
91 const Ice::Current& c = Ice::emptyCurrent) override;
92
93 /**
94 * @see PropertyUser::createPropertyDefinitions()
95 */
97
98 protected:
99 void updateCurrentPose(const PoseBasePtr& newPose);
100 void updateCurrentVelocity(const Vector3BasePtr& translationVel,
101 const Vector3BasePtr& rotationVel);
102
103 // implement SimulatorRobotListener to receive robot updates from simulator
104 void reportState(SimulatedRobotState const& state, const Ice::Current&) override;
105
106 //calc acceleration based on distance and current speed
107 Eigen::Vector3f calculateLinearVelocity(Eigen::Vector3f distance, Eigen::Vector3f curV);
108 float calculateAngularVelocity(float source, float target, float curV);
109
110 float
111 clampf(float x, float min, float max)
112 {
113 return std::max<float>(std::min<float>(x, max), min);
114 }
115
117 IceUtil::Time lastExecutionTime;
119
122 ::Ice::Float currentRotation;
123
124 ::Ice::Float targetRotation;
125
128
129 ::Ice::Float linearVelocityMin;
130 ::Ice::Float linearVelocityMax;
133
134 ::Ice::Float angularVelocityMax;
136
137 ::Ice::Float positionalAccuracy;
139
140 std::string referenceFrame;
141 std::string simulatorPrxName;
142 std::string robotName;
143 std::string platformName;
144
146
147
148 SimulatorInterfacePrx simulatorPrx;
149
151
152 // PlatformUnitInterface interface
153 public:
154 void stopPlatform(const Ice::Current& current) override;
155 };
156} // namespace armarx
constexpr T c
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
This unit connects to the physics simulator topic (default: "Simulator") and handles platform movemen...
void setMaxVelocities(float linearVelocity, float angularVelocity, const Ice::Current &c=Ice::emptyCurrent) override
float clampf(float x, float min, float max)
void moveTo(Ice::Float targetPlatformPositionX, Ice::Float targetPlatformPositionY, Ice::Float targetPlatformRotation, Ice::Float positionalAccuracy, Ice::Float orientationalAccuracy, const Ice::Current &c=Ice::emptyCurrent) override
PeriodicTask< PlatformUnitDynamicSimulation >::pointer_type simulationTask
void stopPlatform(const Ice::Current &current) override
Eigen::Vector3f calculateLinearVelocity(Eigen::Vector3f distance, Eigen::Vector3f curV)
void reportState(SimulatedRobotState const &state, const Ice::Current &) override
void updateCurrentVelocity(const Vector3BasePtr &translationVel, const Vector3BasePtr &rotationVel)
PropertyDefinitionsPtr createPropertyDefinitions() override
float calculateAngularVelocity(float source, float target, float curV)
void move(float targetPlatformVelocityX, float targetPlatformVelocityY, float targetPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
void moveRelative(float targetPlatformOffsetX, float targetPlatformOffsetY, float targetPlatformOffsetRotation, float positionalAccuracy, float orientationalAccuracy, const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
The PlatformUnit class.
The Vector3 class.
Definition Pose.h:113
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
double distance(const Point &a, const Point &b)
Definition point.hpp:95