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>
22#include "RobotAPI/libraries/armem_gui/instance/tree_visitors/TreeTypedJSONConverter.h"
26#include <RobotAPI/interface/aron/Aron.h>
27#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
28#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
40#include <nlohmann/json_fwd.hpp>
41#include <zenoh_constants.h>
45 namespace base = armarx::control::njoint_controller::task_space;
47 armarx::NJointControllerRegistration<
72 base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>>
81 const Ice::Current&)
const
90 const Ice::Current&)
const
108 class base::NJointTaskspaceCollisionAvoidanceImpedanceController>::
118 class base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>::
125 template <
typename NJo
intTaskspaceController>
128 const armarx::NJointControllerConfigPtr& config,
137 class base::NJointTaskspaceCollisionAvoidanceImpedanceController>::
139 const armarx::NJointControllerConfigPtr& config,
140 const VirtualRobot::RobotPtr& robot) :
141 base::NJointTaskspaceImpedanceController{
robotUnit, config, robot},
142 base::NJointTaskspaceCollisionAvoidanceImpedanceController{robotUnit, config, robot}
148 NJointZenohTaskspaceController<
149 class base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>::
151 const armarx::NJointControllerConfigPtr& config,
152 const VirtualRobot::RobotPtr& robot) :
153 base::NJointTaskspaceMixedImpedanceVelocityController{
robotUnit, config, robot},
154 base::NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController{robotUnit,
162 template <
typename NJo
intTaskspaceController>
167 auto config = zenoh::Config::create_default();
169 config.insert_json5(
"connect/endpoints",
"[\"" + _connect_endpoint +
"\"]");
172 _session = std::make_unique<zenoh::Session>(zenoh::Session::open(std::move(config)));
173 ARMARX_CHECK(_session) <<
"Failed to create Zenoh session unique pointer";
177 ARMARX_INFO <<
"setting up publisher and subscriber";
179 _publisher = std::make_unique<zenoh::Publisher>(
180 _session->declare_publisher(zenoh::KeyExpr(_state_key)));
182 auto queryable_expr = zenoh::KeyExpr(_config_key);
183 auto on_drop_queryable = []() {
ARMARX_INFO <<
"Destroying queryable"; };
184 zenoh::Session::QueryableOptions opts;
185 opts.complete =
true;
186 auto queryable = _session->declare_queryable(
188 [&queryable_expr](
const zenoh::Query& query)
190 ARMARX_INFO <<
"Received Query '" << query.get_keyexpr().as_string_view();
191 query.reply(queryable_expr, zenoh::Bytes(
"42"));
193 std::move(on_drop_queryable),
198 ARMARX_INFO <<
"Zenoh session and endpoints initialized";
199 time_last_packet = std::chrono::steady_clock::now();
202 template <
typename NJo
intTaskspaceController>
208 auto sendTime = std::chrono::duration_cast<std::chrono::microseconds>(
209 std::chrono::system_clock::now().time_since_epoch())
213 j[
"timestamp"] =
static_cast<double>(sendTime) / 1e6;
214 j[
"msg"] = R
"({"matrix":[[1,0],[0,1]],"float":3.14,"string":"hello","bool":true})";
217 for (
auto& pair : this->
limb)
219 this->
userConfig.limbs.at(pair.first) = pair.second->nonRtConfig;
222 auto json_msg = this->
userConfig.write(writer);
227 ARMARX_INFO << this->limb.at(
"LeftArm")->nonRtConfig.desiredNullspaceJointAngles.value();
232 this->limb.at(
"LeftArm")->nonRtConfig.toAron(),
233 this->limb.at(
"LeftArm")->nonRtConfig.ToAronType());
237 ARMARX_WARNING <<
"In controller additional task, failed to Aron data to JSON: "
241 _publisher->put(conv.
getJSON().dump(2));
298 if (not rtTargetSafe)
304 template <
typename NJo
intTaskspaceController>
307 const zenoh::Sample& sample)
310 std::string payload = sample.get_payload().as_string();
311 _config_json = payload;
312 ARMARX_INFO <<
"[CONFIG] Updated: " << _config_json;
315 template <
typename NJo
intTaskspaceController>
324 datafields[
"frequency_ms"] =
new Variant(frequency_ms);
325 datafields[
"latency_ms"] =
new Variant(latency_ms);
329 for (
auto& pair : this->
limb)
331 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