ForceTorqueObserver.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 ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include <RobotAPI/interface/units/ForceTorqueUnit.h>
28 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
29 
30 #include <mutex>
31 
32 namespace armarx
33 {
34  /**
35  * \class ForceTorqueObserverPropertyDefinitions
36  * \brief
37  */
40  {
41  public:
44  {
45  defineRequiredProperty<std::string>("ForceTorqueTopicName", "Name of the ForceTorqueUnit Topic");
46  defineOptionalProperty<bool>("VisualizeForce", true, "Visualize the force with an arrow in the debug drawer");
47  defineOptionalProperty<int>("RobotUpdateFrequency", 50, "Update frequency of the local robot");
48  defineOptionalProperty<int>("VisualizeForceUpdateFrequency", 30, "Frequency with which the force is visualized");
49  defineOptionalProperty<float>("ForceVisualizerFactor", 0.01f, "Factor by which the forces are scaled to fit into 0..1 (only for visulization) ");
50  defineOptionalProperty<float>("MaxExpectedTorqueValue", 30, "The torque visualization circle reaches the full circle at this value");
51  defineOptionalProperty<float>("TorqueVisuDeadZone", 1, "Torques below this threshold are not visualized.");
52  defineOptionalProperty<float>("MaxForceArrowLength", 150, "Length of the force visu arrow in mm");
53  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the RobotStateComponent that should be used");
54  defineOptionalProperty<std::string>("SensorRobotNodeMapping", "", "Triplets of sensor node name, target frame robot node name and optional channel name: Sensor values are also reported in the frame of the robot node: e. g. SensorName:RobotNodeName[:ChannelName],SensorName2:RobotNodeName2[:ChannelName2]");
55 
56  }
57  };
58 
59  /**
60  * \class ForceTorqueObserver
61  * \ingroup RobotAPI-SensorActorUnits-observers
62  * \brief Observer monitoring Force/Torque values
63  *
64  * The ForceTorqueObserver monitors F/T values published by ForceTorqueUnit-implementations and offers condition checks on these values.
65  * Available condition checks are: *updated*, *larger*, *equals*, *smaller* and *magnitudelarger*.
66  */
68  virtual public Observer,
69  virtual public ForceTorqueUnitObserverInterface
70  {
71  public:
73 
74  void setTopicName(std::string topicName);
75 
76  // framework hooks
77  std::string getDefaultName() const override
78  {
79  return "ForceTorqueUnitObserver";
80  }
81  void onInitObserver() override;
82  void onConnectObserver() override;
83  void onExitObserver() override;
84 
85  void visualizerFunction();
86 
87  void reportSensorValues(const std::string& sensorNodeName, const FramedDirectionBasePtr& forces, const FramedDirectionBasePtr& torques, const Ice::Current&) override;
88 
89  /**
90  * @see PropertyUser::createPropertyDefinitions()
91  */
93 
94  private:
95  void updateRobot();
96 
97  std::mutex dataMutex;
98  std::string topicName;
100  VirtualRobot::RobotPtr localRobot;
101  DebugDrawerInterfacePrx debugDrawer;
104  // One sensor can be reported in multiple frames => multimap
105  std::multimap<std::string, std::pair<std::string, std::string> > sensorRobotNodeMapping;
106 
107  void offerValue(const std::string& nodeName, const std::string& type, const FramedDirectionBasePtr& value, const DataFieldIdentifierPtr& id);
108 
109  // ForceTorqueUnitObserverInterface interface
110  public:
111  DatafieldRefBasePtr createNulledDatafield(const DatafieldRefBasePtr& forceTorqueDatafieldRef, const Ice::Current&) override;
112 
113  DatafieldRefBasePtr getForceDatafield(const std::string& nodeName, const Ice::Current&) override;
114  DatafieldRefBasePtr getTorqueDatafield(const std::string& nodeName, const Ice::Current&) override;
115 
116  DataFieldIdentifierPtr getForceDatafieldId(const std::string& nodeName, const std::string& frame);
117  DataFieldIdentifierPtr getTorqueDatafieldId(const std::string& nodeName, const std::string& frame);
118 
119 
120  // ManagedIceObject interface
121  protected:
122  void onDisconnectComponent() override;
123  };
124 }
125 
armarx::ForceTorqueObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: ForceTorqueObserver.cpp:100
armarx::Observer
Baseclass for all ArmarX Observers.
Definition: Observer.h:80
armarx::ForceTorqueObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ForceTorqueObserver.cpp:239
armarx::ForceTorqueObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: ForceTorqueObserver.cpp:61
armarx::ForceTorqueObserver
Observer monitoring Force/Torque values.
Definition: ForceTorqueObserver.h:67
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::ForceTorqueObserver::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ForceTorqueObserver.h:77
Observer.h
IceInternal::Handle< DataFieldIdentifier >
armarx::ForceTorqueObserver::getForceDatafield
DatafieldRefBasePtr getForceDatafield(const std::string &nodeName, const Ice::Current &) override
Definition: ForceTorqueObserver.cpp:389
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::ForceTorqueObserver::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ForceTorqueObserver.cpp:460
armarx::ForceTorqueObserver::getTorqueDatafieldId
DataFieldIdentifierPtr getTorqueDatafieldId(const std::string &nodeName, const std::string &frame)
Definition: ForceTorqueObserver.cpp:442
FramedPose.h
armarx::ForceTorqueObserver::reportSensorValues
void reportSensorValues(const std::string &sensorNodeName, const FramedDirectionBasePtr &forces, const FramedDirectionBasePtr &torques, const Ice::Current &) override
Definition: ForceTorqueObserver.cpp:307
armarx::ForceTorqueObserverPropertyDefinitions
Definition: ForceTorqueObserver.h:38
armarx::ForceTorqueObserver::ForceTorqueObserver
ForceTorqueObserver()
Definition: ForceTorqueObserver.cpp:52
armarx::ForceTorqueObserver::setTopicName
void setTopicName(std::string topicName)
Definition: ForceTorqueObserver.cpp:56
armarx::ForceTorqueObserver::getForceDatafieldId
DataFieldIdentifierPtr getForceDatafieldId(const std::string &nodeName, const std::string &frame)
Definition: ForceTorqueObserver.cpp:424
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::ForceTorqueObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: ForceTorqueObserver.cpp:472
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ForceTorqueObserver::createNulledDatafield
DatafieldRefBasePtr createNulledDatafield(const DatafieldRefBasePtr &forceTorqueDatafieldRef, const Ice::Current &) override
Definition: ForceTorqueObserver.cpp:384
armarx::ForceTorqueObserverPropertyDefinitions::ForceTorqueObserverPropertyDefinitions
ForceTorqueObserverPropertyDefinitions(std::string prefix)
Definition: ForceTorqueObserver.h:42
armarx::ForceTorqueObserver::visualizerFunction
void visualizerFunction()
Definition: ForceTorqueObserver.cpp:115
armarx::ObserverPropertyDefinitions
Definition: Observer.h:50
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ForceTorqueObserver::getTorqueDatafield
DatafieldRefBasePtr getTorqueDatafield(const std::string &nodeName, const Ice::Current &) override
Definition: ForceTorqueObserver.cpp:407
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18