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 
26 {
27  NJointControllerRegistration<NJointKeypointsAdmittanceMPController>
29  "NJointKeypointsAdmittanceMPController");
30 
32  const RobotUnitPtr& robotUnit,
33  const NJointControllerConfigPtr& config,
34  const VirtualRobot::RobotPtr& robot) :
35  NJointKeypointsAdmittanceController{robotUnit, config, robot}, mp::MPPool{}
36  {
37  createMPs(configFileName);
38  }
39 
40  std::string
42  {
43  return "NJointKeypointsAdmittanceMPController";
44  }
45 
46  void
48  const Ice::Current&)
49  {
52  }
53 
54  void
56  {
57  /// parse arguments and run mp
58  for (auto mp : mps)
59  {
60  if (mp.second.mp->getClassName() == "KeypointsMP")
61  {
63  std::dynamic_pointer_cast<mp::KeypointsMPInput>(mp.second.input);
64  in->keypointPosition = controlStatusBuffer.getReadBuffer().filteredKeypointPosition;
65  in->keypointVelocity = controlStatusBuffer.getReadBuffer().currentKeypointVelocity;
66  in->deltaT = controlStatusBuffer.getReadBuffer().deltaT;
67  // ARMARX_INFO << "additional Task: " << VAROUT(in->keypointPosition) << VAROUT(in->keypointVelocity) << VAROUT(in->keypointVelocity.size());
68  }
69  }
70  runMPs(true);
71  for (auto mp : mps)
72  {
73  if (mp.second.mp->getClassName() == "KeypointsMP" and !mp.second.mp->isFinished())
74  {
76  std::dynamic_pointer_cast<mp::KeypointsMPOutput>(mp.second.output);
77  getWriterControlStruct().desiredKeypointPosition = out->keypointPosition;
78  getWriterControlStruct().desiredKeypointVelocity = out->keypointVelocity;
80  // ARMARX_INFO << "additional Task: " << VAROUT(out->keypointPosition) << VAROUT(out->keypointVelocity) << VAROUT(out->keypointVelocity.size());
81  }
82  }
83  }
84 
85  void
87  {
88  ARMARX_IMPORTANT << "rt pre activate: reinitialize the mp input output, as well as the rt "
89  "related buffer values";
91  for (auto mp : mps)
92  {
93  if (mp.second.mp->getClassName() == "KeypointsMP")
94  {
95  ARMARX_IMPORTANT << "initialize input output buffers between KeypointsMP and "
96  "keypoint controllers";
97 
98  auto in = std::dynamic_pointer_cast<mp::KeypointsMPInput>(mp.second.input);
99  in->keypointPosition = controller.s.filteredKeypointPosition;
100  in->keypointVelocity = controller.s.currentKeypointVelocity;
101 
102  auto out = std::dynamic_pointer_cast<mp::KeypointsMPOutput>(mp.second.output);
103  out->keypointPosition = controller.s.filteredKeypointPosition;
104  out->keypointVelocity = controller.s.currentKeypointVelocity;
105  // ARMARX_INFO << VAROUT(in->keypointPosition) << VAROUT(in->keypointVelocity) << VAROUT(out->keypointPosition) << VAROUT(out->keypointVelocity) << VAROUT(controller.s.numPoints);
106  }
107  }
108  }
109 } // namespace armarx::control::njoint_mp_controller::task_space
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::additionalTask
void additionalTask() override
Definition: KeypointsAdmittanceController.cpp:55
armarx::control::common::mp::MPPool::reconfigureMPs
void reconfigureMPs(const MPListConfig &mpListConfig)
Definition: MPPool.cpp:80
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
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:561
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:87
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:420
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::NJointKeypointsAdmittanceMPController
NJointKeypointsAdmittanceMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: KeypointsAdmittanceController.cpp:31
controller
Definition: AddOperation.h:39
armarx::control::njoint_controller::task_space::NJointKeypointsAdmittanceController
Brief description of class NJointKeypointsAdmittanceController.
Definition: KeypointsAdmittanceController.h:50
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:86
armarx::NJointControllerWithTripleBuffer< law::KeypointsAdmittanceController::Config >::writeControlStruct
void writeControlStruct()
Definition: NJointControllerWithTripleBuffer.h:44
armarx::TripleBuffer::getReadBuffer
const T & getReadBuffer() const
Definition: TripleBuffer.h:108
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::reconfigureController
void reconfigureController(const std::string &filename, const Ice::Current &) override
Definition: KeypointsAdmittanceController.cpp:47
KeypointsAdmittanceController.h
armarx::control::njoint_mp_controller::task_space
This file is part of ArmarX.
Definition: AdmittanceController.cpp:29
armarx::control::njoint_mp_controller::task_space::NJointKeypointsAdmittanceMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: KeypointsAdmittanceController.cpp:41
armarx::control::njoint_controller::task_space::NJointKeypointsAdmittanceController::controlStatusBuffer
TripleBuffer< law::KeypointsAdmittanceController::Status > controlStatusBuffer
set buffers
Definition: KeypointsAdmittanceController.h:108
IceUtil::Handle< class RobotUnit >
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:19