7#include <ArmarXCore/interface/observers/ObserverInterface.h>
8#include <ArmarXCore/interface/observers/VariantBase.h>
15#include <Ice/Current.h>
16#include <Ice/Object.h>
18#include <VirtualRobot/VirtualRobot.h>
20#include "RobotAPI/libraries/armem_gui/instance/tree_visitors/TreeTypedJSONConverter.h"
24#include <RobotAPI/interface/aron/Aron.h>
25#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
26#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
38#include <nlohmann/json_fwd.hpp>
39#include <zenoh_constants.h>
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}
146 NJointZenohTaskspaceController<
147 class base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>::
149 const armarx::NJointControllerConfigPtr& config,
150 const VirtualRobot::RobotPtr& robot) :
151 base::NJointTaskspaceMixedImpedanceVelocityController{
robotUnit, config, robot},
152 base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController{robotUnit,
160 template <
typename NJo
intTaskspaceController>
165 auto config = zenoh::Config::create_default();
167 config.insert_json5(
"connect/endpoints",
"[\"" + _connect_endpoint +
"\"]");
170 _session = std::make_unique<zenoh::Session>(zenoh::Session::open(std::move(config)));
171 ARMARX_CHECK(_session) <<
"Failed to create Zenoh session unique pointer";
175 ARMARX_INFO <<
"setting up publisher and subscriber";
177 _publisher = std::make_unique<zenoh::Publisher>(
178 _session->declare_publisher(zenoh::KeyExpr(_state_key)));
180 auto queryable_expr = zenoh::KeyExpr(_config_key);
181 auto on_drop_queryable = []() {
ARMARX_INFO <<
"Destroying queryable"; };
182 zenoh::Session::QueryableOptions opts;
183 opts.complete =
true;
184 auto queryable = _session->declare_queryable(
186 [&queryable_expr](
const zenoh::Query& query)
188 ARMARX_INFO <<
"Received Query '" << query.get_keyexpr().as_string_view();
189 query.reply(queryable_expr, zenoh::Bytes(
"42"));
191 std::move(on_drop_queryable),
196 ARMARX_INFO <<
"Zenoh session and endpoints initialized";
197 time_last_packet = std::chrono::steady_clock::now();
200 template <
typename NJo
intTaskspaceController>
206 auto sendTime = std::chrono::duration_cast<std::chrono::microseconds>(
207 std::chrono::system_clock::now().time_since_epoch())
211 j[
"timestamp"] =
static_cast<double>(sendTime) / 1e6;
212 j[
"msg"] = R
"({"matrix":[[1,0],[0,1]],"float":3.14,"string":"hello","bool":true})";
215 for (
auto& pair : this->
limb)
217 this->
userConfig.limbs.at(pair.first) = pair.second->nonRtConfig;
220 auto json_msg = this->
userConfig.write(writer);
225 ARMARX_INFO << this->limb.at(
"LeftArm")->nonRtConfig.desiredNullspaceJointAngles.value();
230 this->limb.at(
"LeftArm")->nonRtConfig.toAron(),
231 this->limb.at(
"LeftArm")->nonRtConfig.ToAronType());
235 ARMARX_WARNING <<
"In controller additional task, failed to Aron data to JSON: "
239 _publisher->put(conv.
getJSON().dump(2));
296 if (not rtTargetSafe)
302 template <
typename NJo
intTaskspaceController>
305 const zenoh::Sample& sample)
308 std::string payload = sample.get_payload().as_string();
309 _config_json = payload;
310 ARMARX_INFO <<
"[CONFIG] Updated: " << _config_json;
313 template <
typename NJo
intTaskspaceController>
322 datafields[
"frequency_ms"] =
new Variant(frequency_ms);
323 datafields[
"latency_ms"] =
new Variant(latency_ms);
327 for (
auto& pair : this->
limb)
329 if (not pair.second->rtReady.load())
The Variant class is described here: Variants.
const nlohmann::json & getJSON()
A base class for aron exceptions.
NJointTaskspaceController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
std::map< std::string, ArmPtr > limb
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
void updateConfigZenoh(const zenoh::Sample &sample)
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const final
NJointZenohTaskspaceController(const armarx::RobotUnitPtr &robotUnit, const armarx::NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &robot)
void additionalTask() final
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< class Robot > RobotPtr
void visitRecursive(RecursiveVisitorImplementation &v, typename RecursiveVisitorImplementation::Input &o)
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