NJointHolonomicPlatformRelativePositionController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, 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 ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2017
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
26 #include <Eigen/Geometry>
27 
29 
30 namespace armarx
31 {
32  NJointControllerRegistration<NJointHolonomicPlatformRelativePositionController>
34  "NJointHolonomicPlatformRelativePositionController");
35 
38  RobotUnit*,
39  const NJointHolonomicPlatformRelativePositionControllerConfigPtr& cfg,
40  const VirtualRobot::RobotPtr&) :
41  pid(cfg->p, cfg->i, cfg->d, cfg->maxVelocity, cfg->maxAcceleration)
42  {
43  const SensorValueBase* sv = useSensorValue(cfg->platformName);
44  this->sv = sv->asA<SensorValueHolonomicPlatform>();
45  target = useControlTarget(cfg->platformName, ControlModes::HolonomicPlatformVelocity)
48  << "The actuator '" << cfg->platformName << "' has no control mode "
49  << ControlModes::HolonomicPlatformVelocity;
50 
51  pid.threadSafe = false;
52 
53  oriCtrl.maxV = cfg->maxRotationVelocity;
54  oriCtrl.acceleration = cfg->maxRotationAcceleration;
55  oriCtrl.deceleration = cfg->maxRotationAcceleration;
56  oriCtrl.maxDt = 0.1;
57  oriCtrl.pid->Kp = cfg->p;
60  pid.preallocate(2);
61  }
62 
63  void
65  const IceUtil::Time&,
66  const IceUtil::Time& timeSinceLastIteration)
67  {
70  if (rtGetControlStruct().newTargetSet)
71  {
74  pid.reset();
77  }
78 
79  //position pid
80  Eigen::Vector2f relativeCurrentPosition = currentPosition - startPosition;
81  pid.update(timeSinceLastIteration.toSecondsDouble(),
82  relativeCurrentPosition,
84 
85  float relativeOrientation = currentOrientation - startOrientation;
86  //rotation pid
87  // Revert the rotation by rotating by the negative angle
88  Eigen::Vector2f localTargetVelocity =
89  Eigen::Rotation2Df(-currentOrientation) *
90  Eigen::Vector2f(pid.getControlValue()[0], pid.getControlValue()[1]);
91  //ARMARX_RT_LOGF_INFO("global target vel x: %.2f y: %2.f, local target vel x: %.2f y: %2.f rotation: %2.f", pid.getControlValue()[0], pid.getControlValue()[1], localTargetVelocity[0], localTargetVelocity[1], sv->relativePositionRotation).deactivateSpam(0.1);
92 
93  target->velocityX = localTargetVelocity[0];
94  target->velocityY = localTargetVelocity[1];
95  // target->velocityRotation = pid.getControlValue()[2] / rad2MMFactor;
96  oriCtrl.dt = timeSinceLastIteration.toSecondsDouble();
98  oriCtrl.currentPosition = relativeOrientation;
102  Eigen::Vector2f posError = pid.target.head(2) - pid.processValue.head(2);
103  if (posError.norm() < rtGetControlStruct().translationAccuracy)
104  {
105  target->velocityX = 0;
106  target->velocityY = 0;
107  }
108  //float orientationError = std::abs(oriCtrl.currentPosition - oriCtrl.targetPosition);
109  // if (orientationError < rtGetControlStruct().rotationAccuracy)
110  // {
111  // target->velocityRotation = 0;
112  // }
113  // ARMARX_INFO << deactivateSpam(0.1) << VAROUT(oriCtrl.currentPosition) << VAROUT(orientationError);
114  // ARMARX_INFO << deactivateSpam(0.1) << VAROUT(target->velocityRotation) << VAROUT(sv->velocityRotation);
115  // ARMARX_RT_LOGF_INFO("current pose x: %.2f y: %2.f, error x: %.2f y: %2.f error: %2.f ori error: %2.f", currentPose[0], currentPose[1], posError[0], posError[1], posError.norm(), orientationError).deactivateSpam(0.1);
116  // ARMARX_RT_LOGF_INFO("new target vel: %2.f, %2.f current vel: %2.f, %2.f", target->velocityX, target->velocityY, sv->velocityX, sv->velocityY).deactivateSpam(0.1);
117  }
118 
119  void
121  {
125  }
126 
127  void
129  float y,
130  float yaw,
131  float translationAccuracy,
132  float rotationAccuracy)
133  {
135  getWriterControlStruct().target << x, y;
137  getWriterControlStruct().translationAccuracy = translationAccuracy;
138  getWriterControlStruct().rotationAccuracy = rotationAccuracy;
141  // rtUpdateControlStruct();
142  }
143 
144 
145 } // namespace armarx
armarx::MultiDimPIDControllerTemplate::processValue
PIDVectorX processValue
Definition: MultiDimPIDController.h:216
armarx::PositionThroughVelocityControllerWithAccelerationBounds::acceleration
float acceleration
Definition: BasicControllers.h:306
armarx::ControlTargetHolonomicPlatformVelocity
Brief description of class ControlTargetHolonomicPlatformVelocity.
Definition: ControlTargetHolonomicPlatformVelocity.h:38
armarx::PositionThroughVelocityControllerWithAccelerationBounds::targetPosition
float targetPosition
Definition: BasicControllers.h:309
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
armarx::NJointHolonomicPlatformRelativePositionController::setTarget
void setTarget(float x, float y, float yaw, float translationAccuracy, float rotationAccuracy)
Definition: NJointHolonomicPlatformRelativePositionController.cpp:128
armarx::SensorValueHolonomicPlatform
Definition: SensorValueHolonomicPlatform.h:128
armarx::NJointControllerWithTripleBuffer< NJointHolonomicPlatformRelativePositionControllerTarget >::rtGetControlStruct
const NJointHolonomicPlatformRelativePositionControllerTarget & rtGetControlStruct() const
Definition: NJointControllerWithTripleBuffer.h:32
armarx::NJointHolonomicPlatformRelativePositionControllerTarget::target
Eigen::Vector2f target
Definition: NJointHolonomicPlatformRelativePositionController.h:63
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::MultiDimPIDControllerTemplate::reset
void reset()
Definition: MultiDimPIDController.h:196
NJointHolonomicPlatformRelativePositionController.h
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::MultiDimPIDControllerTemplate::update
void update(const double deltaSec, const PIDVectorX &measuredValue, const PIDVectorX &targetValue)
Definition: MultiDimPIDController.h:75
armarx::MultiDimPIDControllerTemplate::preallocate
void preallocate(size_t size)
Definition: MultiDimPIDController.h:66
armarx::PositionThroughVelocityControllerWithAccelerationBounds::deceleration
float deceleration
Definition: BasicControllers.h:307
armarx::NJointControllerWithTripleBuffer< NJointHolonomicPlatformRelativePositionControllerTarget >::getWriterControlStruct
NJointHolonomicPlatformRelativePositionControllerTarget & getWriterControlStruct()
Definition: NJointControllerWithTripleBuffer.h:54
armarx::SensorValueHolonomicPlatformRelativePosition::relativePositionRotation
float relativePositionRotation
Definition: SensorValueHolonomicPlatform.h:90
armarx::MultiDimPIDControllerTemplate::threadSafe
bool threadSafe
Definition: MultiDimPIDController.h:224
armarx::PositionThroughVelocityControllerWithAccelerationBoundsAndPeriodicPosition::run
float run() const
Definition: BasicControllers.cpp:902
armarx::NJointControllerWithTripleBuffer< NJointHolonomicPlatformRelativePositionControllerTarget >::LockGuardType
std::lock_guard< std::recursive_mutex > LockGuardType
Definition: NJointControllerWithTripleBuffer.h:14
armarx::ControlTargetHolonomicPlatformVelocity::velocityRotation
float velocityRotation
Definition: ControlTargetHolonomicPlatformVelocity.h:43
armarx::SensorValueHolonomicPlatformVelocity::velocityRotation
float velocityRotation
Definition: SensorValueHolonomicPlatform.h:35
armarx::NJointHolonomicPlatformRelativePositionController::startOrientation
float startOrientation
Definition: NJointHolonomicPlatformRelativePositionController.h:109
armarx::NJointHolonomicPlatformRelativePositionControllerTarget::newTargetSet
bool newTargetSet
Definition: NJointHolonomicPlatformRelativePositionController.h:67
armarx::NJointHolonomicPlatformRelativePositionController::pid
MultiDimPIDController pid
Definition: NJointHolonomicPlatformRelativePositionController.h:105
armarx::PositionThroughVelocityControllerWithAccelerationBounds::currentPosition
float currentPosition
Definition: BasicControllers.h:308
M_PI
#define M_PI
Definition: MathTools.h:17
armarx::PositionThroughVelocityControllerWithAccelerationBounds::maxV
float maxV
Definition: BasicControllers.h:305
armarx::NJointHolonomicPlatformRelativePositionControllerTarget::rotationAccuracy
float rotationAccuracy
Definition: NJointHolonomicPlatformRelativePositionController.h:66
armarx::NJointHolonomicPlatformRelativePositionController::rtRun
virtual void rtRun(const IceUtil::Time &, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointHolonomicPlatformRelativePositionController.cpp:64
armarx::NJointHolonomicPlatformRelativePositionController::sv
const SensorValueHolonomicPlatform * sv
Definition: NJointHolonomicPlatformRelativePositionController.h:104
armarx::PositionThroughVelocityControllerWithAccelerationBounds::currentV
float currentV
Definition: BasicControllers.h:304
armarx::NJointHolonomicPlatformRelativePositionController::oriCtrl
PositionThroughVelocityControllerWithAccelerationBoundsAndPeriodicPosition oriCtrl
Definition: NJointHolonomicPlatformRelativePositionController.h:106
armarx::NJointControllerWithTripleBuffer< NJointHolonomicPlatformRelativePositionControllerTarget >::writeControlStruct
void writeControlStruct()
Definition: NJointControllerWithTripleBuffer.h:44
armarx::NJointHolonomicPlatformRelativePositionController::startPosition
Eigen::Vector2f startPosition
Definition: NJointHolonomicPlatformRelativePositionController.h:108
armarx::NJointControllerWithTripleBuffer< NJointHolonomicPlatformRelativePositionControllerTarget >::controlDataMutex
MutexType controlDataMutex
Definition: NJointControllerWithTripleBuffer.h:73
armarx::ControlTargetHolonomicPlatformVelocity::velocityX
float velocityX
Definition: ControlTargetHolonomicPlatformVelocity.h:41
armarx::NJointHolonomicPlatformRelativePositionController::NJointHolonomicPlatformRelativePositionController
NJointHolonomicPlatformRelativePositionController(RobotUnit *robotUnit, const NJointHolonomicPlatformRelativePositionControllerConfigPtr &cfg, const VirtualRobot::RobotPtr &)
Definition: NJointHolonomicPlatformRelativePositionController.cpp:37
armarx::PositionThroughVelocityControllerWithAccelerationBounds::pid
std::shared_ptr< PIDController > pid
Definition: BasicControllers.h:314
armarx::NJointHolonomicPlatformRelativePositionController::currentPosition
Eigen::Vector2f currentPosition
Definition: NJointHolonomicPlatformRelativePositionController.h:108
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::PositionThroughVelocityControllerWithAccelerationBounds::maxDt
float maxDt
Definition: BasicControllers.h:303
armarx::ControlTargetHolonomicPlatformVelocity::velocityY
float velocityY
Definition: ControlTargetHolonomicPlatformVelocity.h:42
armarx::MultiDimPIDControllerTemplate::target
PIDVectorX target
Definition: MultiDimPIDController.h:217
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
armarx::PositionThroughVelocityControllerWithAccelerationBounds::accuracy
float accuracy
Definition: BasicControllers.h:313
armarx::MultiDimPIDControllerTemplate::getControlValue
const PIDVectorX & getControlValue() const
Definition: MultiDimPIDController.h:186
armarx::PositionThroughVelocityControllerWithAccelerationBoundsAndPeriodicPosition::positionPeriodLo
float positionPeriodLo
Definition: BasicControllers.h:451
armarx::registrationNJointHolonomicPlatformRelativePositionController
NJointControllerRegistration< NJointHolonomicPlatformRelativePositionController > registrationNJointHolonomicPlatformRelativePositionController("NJointHolonomicPlatformRelativePositionController")
armarx::NJointHolonomicPlatformRelativePositionController::rtPreActivateController
virtual void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointHolonomicPlatformRelativePositionController.cpp:120
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::NJointHolonomicPlatformRelativePositionController::target
ControlTargetHolonomicPlatformVelocity * target
Definition: NJointHolonomicPlatformRelativePositionController.h:107
armarx::PositionThroughVelocityControllerWithAccelerationBounds::dt
float dt
Definition: BasicControllers.h:302
armarx::NJointHolonomicPlatformRelativePositionControllerTarget::translationAccuracy
float translationAccuracy
Definition: NJointHolonomicPlatformRelativePositionController.h:65
armarx::NJointHolonomicPlatformRelativePositionController::currentOrientation
float currentOrientation
Definition: NJointHolonomicPlatformRelativePositionController.h:110
armarx::SensorValueHolonomicPlatformRelativePosition::relativePositionY
float relativePositionY
Definition: SensorValueHolonomicPlatform.h:89
armarx::NJointHolonomicPlatformRelativePositionControllerTarget::targetOrientation
float targetOrientation
Definition: NJointHolonomicPlatformRelativePositionController.h:64
NJointControllerRegistry.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
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
armarx::PositionThroughVelocityControllerWithAccelerationBoundsAndPeriodicPosition::positionPeriodHi
float positionPeriodHi
Definition: BasicControllers.h:452
armarx::SensorValueHolonomicPlatformRelativePosition::relativePositionX
DETAIL_SensorValueBase_DEFAULT_METHOD_IMPLEMENTATION float relativePositionX
Definition: SensorValueHolonomicPlatform.h:88