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
34#include "../util.h"
35#include "RobotUnitSubUnit.h"
36
37namespace armarx
38{
40
42
43 class KinematicSubUnit : virtual public RobotUnitSubUnit, virtual public KinematicUnit
44 {
45 public:
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
#define TYPEDEF_PTRS_HANDLE(T)
constexpr T c
void switchControlMode(const NameControlModeMap &ncm, const Ice::Current &) override
void setJointAngles(const NameValueMap &angles, const Ice::Current &) override
void releaseJoints(const Ice::StringSeq &, const Ice::Current &) override
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)
void requestJoints(const Ice::StringSeq &, const Ice::Current &) override
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
void onInitKinematicUnit() override
void setJointDecelerations(const NameValueMap &, const Ice::Current &) override
NameControlModeMap getControlModes(const Ice::Current &) override
DebugInfo getDebugInfo(const Ice::Current &c=Ice::emptyCurrent) const override
void onStartKinematicUnit() override
void setJointVelocities(const NameValueMap &velocities, const Ice::Current &) override
void setJointAccelerations(const NameValueMap &, const Ice::Current &) override
void setJointTorques(const NameValueMap &torques, const Ice::Current &) override
Ice::StringSeq getJoints(const Ice::Current &c) const override
void onExitKinematicUnit() override
NameValueMap getJointAngles(const Ice::Current &) const override
NameValueMap getJointVelocities(const Ice::Current &) const override
The KinematicUnit class.
The RobotUnit class manages a robot and its controllers.
Definition RobotUnit.h:192
The SensorValueBase class.
const T * asA() const
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
double v(double t, double v0, double a0, double j)
Definition CtrlUtil.h:39
This file offers overloads of toIce() and fromIce() functions for STL container types.
SynchronousNJointControllerPtr NJointControllerPtr
detail::ControlThreadOutputBufferEntry SensorAndControl
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.
NJointControllerPtr getActiveController() const
NJointKinematicUnitPassThroughControllerPtr ctrlPos
NJointControllerPtr getController(ControlMode c) const
NJointKinematicUnitPassThroughControllerPtr ctrlTor
NJointKinematicUnitPassThroughControllerPtr ctrlVel