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
25#include <VirtualRobot/Robot.h>
26
28
29namespace armarx
30{
33 "NJointKinematicUnitPassThroughController");
34
36 RobotUnit* prov,
37 const NJointKinematicUnitPassThroughControllerConfigPtr& cfg,
39 {
40 const SensorValueBase* sv = useSensorValue(cfg->deviceName);
41
42 ControlTargetBase* ct = useControlTarget(cfg->deviceName, cfg->controlMode);
43 //get sensor
44 if (ct->isA<ControlTarget1DoFActuatorPosition>())
45 {
46 ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFActuatorPosition>());
47 sensor._float = &(sv->asA<SensorValue1DoFActuatorPosition>()->position);
48 ARMARX_CHECK_EXPRESSION(ct->asA<ControlTarget1DoFActuatorPosition>());
49 target._float = &(ct->asA<ControlTarget1DoFActuatorPosition>()->position);
51 }
52 else if (ct->isA<ControlTarget1DoFActuatorVelocity>())
53 {
54 ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFActuatorVelocity>());
55 sensor._float = &(sv->asA<SensorValue1DoFActuatorVelocity>()->velocity);
56 ARMARX_CHECK_EXPRESSION(ct->asA<ControlTarget1DoFActuatorVelocity>());
57 target._float = &(ct->asA<ControlTarget1DoFActuatorVelocity>()->velocity);
59 resetZeroThreshold = 0.1f; // TODO: way to big value?!
60 }
61 else if (ct->isA<ControlTarget1DoFActuatorTorque>())
62 {
63 ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFActuatorTorque>());
64 sensor._float = &(sv->asA<SensorValue1DoFActuatorTorque>()->torque);
65 ARMARX_CHECK_EXPRESSION(ct->asA<ControlTarget1DoFActuatorTorque>());
66 target._float = &(ct->asA<ControlTarget1DoFActuatorTorque>()->torque);
68 }
69 else if (ct->isA<ControlTarget1DoFActuatorPWM>())
70 {
71 ARMARX_CHECK_EXPRESSION(sv->asA<SensorValue1DoFMotorPWM>());
72 sensor._int16 = &(sv->asA<SensorValue1DoFMotorPWM>()->motorPWM);
74 target._int16 = &(ct->asA<ControlTarget1DoFActuatorPWM>()->pwm);
76 }
77 else
78 {
79 throw InvalidArgumentException{"Unsupported control mode: " + cfg->controlMode};
80 }
81 }
82} // namespace armarx
Brief description of class JointControlTargetBase.
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
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...
NJointKinematicUnitPassThroughController(RobotUnit *prov, const NJointKinematicUnitPassThroughControllerConfigPtr &cfg, const VirtualRobot::RobotPtr &)
The RobotUnit class manages a robot and its controllers.
Definition RobotUnit.h:192
The SensorValueBase class.
const T * asA() const
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
NJointControllerRegistration< NJointKinematicUnitPassThroughController > registrationControllerNJointKinematicUnitPassThroughController("NJointKinematicUnitPassThroughController")