KeypointsImpedanceController.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<NJointKeypointsImpedanceMPController>
29  "NJointKeypointsImpedanceMPController");
30 
32  const RobotUnitPtr& robotUnit,
33  const NJointControllerConfigPtr& config,
34  const VirtualRobot::RobotPtr& robot) :
36  {
37  createMPs(configFileName);
38  }
39 
40  std::string
42  {
43  return "NJointKeypointsImpedanceMPController";
44  }
45 
46  void
48  const Ice::Current&)
49  {
50  NJointKeypointsImpedanceController::reconfigureController(filename);
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  else if (mp.second.mp->getClassName() == "JSMP")
70  {
71  mp::JSMPInputPtr in = std::dynamic_pointer_cast<mp::JSMPInput>(mp.second.input);
72  in->angleRadian = controlStatusBuffer.getReadBuffer().qpos;
73  in->angularVel = controlStatusBuffer.getReadBuffer().qvel;
74  in->deltaT = controlStatusBuffer.getReadBuffer().deltaT;
75  }
76  }
77  runMPs(true);
78  for (auto mp : mps)
79  {
80  if (mp.second.mp->getClassName() == "KeypointsMP" and !mp.second.mp->isFinished())
81  {
83  std::dynamic_pointer_cast<mp::KeypointsMPOutput>(mp.second.output);
84  getWriterControlStruct().desiredKeypointPosition = out->keypointPosition;
85  getWriterControlStruct().desiredKeypointVelocity = out->keypointVelocity;
86  writeControlStruct();
87  // ARMARX_INFO << "additional Task: " << VAROUT(out->keypointPosition) << VAROUT(out->keypointVelocity) << VAROUT(out->keypointVelocity.size());
88  }
89  else if (mp.second.mp->getClassName() == "JSMP" and !mp.second.mp->isFinished())
90  {
91  mp::JSMPOutputPtr out = std::dynamic_pointer_cast<mp::JSMPOutput>(mp.second.output);
92  getWriterControlStruct().desiredNullspaceJointAngles = out->angleRadian;
93  writeControlStruct();
94  }
95  }
96  }
97 
98  //void NJointKeypointsImpedanceMPController::deactivateController(const Ice::Current &)
99  //{
100  // for (auto mp: mps)
101  // {
102  // mp.second.mp->stop();
103  // }
104  //}
105 
106  void
108  {
109  ARMARX_IMPORTANT << "rt pre activate: reinitialize the mp input output, as well as the rt "
110  "related buffer values";
112  for (auto mp : mps)
113  {
114  if (mp.second.mp->getClassName() == "KeypointsMP")
115  {
116  ARMARX_IMPORTANT << "initialize input output buffers between KeypointsMP and "
117  "keypoint controllers";
118 
119  auto in = std::dynamic_pointer_cast<mp::KeypointsMPInput>(mp.second.input);
120  in->keypointPosition = controller.s.filteredKeypointPosition;
121  in->keypointVelocity = controller.s.currentKeypointVelocity;
122 
123  auto out = std::dynamic_pointer_cast<mp::KeypointsMPOutput>(mp.second.output);
124  out->keypointPosition = controller.s.filteredKeypointPosition;
125  out->keypointVelocity = controller.s.currentKeypointVelocity;
126  // ARMARX_INFO << VAROUT(in->keypointPosition) << VAROUT(in->keypointVelocity) << VAROUT(out->keypointPosition) << VAROUT(out->keypointVelocity) << VAROUT(controller.s.numPoints);
127  }
128  else if (mp.second.mp->getClassName() == "JSMP")
129  {
131  << "initialize input output buffers between JSMP and keypoint controllers";
132  auto in = std::dynamic_pointer_cast<mp::JSMPInput>(mp.second.input);
133  auto out = std::dynamic_pointer_cast<mp::JSMPOutput>(mp.second.output);
134  in->angleRadian = controller.s.qpos;
135  in->angularVel = controller.s.qvel;
136  out->angleRadian = controller.s.qpos;
137  out->angularVel = controller.s.qvel;
138  }
139  }
140  }
141 } // namespace armarx::control::njoint_mp_controller::task_space
armarx::control::njoint_mp_controller::task_space::NJointKeypointsImpedanceMPController::reconfigureController
void reconfigureController(const std::string &filename, const Ice::Current &) override
Definition: KeypointsImpedanceController.cpp:47
armarx::control::njoint_controller::task_space::NJointKeypointsImpedanceController::robotUnit
RobotUnitPtr robotUnit
Definition: KeypointsImpedanceController.h:115
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_controller::task_space::NJointKeypointsImpedanceController
Brief description of class NJointKeypointsImpedanceController.
Definition: KeypointsImpedanceController.h:49
armarx::control::common::mp::JSMPInputPtr
std::shared_ptr< JSMPInput > JSMPInputPtr
Definition: JSMP.h:47
armarx::control::njoint_mp_controller::task_space::registrationControllerNJointKeypointsImpedanceMPController
NJointControllerRegistration< NJointKeypointsImpedanceMPController > registrationControllerNJointKeypointsImpedanceMPController("NJointKeypointsImpedanceMPController")
KeypointsImpedanceController.h
armarx::control::njoint_mp_controller::task_space::NJointKeypointsImpedanceMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: KeypointsImpedanceController.cpp:41
armarx::control::common::mp::MPPool::runMPs
void runMPs(const bool rtSafe)
Definition: MPPool.cpp:87
armarx::control::common::mp::JSMPOutputPtr
std::shared_ptr< JSMPOutput > JSMPOutputPtr
Definition: JSMP.h:48
armarx::control::njoint_mp_controller::task_space::NJointKeypointsImpedanceMPController::NJointKeypointsImpedanceMPController
NJointKeypointsImpedanceMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: KeypointsImpedanceController.cpp:31
controller
Definition: AddOperation.h:39
armarx::control::common::mp::KeypointsMPOutputPtr
std::shared_ptr< KeypointsMPOutput > KeypointsMPOutputPtr
Definition: KeypointsMP.h:46
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::control::njoint_mp_controller::task_space
This file is part of ArmarX.
Definition: AdmittanceController.cpp:29
armarx::control::njoint_controller::task_space::NJointKeypointsImpedanceController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: KeypointsImpedanceController.cpp:292
IceUtil::Handle< class RobotUnit >
armarx::control::njoint_mp_controller::task_space::NJointKeypointsImpedanceMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: KeypointsImpedanceController.cpp:107
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::njoint_mp_controller::task_space::NJointKeypointsImpedanceMPController::additionalTask
void additionalTask() override
Definition: KeypointsImpedanceController.cpp:55
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