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