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
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);
51 reconfigureMPs(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
void reconfigureMPs(const MPListConfig &mpListConfig)
Definition MPPool.cpp:97
void createMPs(const MPListConfig &mpListConfig)
Definition MPPool.cpp:23
std::map< std::string, MPInputOutput > mps
Definition MPPool.h:146
NJointKeypointsImpedanceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
void rtPreActivateController() override
This function is called before the controller is activated.
NJointKeypointsImpedanceMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
void reconfigureController(const std::string &filename, const Ice::Current &) override
void rtPreActivateController() override
This function is called before the controller is activated.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file is part of ArmarX.
std::shared_ptr< KeypointsMPInput > KeypointsMPInputPtr
Definition KeypointsMP.h:45
std::shared_ptr< JSMPOutput > JSMPOutputPtr
Definition JSMP.h:48
std::shared_ptr< KeypointsMPOutput > KeypointsMPOutputPtr
Definition KeypointsMP.h:46
std::shared_ptr< JSMPInput > JSMPInputPtr
Definition JSMP.h:47
NJointControllerRegistration< NJointKeypointsImpedanceMPController > registrationControllerNJointKeypointsImpedanceMPController("NJointKeypointsImpedanceMPController")
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34