diff --git a/source/RobotAPI/libraries/RobotStatechartHelpers/CMakeLists.txt b/source/RobotAPI/libraries/RobotStatechartHelpers/CMakeLists.txt index 00cfc565c1a309780e4f3e219c84de32cc658f68..6202780fac063d4afae5c27ddfaa183b9a8efb46 100644 --- a/source/RobotAPI/libraries/RobotStatechartHelpers/CMakeLists.txt +++ b/source/RobotAPI/libraries/RobotStatechartHelpers/CMakeLists.txt @@ -28,6 +28,7 @@ set(LIB_FILES VelocityControllerHelper.cpp PositionControllerHelper.cpp ForceTorqueHelper.cpp +KinematicUnitHelper.cpp RobotNameHelper.cpp #@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.cpp ) @@ -36,6 +37,7 @@ set(LIB_HEADERS VelocityControllerHelper.h PositionControllerHelper.h ForceTorqueHelper.h +KinematicUnitHelper.h RobotNameHelper.h #@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@.h ) diff --git a/source/RobotAPI/libraries/RobotStatechartHelpers/KinematicUnitHelper.cpp b/source/RobotAPI/libraries/RobotStatechartHelpers/KinematicUnitHelper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0574ba6de8812d03cc5e0a077ae911ad089c5e1 --- /dev/null +++ b/source/RobotAPI/libraries/RobotStatechartHelpers/KinematicUnitHelper.cpp @@ -0,0 +1,59 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "KinematicUnitHelper.h" + +using namespace armarx; + +KinematicUnitHelper::KinematicUnitHelper(const KinematicUnitInterfacePrx& kinUnit) + : kinUnit(kinUnit) +{ +} + +void KinematicUnitHelper::setJointAngles(const NameValueMap& jointAngles) +{ + kinUnit->switchControlMode(MakeControlModes(jointAngles, ePositionControl)); + kinUnit->setJointAngles(jointAngles); +} + +void KinematicUnitHelper::setJointVelocities(const NameValueMap& jointVelocities) +{ + kinUnit->switchControlMode(MakeControlModes(jointVelocities, eVelocityControl)); + kinUnit->setJointVelocities(jointVelocities); +} + +void KinematicUnitHelper::setJointTorques(const NameValueMap& jointTorques) +{ + kinUnit->switchControlMode(MakeControlModes(jointTorques, eTorqueControl)); + kinUnit->setJointTorques(jointTorques); +} + +NameControlModeMap KinematicUnitHelper::MakeControlModes(const NameValueMap& jointValues, ControlMode controlMode) +{ + NameControlModeMap cm; + for (const auto& pair : jointValues) + { + cm[pair.first] = controlMode; + } + return cm; +} diff --git a/source/RobotAPI/libraries/RobotStatechartHelpers/KinematicUnitHelper.h b/source/RobotAPI/libraries/RobotStatechartHelpers/KinematicUnitHelper.h new file mode 100644 index 0000000000000000000000000000000000000000..bc28651565e0289cf65fb0ffcfcb9cf354f806ec --- /dev/null +++ b/source/RobotAPI/libraries/RobotStatechartHelpers/KinematicUnitHelper.h @@ -0,0 +1,48 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <RobotAPI/interface/units/KinematicUnitInterface.h> + +namespace armarx +{ + class KinematicUnitHelper; + typedef boost::shared_ptr<KinematicUnitHelper> KinematicUnitHelperPtr; + + class KinematicUnitHelper + { + public: + KinematicUnitHelper(const KinematicUnitInterfacePrx& kinUnit); + + void setJointAngles(const NameValueMap& jointAngles); + void setJointVelocities(const NameValueMap& jointVelocities); + void setJointTorques(const NameValueMap& jointTorques); + static NameControlModeMap MakeControlModes(const NameValueMap& jointValues, ControlMode controlMode); + + private: + KinematicUnitInterfacePrx kinUnit; + }; +}