NJointKinematicUnitPassThroughController.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::NJointKinematicUnitPassThroughController
17  * @author Raphael Grimm ( 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 <atomic>
26 
27 #include <VirtualRobot/Robot.h>
28 
30 
31 #include "../ControlTargets/ControlTarget1DoFActuator.h"
32 #include "../SensorValues/SensorValue1DoFActuator.h"
33 #include "NJointControllerBase.h"
34 
35 namespace armarx
36 {
37  TYPEDEF_PTRS_HANDLE(NJointKinematicUnitPassThroughControllerConfig);
38 
39  class NJointKinematicUnitPassThroughControllerConfig : virtual public NJointControllerConfig
40  {
41  public:
42  std::string deviceName;
43  std::string controlMode;
44  };
45 
47 
48  /**
49  * @brief The NJointKinematicUnitPassThroughController class
50  * @ingroup Library-RobotUnit-NJointControllers
51  */
53  {
54  public:
55  using ConfigPtrT = NJointKinematicUnitPassThroughControllerConfigPtr;
56 
58  RobotUnit* prov,
59  const NJointKinematicUnitPassThroughControllerConfigPtr& cfg,
60  const VirtualRobot::RobotPtr&);
61 
62  inline void
63  rtRun(const IceUtil::Time&, const IceUtil::Time&) override
64  {
66  }
67 
68  inline void
70  {
71  }
72 
73  void
75  {
78  {
79  control = 0;
80  }
81  }
82 
83  //ice interface
84  inline std::string
85  getClassName(const Ice::Current& = Ice::emptyCurrent) const override
86  {
87  return "NJointKinematicUnitPassThroughController";
88  }
89 
90  void
91  set(float val)
92  {
93  control = val;
94  }
95 
96  protected:
97  std::atomic<float> control{0};
98 
99  template <bool ConstPtr>
100  struct ptr_wrapper
101  {
102  float
103  getValue() const
104  {
105  if (_float)
106  {
107  return *_float;
108  }
109  return *_int16;
110  }
111 
112  template <bool constPtr = ConstPtr, std::enable_if_t<!constPtr, int> = 0>
113  void
114  setValue(float val)
115  {
116  if (_float)
117  {
118  *_float = val;
119  }
120  else
121  {
122  *_int16 = static_cast<std::int16_t>(val);
123  }
124  }
125  template <class T>
126  using maybe_const_ptr = std::conditional_t<ConstPtr, const T*, T*>;
129  };
130 
135  };
136 } // namespace armarx
NJointControllerBase.h
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::NJointKinematicUnitPassThroughController::ptr_wrapper< true >::maybe_const_ptr
std::conditional_t< ConstPtr, const T *, T * > maybe_const_ptr
Definition: NJointKinematicUnitPassThroughController.h:126
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::NJointKinematicUnitPassThroughControllerConfig
Definition: NJointKinematicUnitPassThroughController.h:39
armarx::NJointKinematicUnitPassThroughControllerConfig::deviceName
std::string deviceName
Definition: NJointKinematicUnitPassThroughController.h:42
armarx::NJointKinematicUnitPassThroughController::resetZeroThreshold
float resetZeroThreshold
Definition: NJointKinematicUnitPassThroughController.h:134
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::NJointKinematicUnitPassThroughController::sensor
ptr_wrapper< true > sensor
Definition: NJointKinematicUnitPassThroughController.h:132
armarx::NJointKinematicUnitPassThroughController
The NJointKinematicUnitPassThroughController class.
Definition: NJointKinematicUnitPassThroughController.h:52
armarx::NJointKinematicUnitPassThroughController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: NJointKinematicUnitPassThroughController.h:85
armarx::NJointKinematicUnitPassThroughController::rtRun
void rtRun(const IceUtil::Time &, const IceUtil::Time &) override
TODO make protected and use attorneys.
Definition: NJointKinematicUnitPassThroughController.h:63
armarx::NJointKinematicUnitPassThroughController::set
void set(float val)
Definition: NJointKinematicUnitPassThroughController.h:91
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::NJointKinematicUnitPassThroughController::NJointKinematicUnitPassThroughController
NJointKinematicUnitPassThroughController(RobotUnit *prov, const NJointKinematicUnitPassThroughControllerConfigPtr &cfg, const VirtualRobot::RobotPtr &)
Definition: NJointKinematicUnitPassThroughController.cpp:33
armarx::NJointKinematicUnitPassThroughController::ptr_wrapper
Definition: NJointKinematicUnitPassThroughController.h:100
armarx::NJointKinematicUnitPassThroughController::ptr_wrapper::_float
maybe_const_ptr< float > _float
Definition: NJointKinematicUnitPassThroughController.h:127
armarx::NJointKinematicUnitPassThroughController::ptr_wrapper::_int16
maybe_const_ptr< std::int16_t > _int16
Definition: NJointKinematicUnitPassThroughController.h:128
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::NJointKinematicUnitPassThroughController::target
ptr_wrapper< false > target
Definition: NJointKinematicUnitPassThroughController.h:131
armarx::NJointKinematicUnitPassThroughControllerConfig::controlMode
std::string controlMode
Definition: NJointKinematicUnitPassThroughController.h:43
ExpressionException.h
armarx::NJointKinematicUnitPassThroughController::ptr_wrapper::setValue
void setValue(float val)
Definition: NJointKinematicUnitPassThroughController.h:114
armarx::NJointKinematicUnitPassThroughController::ptr_wrapper::getValue
float getValue() const
Definition: NJointKinematicUnitPassThroughController.h:103
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::NJointKinematicUnitPassThroughController::sensorToControlOnActivateFactor
float sensorToControlOnActivateFactor
Definition: NJointKinematicUnitPassThroughController.h:133
control
This file is part of ArmarX.
armarx::NJointKinematicUnitPassThroughController::reset
void reset()
Definition: NJointKinematicUnitPassThroughController.h:74
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::NJointKinematicUnitPassThroughController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointKinematicUnitPassThroughController.h:69
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18