NJointKinematicUnitPassThroughController.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 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 
24 
26 
27 namespace armarx
28 {
29  NJointControllerRegistration<NJointKinematicUnitPassThroughController>
31  "NJointKinematicUnitPassThroughController");
32 
34  RobotUnit* prov,
35  const NJointKinematicUnitPassThroughControllerConfigPtr& cfg,
37  {
38  const SensorValueBase* sv = useSensorValue(cfg->deviceName);
39 
40  ControlTargetBase* ct = useControlTarget(cfg->deviceName, cfg->controlMode);
41  //get sensor
42  if (ct->isA<ControlTarget1DoFActuatorPosition>())
43  {
44  ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFActuatorPosition>());
45  sensor._float = &(sv->asA<SensorValue1DoFActuatorPosition>()->position);
46  ARMARX_CHECK_EXPRESSION(ct->asA<ControlTarget1DoFActuatorPosition>());
47  target._float = &(ct->asA<ControlTarget1DoFActuatorPosition>()->position);
49  }
50  else if (ct->isA<ControlTarget1DoFActuatorVelocity>())
51  {
52  ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFActuatorVelocity>());
53  sensor._float = &(sv->asA<SensorValue1DoFActuatorVelocity>()->velocity);
54  ARMARX_CHECK_EXPRESSION(ct->asA<ControlTarget1DoFActuatorVelocity>());
55  target._float = &(ct->asA<ControlTarget1DoFActuatorVelocity>()->velocity);
57  resetZeroThreshold = 0.1f; // TODO: way to big value?!
58  }
59  else if (ct->isA<ControlTarget1DoFActuatorTorque>())
60  {
61  ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFActuatorTorque>());
62  sensor._float = &(sv->asA<SensorValue1DoFActuatorTorque>()->torque);
63  ARMARX_CHECK_EXPRESSION(ct->asA<ControlTarget1DoFActuatorTorque>());
64  target._float = &(ct->asA<ControlTarget1DoFActuatorTorque>()->torque);
66  }
67  else if (ct->isA<ControlTarget1DoFActuatorPWM>())
68  {
69  ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFMotorPWM>());
70  sensor._int16 = &(sv->asA<SensorValue1DoFMotorPWM>()->motorPWM);
74  }
75  else
76  {
77  throw InvalidArgumentException{"Unsupported control mode: " + cfg->controlMode};
78  }
79  }
80 } // namespace armarx
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:47
armarx::ControlTarget1DoFActuatorPWM
Definition: ControlTarget1DoFActuator.h:177
armarx::NJointControllerBase::useControlTarget
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
Definition: NJointController.cpp:410
armarx::NJointKinematicUnitPassThroughController::resetZeroThreshold
float resetZeroThreshold
Definition: NJointKinematicUnitPassThroughController.h:134
NJointKinematicUnitPassThroughController.h
armarx::NJointKinematicUnitPassThroughController::sensor
ptr_wrapper< true > sensor
Definition: NJointKinematicUnitPassThroughController.h:132
armarx::NJointKinematicUnitPassThroughController::NJointKinematicUnitPassThroughController
NJointKinematicUnitPassThroughController(RobotUnit *prov, const NJointKinematicUnitPassThroughControllerConfigPtr &cfg, const VirtualRobot::RobotPtr &)
Definition: NJointKinematicUnitPassThroughController.cpp:33
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::NJointKinematicUnitPassThroughController::target
ptr_wrapper< false > target
Definition: NJointKinematicUnitPassThroughController.h:131
armarx::registrationControllerNJointKinematicUnitPassThroughController
NJointControllerRegistration< NJointKinematicUnitPassThroughController > registrationControllerNJointKinematicUnitPassThroughController("NJointKinematicUnitPassThroughController")
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::ControlTargetBase::isA
bool isA() const
Definition: ControlTargetBase.h:69
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::NJointKinematicUnitPassThroughController::sensorToControlOnActivateFactor
float sensorToControlOnActivateFactor
Definition: NJointKinematicUnitPassThroughController.h:133
NJointControllerRegistry.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::NJointControllerBase::useSensorValue
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
Definition: NJointController.cpp:383
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18