Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <telekyb_calculus/Potentials/PotentialFunction.hpp>
00009
00010 #include <telekyb_defines/telekyb_defines.hpp>
00011
00012 #include <ros/console.h>
00013
00014 namespace TELEKYB_NAMESPACE {
00015
00016 PotentialFunction::PotentialFunction(const std::string& potentialFunctionName_, PotentialFunctionType type_)
00017 : options(potentialFunctionName_), type(type_)
00018 {
00019
00020
00021 if (options.tPotFuncZeroD->isOnInitialValue()) {
00022 ROS_ERROR("%s on initial value! This is most certainly not what you want!", options.tPotFuncZeroD->getNSName().c_str());
00023 }
00024 if (options.tPotFuncInfD->isOnInitialValue()) {
00025 ROS_ERROR("%s on initial value! This is most certainly not what you want!", options.tPotFuncInfD->getNSName().c_str());
00026 }
00027 if (options.tPotFuncSatValue->isOnInitialValue()) {
00028 ROS_ERROR("%s on initial value! This is most certainly not what you want!", options.tPotFuncSatValue->getNSName().c_str());
00029 }
00030
00031
00032
00033
00034
00035
00036 updateBoundsValues();
00037
00038
00039 registerOptionListeners();
00040 }
00041 PotentialFunction:: PotentialFunction(const std::string& potentialFunctionName_, PotentialFunctionType type_,
00042 double tPotFuncZeroD_, double tPotFuncInfD_, double tPotFuncSatValue_, double tPotFuncGain_)
00043 : options(potentialFunctionName_), type(type_)
00044 {
00045
00046
00047 options.tPotFuncZeroD->setValue(tPotFuncZeroD_);
00048 options.tPotFuncInfD->setValue(tPotFuncInfD_);
00049 options.tPotFuncSatValue->setValue(tPotFuncSatValue_);
00050 options.tPotFuncGain->setValue(tPotFuncGain_);
00051
00052
00053 updateBoundsValues();
00054
00055
00056 registerOptionListeners();
00057 }
00058
00059 PotentialFunction::~PotentialFunction() {
00060 options.tPotFuncZeroD->unRegisterOptionListener(this);
00061 options.tPotFuncInfD->unRegisterOptionListener(this);
00062 options.tPotFuncSatValue->unRegisterOptionListener(this);
00063 options.tPotFuncGain->unRegisterOptionListener(this);
00064 }
00065
00066 void PotentialFunction::registerOptionListeners() {
00067 options.tPotFuncZeroD->registerOptionListener(this);
00068 options.tPotFuncInfD->registerOptionListener(this);
00069 options.tPotFuncSatValue->registerOptionListener(this);
00070 options.tPotFuncGain->registerOptionListener(this);
00071 }
00072
00073 void PotentialFunction::updateBoundsValues() {
00074
00075
00076
00077 double zeroDistance = options.tPotFuncZeroD->getValue();
00078 double infDistance = options.tPotFuncInfD->getValue();
00079
00080
00081
00082
00083 if (zeroDistance < infDistance && type == PotentialFunctionType::Repulsive) {
00084 ROS_ERROR("Potential Function Type %s, with d_0(%f) < d_inf(%f). Inverting...", type.str(), zeroDistance, infDistance);
00085 options.tPotFuncZeroD->setValue(infDistance);
00086 options.tPotFuncInfD->setValue(zeroDistance);
00087 } else if (infDistance < zeroDistance && type == PotentialFunctionType::Attractive) {
00088 ROS_ERROR("Potential Function Type %s, with d_0(%f) > d_inf(%f). Inverting...", type.str(), zeroDistance, infDistance);
00089 options.tPotFuncZeroD->setValue(infDistance);
00090 options.tPotFuncInfD->setValue(zeroDistance);
00091 } else {
00092
00093 }
00094 }
00095
00096 PotentialFunctionType PotentialFunction::getType() const {
00097 return type;
00098 }
00099
00100 PotentialFunctionOptions& PotentialFunction::getOptions() {
00101 return options;
00102 }
00103
00104 double PotentialFunction::getPotential(double d) const {
00105 if (type == PotentialFunctionType::Repulsive) {
00106
00107 if (d < options.tPotFuncInfD->getValue()) {
00108 return options.tPotFuncSatValue->getValue();
00109 } else if (d >= options.tPotFuncZeroD->getValue()) {
00110 return 0.0;
00111 } else {
00112 return std::min(getPotentialImpl(d), options.tPotFuncSatValue->getValue());
00113 }
00114
00115 } else {
00116
00117 if (d <= options.tPotFuncZeroD->getValue()) {
00118 return 0.0;
00119 } else if (d > options.tPotFuncInfD->getValue()) {
00120 return options.tPotFuncSatValue->getValue();
00121 } else {
00122 return std::min(getPotentialImpl(d), options.tPotFuncSatValue->getValue());
00123 }
00124 }
00125 }
00126
00127 void PotentialFunction::optionDidChange(const Option<double>* option_) {
00128 if (option_ == options.tPotFuncZeroD) {
00129 ROS_WARN("Changed tPotFuncZeroD");
00130 updateBoundsValues();
00131 } else if (option_ == options.tPotFuncInfD) {
00132 ROS_WARN("Changed tPotFuncInfD");
00133 updateBoundsValues();
00134 } else {
00135
00136 }
00137 }
00138
00139 }
00140