ZeroMQController.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 ...
17 * @author Andre Meixner ( andre dot meixner at kit dot edu )
18 * @date 2024
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <string>
26
27#include <Ice/Object.h>
28
29#include <SimoxUtility/math/convert/mat3f_to_quat.h>
30#include <SimoxUtility/math/convert/mat4f_to_pos.h>
31#include <SimoxUtility/math/convert/mat4f_to_quat.h>
32#include <SimoxUtility/math/convert/pos_quat_to_mat4f.h>
33#include <VirtualRobot/VirtualRobot.h>
34
35#include <ArmarXCore/interface/core/UserException.h>
36#include <ArmarXCore/interface/observers/ObserverInterface.h>
37#include <ArmarXCore/interface/serialization/Eigen/Eigen_fdi.h>
38
41#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
42
43#include <atomic>
44#include <mutex>
45
46#include <zmq.hpp>
47
48#include <armarx/control/njoint_controller/task_space/ControllerInterface.h>
49
51{
52 template <typename NJointTaskspaceController>
54 {
55 public:
57 const armarx::NJointControllerConfigPtr& config,
58 const VirtualRobot::RobotPtr& robot);
59
60 void init();
61
63
64 //overwritten for specific templates, see .cpp
65 std::string
66 getClassName(const Ice::Current& = Ice::emptyCurrent) const final
67 {
68 return "NJointZeroMQTaskspaceUnknownController";
69 }
70
71 void additionalTask() final;
72 void onPublish(const SensorAndControl&,
74 const DebugObserverInterfacePrx&) override;
75
77
78 private:
79 void setPublishIPAddress(const std::string& ipAddress);
80
81 private:
82 zmq::context_t context; // ZeroMQ context (shared by both sockets)
83 zmq::socket_t socket; // Incoming: ZMQ_PULL to receive controller configs
84 zmq::socket_t publishSocket_; // Outgoing: ZMQ_PUSH to send robot state
85 std::mutex publishSocketMutex_;
86 std::atomic<bool> publishSocketBound_{false};
87
88 // Logging stuff
89 std::chrono::steady_clock::time_point time_last_packet;
90 double frequency_ms;
91 double latency_ms;
92 };
93} // namespace armarx::control::njoint_controller::task_space
NJointTaskspaceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition Base.cpp:138
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
NJointZeroMQTaskspaceController(const armarx::RobotUnitPtr &robotUnit, const armarx::NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &robot)
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const final
void onPublishDeactivation(const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
int socket_t
Definition httplib.h:226
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class RobotUnit > RobotUnitPtr
Definition FTSensor.h:34
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl