KeypointsAdmittanceController.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 TaskSpaceActiveImpedanceControl::ArmarXObjects::NJointTaskSpaceImpedanceController
17  * @author zhou ( you dot zhou at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
25 
27 {
28 NJointControllerRegistration<NJointKeypointsAdmittanceMPController> registrationControllerNJointKeypointsAdmittanceMPController("NJointKeypointsAdmittanceMPController");
29 
31  const RobotUnitPtr& robotUnit,
32  const NJointControllerConfigPtr& config,
33  const VirtualRobot::RobotPtr& robot):
34  NJointKeypointsAdmittanceController{robotUnit, config, robot},
35  mp::MPPool{}
36 {
37  createMPs(configFileName);
38 }
39 
40 std::string NJointKeypointsAdmittanceMPController::getClassName(const Ice::Current &) const
41 {
42  return "NJointKeypointsAdmittanceMPController";
43 }
44 
45 void NJointKeypointsAdmittanceMPController::reconfigureController(const std::string &filename, const Ice::Current &)
46 {
49 }
50 
51 
53 {
54  /// parse arguments and run mp
55  for (auto mp: mps)
56  {
57  if (mp.second.mp->getClassName() == "KeypointsMP")
58  {
59  mp::KeypointsMPInputPtr in = std::dynamic_pointer_cast<mp::KeypointsMPInput>(mp.second.input);
60  in->keypointPosition = controlStatusBuffer.getReadBuffer().filteredKeypointPosition;
61  in->keypointVelocity = controlStatusBuffer.getReadBuffer().currentKeypointVelocity;
62  in->deltaT = controlStatusBuffer.getReadBuffer().deltaT;
63  // ARMARX_INFO << "additional Task: " << VAROUT(in->keypointPosition) << VAROUT(in->keypointVelocity) << VAROUT(in->keypointVelocity.size());
64  }
65  }
66  runMPs(true);
67  for (auto mp: mps)
68  {
69  if (mp.second.mp->getClassName() == "KeypointsMP" and !mp.second.mp->isFinished())
70  {
71  mp::KeypointsMPOutputPtr out = std::dynamic_pointer_cast<mp::KeypointsMPOutput>(mp.second.output);
72  getWriterControlStruct().desiredKeypointPosition = out->keypointPosition;
73  getWriterControlStruct().desiredKeypointVelocity = out->keypointVelocity;
75  // ARMARX_INFO << "additional Task: " << VAROUT(out->keypointPosition) << VAROUT(out->keypointVelocity) << VAROUT(out->keypointVelocity.size());
76  }
77  }
78 }
79 
81 {
82  ARMARX_IMPORTANT << "rt pre activate: reinitialize the mp input output, as well as the rt related buffer values";
84  for (auto mp: mps)
85  {
86  if (mp.second.mp->getClassName() == "KeypointsMP")
87  {
88  ARMARX_IMPORTANT << "initialize input output buffers between KeypointsMP and keypoint controllers";
89 
90  auto in = std::dynamic_pointer_cast<mp::KeypointsMPInput>(mp.second.input);
91  in->keypointPosition = controller.s.filteredKeypointPosition;
92  in->keypointVelocity = controller.s.currentKeypointVelocity;
93 
94  auto out = std::dynamic_pointer_cast<mp::KeypointsMPOutput>(mp.second.output);
95  out->keypointPosition = controller.s.filteredKeypointPosition;
96  out->keypointVelocity = controller.s.currentKeypointVelocity;
97  // ARMARX_INFO << VAROUT(in->keypointPosition) << VAROUT(in->keypointVelocity) << VAROUT(out->keypointPosition) << VAROUT(out->keypointVelocity) << VAROUT(controller.s.numPoints);
98  }
99  }
100 }
101 } /// namespace armarx::control::njoint_mp_controller::task_space
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::additionalTask
void additionalTask() override
Definition: KeypointsAdmittanceController.cpp:52
armarx::control::common::mp::MPPool::reconfigureMPs
void reconfigureMPs(const MPListConfig &mpListConfig)
Definition: MPPool.cpp:76
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::control::njoint_mp_controller::task_space::registrationControllerNJointKeypointsAdmittanceMPController
NJointControllerRegistration< NJointKeypointsAdmittanceMPController > registrationControllerNJointKeypointsAdmittanceMPController("NJointKeypointsAdmittanceMPController")
armarx::control::njoint_controller::task_space::NJointKeypointsAdmittanceController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: KeypointsAdmittanceController.cpp:453
armarx::NJointControllerWithTripleBuffer< law::KeypointsAdmittanceController::Config >::getWriterControlStruct
law::KeypointsAdmittanceController::Config & getWriterControlStruct()
Definition: NJointControllerWithTripleBuffer.h:54
armarx::control::common::mp::MPPool::runMPs
void runMPs(const bool rtSafe)
Definition: MPPool.cpp:83
armarx::control::njoint_controller::task_space::NJointKeypointsAdmittanceController::reconfigureController
void reconfigureController(const std::string &filename, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
set control target
Definition: KeypointsAdmittanceController.cpp:331
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::NJointKeypointsAdmittanceMPController
NJointKeypointsAdmittanceMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: KeypointsAdmittanceController.cpp:30
controller
Definition: AddOperation.h:39
armarx::control::njoint_controller::task_space::NJointKeypointsAdmittanceController
Brief description of class NJointKeypointsAdmittanceController.
Definition: KeypointsAdmittanceController.h:53
armarx::control::common::mp::KeypointsMPOutputPtr
std::shared_ptr< KeypointsMPOutput > KeypointsMPOutputPtr
Definition: KeypointsMP.h:46
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: KeypointsAdmittanceController.cpp:80
armarx::NJointControllerWithTripleBuffer< law::KeypointsAdmittanceController::Config >::writeControlStruct
void writeControlStruct()
Definition: NJointControllerWithTripleBuffer.h:44
armarx::TripleBuffer::getReadBuffer
const T & getReadBuffer() const
Definition: TripleBuffer.h:102
filename
std::string filename
Definition: VisualizationRobot.cpp:83
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::reconfigureController
void reconfigureController(const std::string &filename, const Ice::Current &) override
Definition: KeypointsAdmittanceController.cpp:45
KeypointsAdmittanceController.h
armarx::control::njoint_mp_controller::task_space
This file is part of ArmarX.
Definition: AdmittanceController.cpp:26
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: KeypointsAdmittanceController.cpp:40
armarx::control::njoint_controller::task_space::NJointKeypointsAdmittanceController::controlStatusBuffer
TripleBuffer< law::KeypointsAdmittanceController::Status > controlStatusBuffer
set buffers
Definition: KeypointsAdmittanceController.h:99
armarx::control::common::mp::MPPool
Definition: MPPool.h:47
armarx::control::common::mp::MPPool::mps
std::map< std::string, MPInputOutput > mps
Definition: MPPool.h:127
armarx::control::common::mp::KeypointsMPInputPtr
std::shared_ptr< KeypointsMPInput > KeypointsMPInputPtr
Definition: KeypointsMP.h:45
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18