7#include <ArmarXCore/interface/observers/ObserverInterface.h>
8#include <ArmarXCore/interface/observers/VariantBase.h>
15#include <boost/date_time/posix_time/posix_time.hpp>
17#include <Ice/Current.h>
18#include <Ice/Object.h>
20#include <VirtualRobot/VirtualRobot.h>
25#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
26#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
37#include <nlohmann/json_fwd.hpp>
43 namespace base = armarx::control::njoint_controller::task_space;
45 armarx::NJointControllerRegistration<
70 base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>>
79 const Ice::Current&)
const
88 const Ice::Current&)
const
106 class base::NJointTaskspaceCollisionAvoidanceImpedanceController>::
116 class base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>::
123 template <
typename NJo
intTaskspaceController>
126 const armarx::NJointControllerConfigPtr& config,
135 class base::NJointTaskspaceCollisionAvoidanceImpedanceController>::
137 const armarx::NJointControllerConfigPtr& config,
138 const VirtualRobot::RobotPtr& robot) :
139 base::NJointTaskspaceImpedanceController{
robotUnit, config, robot},
140 base::NJointTaskspaceCollisionAvoidanceImpedanceController{robotUnit, config, robot},
142 socket(context, ZMQ_PULL)
148 NJointZeroMQTaskspaceController<
149 class base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>::
151 const armarx::NJointControllerConfigPtr& config,
152 const VirtualRobot::RobotPtr& robot) :
153 base::NJointTaskspaceMixedImpedanceVelocityController{
robotUnit, config, robot},
154 base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController{robotUnit,
158 socket(context, ZMQ_PULL)
164 template <
typename NJo
intTaskspaceController>
170 std::string ip_address =
"*";
171 std::string bind_address =
"tcp://" + ip_address +
":" + std::to_string(port);
174 socket.bind(bind_address);
175 ARMARX_INFO <<
"Controller bound to " << bind_address <<
" through ZeroMQ";
177 catch (
const zmq::error_t& e)
183 time_last_packet = std::chrono::steady_clock::now();
186 template <
typename NJo
intTaskspaceController>
190 zmq::message_t config_msg;
191 bool received = socket.recv(&config_msg, ZMQ_DONTWAIT);
195 auto currentTime = std::chrono::steady_clock::now();
196 std::chrono::duration<double> elapsed_seconds = currentTime - time_last_packet;
197 frequency_ms = elapsed_seconds.count() * 1000;
198 time_last_packet = currentTime;
201 std::string config_json_str(
static_cast<char*
>(config_msg.data()), config_msg.size());
202 nlohmann::json config_json = nlohmann::json::parse(config_json_str);
205 if (config_json.contains(
"timestamp") && config_json[
"timestamp"].is_number())
207 auto arrival_time = std::chrono::duration<double>(
208 std::chrono::system_clock::now().time_since_epoch())
210 double sender_time = config_json[
"timestamp"];
211 latency_ms = (arrival_time - sender_time) * 1000;
219 receivedConfig.read(reader, config_json);
221 for (
auto& pair : this->
limb)
223 auto limbName = pair.first;
224 auto&
limb = pair.second;
226 auto limbConfig = prevCfg.limbs.at(limbName);
227 auto limbConfigNew = receivedConfig.limbs.at(limbName);
228 limbConfig.desiredPose = limbConfigNew.desiredPose;
229 limb->bufferConfigUserToNonRt.getWriteBuffer() =
231 limb->bufferConfigUserToNonRt.commitWrite();
237 this->
hands->updateConfig(receivedConfig.hands);
243 if (not rtTargetSafe)
249 template <
typename NJo
intTaskspaceController>
258 datafields[
"frequency_ms"] =
new Variant(frequency_ms);
259 datafields[
"latency_ms"] =
new Variant(latency_ms);
263 for (
auto& pair : this->
limb)
265 if (not pair.second->rtReady.load())
The Variant class is described here: Variants.
NJointTaskspaceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
std::map< std::string, ArmPtr > limb
core::HandControlPtr hands
typename NJointTaskspaceControllerType::ConfigDict ConfigDict
std::tuple< bool, bool > additionalTaskUpdateStatus()
void additionalTaskSetTarget()
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
void handleRTNotSafeInNonRT()
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 additionalTask() final
#define ARMARX_INFO
The normal logging level.
std::shared_ptr< class Robot > RobotPtr
const simox::meta::EnumNames< ControllerType > ControllerTypeNames
armarx::NJointControllerRegistration< NJointSharedMemoryTaskspaceController< base::NJointTSMixImpVelColController > > registrationControllerNJointCollisionAvoidanceTSMixedImpedanceVelocityController(armarx::control::common::ControllerTypeNames.to_name(armarx::control::common::ControllerType::SharedMemoryTSMixImpVelCol))
armarx::NJointControllerRegistration< NJointSharedMemoryTaskspaceController< base::NJointTSMixImpVelController > > registrationControllerNJointTSMixedImpedanceVelocityController(armarx::control::common::ControllerTypeNames.to_name(armarx::control::common::ControllerType::SharedMemoryTSMixImpVel))
armarx::NJointControllerRegistration< NJointSharedMemoryTaskspaceController< base::NJointTSImpController > > registrationControllerNJointTSImpedanceController(armarx::control::common::ControllerTypeNames.to_name(armarx::control::common::ControllerType::SharedMemoryTSImp))
armarx::NJointControllerRegistration< NJointSharedMemoryTaskspaceController< base::NJointTSVelController > > registrationControllerNJointTSVelocityController(armarx::control::common::ControllerTypeNames.to_name(armarx::control::common::ControllerType::SharedMemoryTSVel))
armarx::NJointControllerRegistration< NJointSharedMemoryTaskspaceController< base::NJointTSImpColController > > registrationControllerNJointCollisionAvoidanceTSImpedanceController(armarx::control::common::ControllerTypeNames.to_name(armarx::control::common::ControllerType::SharedMemoryTSImpCol))
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class RobotUnit > RobotUnitPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl