KinematicSubUnit.h
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 RobotAPI::ArmarXObjects::KinematicSubUnit
17  * @author Raphael ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <mutex>
26 
29 
31 
32 #include "../NJointControllers/NJointKinematicUnitPassThroughController.h"
33 #include "../SensorValues/SensorValue1DoFActuator.h"
34 #include "../util.h"
35 #include "RobotUnitSubUnit.h"
36 
37 namespace armarx
38 {
39  TYPEDEF_PTRS_HANDLE(RobotUnit);
40 
41  TYPEDEF_PTRS_HANDLE(KinematicSubUnit);
42 
43  class KinematicSubUnit : virtual public RobotUnitSubUnit, virtual public KinematicUnit
44  {
45  public:
46  struct ActuatorData
47  {
48  std::string name;
49  std::size_t sensorDeviceIndex;
50  NJointKinematicUnitPassThroughControllerPtr ctrlPos;
51  NJointKinematicUnitPassThroughControllerPtr ctrlVel;
52  NJointKinematicUnitPassThroughControllerPtr ctrlTor;
53 
54  NJointControllerPtr getController(ControlMode c) const;
56  };
57 
59 
60  void setupData(std::string relRobFile,
62  std::map<std::string, ActuatorData>&& newDevs,
63  std::vector<std::set<std::string>> controlDeviceHardwareControlModeGrps,
64  std::set<std::string> controlDeviceHardwareControlModeGrpsMerged,
65  RobotUnit* newRobotUnit);
66  void update(const SensorAndControl& sc, const JointAndNJointControllers& c) override;
67 
68  // KinematicUnitInterface interface
69  void requestJoints(const Ice::StringSeq&, const Ice::Current&) override;
70  void releaseJoints(const Ice::StringSeq&, const Ice::Current&) override;
71 
72  void setJointAngles(const NameValueMap& angles, const Ice::Current&) override;
73  void setJointVelocities(const NameValueMap& velocities, const Ice::Current&) override;
74  void setJointTorques(const NameValueMap& torques, const Ice::Current&) override;
75  void switchControlMode(const NameControlModeMap& ncm, const Ice::Current&) override;
76 
77  void setJointAccelerations(const NameValueMap&, const Ice::Current&) override;
78  void setJointDecelerations(const NameValueMap&, const Ice::Current&) override;
79 
80  NameControlModeMap getControlModes(const Ice::Current&) override;
81  NameValueMap getJointAngles(const Ice::Current&) const override;
82  NameValueMap getJointVelocities(const Ice::Current&) const override;
83  Ice::StringSeq getJoints(const Ice::Current& c) const override;
84 
85  DebugInfo getDebugInfo(const Ice::Current& c = Ice::emptyCurrent) const override;
86 
87  void
89  {
90  }
91 
92  void
94  {
95  }
96 
97  void
99  {
100  }
101 
102  private:
103  std::map<std::string, ActuatorData> devs;
104  // never use this when holding the mutex! (could cause deadlocks)
105  RobotUnit* robotUnit = NULL;
106  mutable std::mutex dataMutex;
107  NameControlModeMap ctrlModes;
108  NameValueMap ang;
109  NameValueMap vel;
110  NameValueMap acc;
111  NameValueMap tor;
112  NameValueMap motorCurrents;
113  NameValueMap motorTemperatures;
114  NameStatusMap statuses;
115  std::vector<std::set<std::string>> controlDeviceHardwareControlModeGroups;
116  std::set<std::string> controlDeviceHardwareControlModeGroupsMerged;
117  IceReportSkipper reportSkipper;
118  std::vector<VirtualRobot::RobotNodePtr> sensorLessJoints;
119 
120  template <class ValueT, class SensorValueT, ValueT SensorValueT::*Member>
121  static void
122  UpdateNameValueMap(std::map<std::string, ValueT>& nvm,
123  const std::string& name,
124  const SensorValueBase* sv,
125  bool& changeState)
126  {
127  const SensorValueT* s = sv->asA<SensorValueT>();
128  if (!s)
129  {
130  return;
131  };
132  const ValueT& v = s->*Member;
133  if (!nvm.count(name) || (nvm.at(name) != v))
134  {
135  changeState = true;
136  }
137  nvm[name] = v;
138  }
139  };
140 } // namespace armarx
armarx::KinematicSubUnit::setupData
void setupData(std::string relRobFile, VirtualRobot::RobotPtr rob, std::map< std::string, ActuatorData > &&newDevs, std::vector< std::set< std::string >> controlDeviceHardwareControlModeGrps, std::set< std::string > controlDeviceHardwareControlModeGrpsMerged, RobotUnit *newRobotUnit)
Definition: KinematicSubUnit.cpp:37
armarx::KinematicSubUnit::getJoints
Ice::StringSeq getJoints(const Ice::Current &c) const override
Definition: KinematicSubUnit.cpp:457
armarx::KinematicSubUnit::setJointVelocities
void setJointVelocities(const NameValueMap &velocities, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:253
armarx::KinematicSubUnit
Definition: KinematicSubUnit.h:43
armarx::KinematicSubUnit::setJointAngles
void setJointAngles(const NameValueMap &angles, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:237
armarx::KinematicSubUnit::getJointVelocities
NameValueMap getJointVelocities(const Ice::Current &) const override
Definition: KinematicSubUnit.cpp:450
armarx::JointAndNJointControllers
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.
Definition: JointAndNJointControllers.h:32
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::KinematicSubUnit::ActuatorData::getActiveController
NJointControllerPtr getActiveController() const
Definition: KinematicSubUnit.cpp:499
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::KinematicSubUnit::setJointTorques
void setJointTorques(const NameValueMap &torques, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:270
armarx::KinematicSubUnit::update
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
Definition: KinematicSubUnit.cpp:78
armarx::KinematicUnit
The KinematicUnit class.
Definition: KinematicUnit.h:76
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::RobotUnitSubUnit
Definition: RobotUnitSubUnit.h:35
armarx::KinematicSubUnit::releaseJoints
void releaseJoints(const Ice::StringSeq &, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:231
KinematicUnit.h
armarx::KinematicSubUnit::requestJoints
void requestJoints(const Ice::StringSeq &, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:225
armarx::KinematicSubUnit::KinematicSubUnit
KinematicSubUnit()
Definition: KinematicSubUnit.cpp:32
armarx::KinematicSubUnit::ActuatorData::getController
NJointControllerPtr getController(ControlMode c) const
Definition: KinematicSubUnit.cpp:481
armarx::KinematicSubUnit::ActuatorData::sensorDeviceIndex
std::size_t sensorDeviceIndex
Definition: KinematicSubUnit.h:49
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::KinematicSubUnit::getJointAngles
NameValueMap getJointAngles(const Ice::Current &) const override
Definition: KinematicSubUnit.cpp:443
armarx::KinematicSubUnit::onInitKinematicUnit
void onInitKinematicUnit() override
Definition: KinematicSubUnit.h:88
RobotUnitSubUnit.h
IceReportSkipper.h
armarx::KinematicSubUnit::setJointDecelerations
void setJointDecelerations(const NameValueMap &, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:430
armarx::KinematicSubUnit::onStartKinematicUnit
void onStartKinematicUnit() override
Definition: KinematicSubUnit.h:93
armarx::KinematicSubUnit::setJointAccelerations
void setJointAccelerations(const NameValueMap &, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:424
ExpressionException.h
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::KinematicSubUnit::getControlModes
NameControlModeMap getControlModes(const Ice::Current &) override
Definition: KinematicSubUnit.cpp:436
armarx::NJointControllerPtr
SynchronousNJointControllerPtr NJointControllerPtr
Definition: NJointControllerBase.h:1169
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::KinematicSubUnit::ActuatorData
Definition: KinematicSubUnit.h:46
armarx::KinematicSubUnit::ActuatorData::name
std::string name
Definition: KinematicSubUnit.h:48
armarx::KinematicSubUnit::getDebugInfo
DebugInfo getDebugInfo(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: KinematicSubUnit.cpp:464
armarx::KinematicSubUnit::ActuatorData::ctrlPos
NJointKinematicUnitPassThroughControllerPtr ctrlPos
Definition: KinematicSubUnit.h:50
armarx::IceReportSkipper
Definition: IceReportSkipper.h:36
armarx::KinematicSubUnit::ActuatorData::ctrlTor
NJointKinematicUnitPassThroughControllerPtr ctrlTor
Definition: KinematicSubUnit.h:52
armarx::KinematicSubUnit::ActuatorData::ctrlVel
NJointKinematicUnitPassThroughControllerPtr ctrlVel
Definition: KinematicSubUnit.h:51
armarx::KinematicSubUnit::switchControlMode
void switchControlMode(const NameControlModeMap &ncm, const Ice::Current &) override
Definition: KinematicSubUnit.cpp:286
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::KinematicSubUnit::onExitKinematicUnit
void onExitKinematicUnit() override
Definition: KinematicSubUnit.h:98
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18