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 std::string
59 getDefaultName() const override
60 {
61 return "PlatformUnit";
62 }
63
64 void onInitPlatformUnit() override;
65 void onStartPlatformUnit() override;
66 void onStopPlatformUnit() override;
67 void onExitPlatformUnit() override;
68
69 void simulationFunction();
70
71 // proxy implementation
72 void moveTo(Ice::Float targetPlatformPositionX,
73 Ice::Float targetPlatformPositionY,
74 Ice::Float targetPlatformRotation,
75 Ice::Float positionalAccuracy,
76 Ice::Float orientationalAccuracy,
77 const Ice::Current& c = Ice::emptyCurrent) override;
78 void move(float targetPlatformVelocityX,
79 float targetPlatformVelocityY,
80 float targetPlatformVelocityRotation,
81 const Ice::Current& c = Ice::emptyCurrent) override;
82 void moveRelative(float targetPlatformOffsetX,
83 float targetPlatformOffsetY,
84 float targetPlatformOffsetRotation,
87 const Ice::Current& c = Ice::emptyCurrent) override;
88 void setMaxVelocities(float linearVelocity,
89 float angularVelocity,
90 const Ice::Current& c = Ice::emptyCurrent) override;
91
92 /**
93 * @see PropertyUser::createPropertyDefinitions()
94 */
96
97 protected:
98 void updateCurrentPose(const PoseBasePtr& newPose);
99 void updateCurrentVelocity(const Vector3BasePtr& translationVel,
100 const Vector3BasePtr& rotationVel);
101
102 // implement SimulatorRobotListener to receive robot updates from simulator
103 void reportState(SimulatedRobotState const& state, const Ice::Current&) override;
104
105 //calc acceleration based on distance and current speed
106 Eigen::Vector3f calculateLinearVelocity(Eigen::Vector3f distance, Eigen::Vector3f curV);
107 float calculateAngularVelocity(float source, float target, float curV);
108
109 float
110 clampf(float x, float min, float max)
111 {
112 return std::max<float>(std::min<float>(x, max), min);
113 }
114
116 IceUtil::Time lastExecutionTime;
118
121 ::Ice::Float currentRotation;
122
123 ::Ice::Float targetRotation;
124
127
128 ::Ice::Float linearVelocityMin;
129 ::Ice::Float linearVelocityMax;
132
133 ::Ice::Float angularVelocityMax;
135
136 ::Ice::Float positionalAccuracy;
138
139 std::string referenceFrame;
140 std::string simulatorPrxName;
141 std::string robotName;
142 std::string platformName;
143
145
146
147 SimulatorInterfacePrx simulatorPrx;
148
150
151 // PlatformUnitInterface interface
152 public:
153 void stopPlatform(const Ice::Current& current) override;
154 };
155} // 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