NJointHolonomicPlatformVelocityControllerWithRamp.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 RobotAPI::ArmarXObjects::NJointHolonomicPlatformUnitVelocityPassThroughController
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
26 
28 
29 namespace armarx
30 {
33  ConfigPtrT cfg,
34  const VirtualRobot::RobotPtr&) :
35  ramp(cfg->maxPositionAcceleration, cfg->maxOrientationAcceleration)
36  {
37  target = useControlTarget(cfg->platformName, ControlModes::HolonomicPlatformVelocity)
40  << "The actuator " << cfg->platformName << " has no control mode "
41  << ControlModes::HolonomicPlatformVelocity;
42 
43  const auto sensor = useSensorValue(cfg->platformName);
44  ARMARX_CHECK_EXPRESSION(sensor) << "No sensor value for " << cfg->platformName;
47  << "Sensor value for " << cfg->platformName << " has invalid type";
48  }
49 
50  void
52  {
56  activationTime = IceUtil::Time::now();
57 
58  // init velocity ramp
60  }
61 
62  void
64  const IceUtil::Time& sensorValuesTimestamp,
65  const IceUtil::Time& timeSinceLastIteration)
66  {
67  auto commandAge = sensorValuesTimestamp - rtGetControlStruct().commandTimestamp;
68 
69  if (commandAge > maxCommandDelay && // command must be recent
70  (rtGetControlStruct().velocityX != 0.0f || rtGetControlStruct().velocityY != 0.0f ||
71  rtGetControlStruct().velocityRotation !=
72  0.0f)) // only throw error if any command is not zero
73  {
74  throw LocalException(
75  "Platform target velocity was not set for a too long time: delay: ")
76  << commandAge.toSecondsDouble()
77  << " s, max allowed delay: " << maxCommandDelay.toSecondsDouble() << " s";
78  }
79  else
80  {
81  Eigen::Vector3f result;
82  if (activationTime > rtGetControlStruct().commandTimestamp)
83  {
84  // No valid command has been specified. Sane default: come to rest.
85  const Eigen::Vector3f targetVelocity = Eigen::Vector3f::Zero();
86  result = ramp.update(targetVelocity, timeSinceLastIteration.toSecondsDouble());
87  }
88  else
89  {
90  Eigen::Vector3f x(rtGetControlStruct().velocityX,
91  rtGetControlStruct().velocityY,
92  rtGetControlStruct().velocityRotation);
93  result = ramp.update(x, timeSinceLastIteration.toSecondsDouble());
94  }
95 
96  target->velocityX = result(0);
97  target->velocityY = result(1);
98  target->velocityRotation = result(2);
99  }
100  }
101 
102  void
104  float maxPositionAcceleration,
105  float maxOrientationAcceleration)
106  {
107  ramp.setMaxPositionAcceleration(maxPositionAcceleration);
108  ramp.setMaxOrientationAcceleration(maxOrientationAcceleration);
109  }
110 
113  "NJointHolonomicPlatformVelocityControllerWithRamp");
114 
116  float maxOrientationAcceleration) :
117  maxPositionAcceleration(maxPositionAcceleration),
118  maxOrientationAcceleration(maxOrientationAcceleration)
119  {
120  }
121 
122  void
123  Cartesian2DimVelocityRamp::init(const Eigen::Vector3f& state)
124  {
125  this->state = state;
126  }
127 
128  Eigen::Vector3f
129  Cartesian2DimVelocityRamp::update(const Eigen::Vector3f& target, float dt)
130  {
131  if (dt <= 0)
132  {
133  return state;
134  }
135  Eigen::Vector3f delta = target - state;
136  float factor = 1;
137 
138  Eigen::Vector2f posDelta = delta.block<2, 1>(0, 0);
139  float posFactor = posDelta.norm() / maxPositionAcceleration / dt;
140  factor = std::max(factor, posFactor);
141 
142  float oriFactor = std::abs(delta(2)) / maxOrientationAcceleration / dt;
143  factor = std::max(factor, oriFactor);
144 
145  state += delta / factor;
146  return state;
147  }
148 
149  void
151  {
152  this->maxPositionAcceleration = maxPositionAcceleration;
153  }
154 
155  void
157  {
158  this->maxOrientationAcceleration = maxOrientationAcceleration;
159  }
160 
161 } // namespace armarx
armarx::ControlTargetHolonomicPlatformVelocity
Brief description of class ControlTargetHolonomicPlatformVelocity.
Definition: ControlTargetHolonomicPlatformVelocity.h:38
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:63
armarx::SensorValueHolonomicPlatformVelocity::velocityX
DETAIL_SensorValueBase_DEFAULT_METHOD_IMPLEMENTATION float velocityX
Definition: SensorValueHolonomicPlatform.h:33
armarx::NJointControllerRegistration
Definition: NJointControllerRegistry.h:74
armarx::NJointControllerWithTripleBuffer< NJointHolonomicPlatformVelocityControllerControlData >::rtGetControlStruct
const NJointHolonomicPlatformVelocityControllerControlData & rtGetControlStruct() const
Definition: NJointControllerWithTripleBuffer.h:32
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::Cartesian2DimVelocityRamp::update
Eigen::Vector3f update(const Eigen::Vector3f &target, float dt)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:129
armarx::NJointControllerBase::useControlTarget
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
Definition: NJointController.cpp:410
armarx::registrationNJointHolonomicPlatformVelocityControllerWithRamp
NJointControllerRegistration< NJointHolonomicPlatformVelocityControllerWithRamp > registrationNJointHolonomicPlatformVelocityControllerWithRamp("NJointHolonomicPlatformVelocityControllerWithRamp")
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::NJointHolonomicPlatformVelocityControllerWithRamp
NJointHolonomicPlatformVelocityControllerWithRamp(RobotUnit *prov, ConfigPtrT config, const VirtualRobot::RobotPtr &)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:32
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::ramp
Cartesian2DimVelocityRamp ramp
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.h:94
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::ControlTargetHolonomicPlatformVelocity::velocityRotation
float velocityRotation
Definition: ControlTargetHolonomicPlatformVelocity.h:43
armarx::SensorValueHolonomicPlatformVelocity::velocityRotation
float velocityRotation
Definition: SensorValueHolonomicPlatform.h:35
armarx::NJointHolonomicPlatformVelocityControllerInterface::maxCommandDelay
IceUtil::Time maxCommandDelay
Definition: NJointHolonomicPlatformVelocityControllerInterface.h:57
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::velocitySensor
const SensorValueHolonomicPlatformVelocity * velocitySensor
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.h:100
armarx::SensorValueHolonomicPlatformVelocity::velocityY
float velocityY
Definition: SensorValueHolonomicPlatform.h:34
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::setMaxAccelerations
void setMaxAccelerations(float maxPositionAcceleration, float maxOrientationAcceleration)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:103
armarx::SensorValueHolonomicPlatformVelocity
Definition: SensorValueHolonomicPlatform.h:30
armarx::Cartesian2DimVelocityRamp::init
void init(const Eigen::Vector3f &state)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:123
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::target
ControlTargetHolonomicPlatformVelocity * target
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.h:99
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::ControlTargetHolonomicPlatformVelocity::velocityX
float velocityX
Definition: ControlTargetHolonomicPlatformVelocity.h:41
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::ControlTargetHolonomicPlatformVelocity::velocityY
float velocityY
Definition: ControlTargetHolonomicPlatformVelocity.h:42
ExpressionException.h
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::activationTime
IceUtil::Time activationTime
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.h:97
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
NJointHolonomicPlatformVelocityControllerWithRamp.h
armarx::NJointHolonomicPlatformVelocityControllerControlData::commandTimestamp
IceUtil::Time commandTimestamp
Definition: NJointHolonomicPlatformVelocityControllerInterface.h:38
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::Cartesian2DimVelocityRamp::setMaxOrientationAcceleration
void setMaxOrientationAcceleration(float maxOrientationAcceleration)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:156
armarx::Cartesian2DimVelocityRamp::setMaxPositionAcceleration
void setMaxPositionAcceleration(float maxPositionAcceleration)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:150
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:51
NJointControllerRegistry.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::Cartesian2DimVelocityRamp::Cartesian2DimVelocityRamp
Cartesian2DimVelocityRamp(float maxPositionAcceleration, float maxOrientationAcceleration)
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.cpp:115
armarx::NJointHolonomicPlatformVelocityControllerWithRamp::activationVelocity
Eigen::Vector3f activationVelocity
Definition: NJointHolonomicPlatformVelocityControllerWithRamp.h:96
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:42
armarx::NJointControllerBase::useSensorValue
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
Definition: NJointController.cpp:383
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18