5#include <Ice/Current.h>
6#include <IceUtil/Time.h>
8#include <SimoxUtility/math/convert/mat4f_to_rpy.h>
9#include <VirtualRobot/VirtualRobot.h>
15#include <ArmarXCore/interface/core/ManagedIceObjectDefinitions.h>
16#include <ArmarXCore/interface/observers/ObserverInterface.h>
17#include <ArmarXCore/interface/observers/VariantBase.h>
26#include <RobotAPI/interface/units/RobotUnit/NJointController.h>
27#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
29#include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
31#include <armarx/navigation/platform_controller/aron/PlatformGlobalTrajectoryControllerConfig.aron.generated.h>
41 const NJointControllerConfigPtr& config,
48 ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
58 const std::string controlTargetName = robotUnit->getRobotPlatformName();
60 ARMARX_INFO <<
"Using control target " << controlTargetName;
61 auto* ct =
useControlTarget(controlTargetName, ControlModes::HolonomicPlatformVelocity);
67 <<
"The actuator " << controlTargetName <<
" has no control mode "
68 << ControlModes::HolonomicPlatformVelocity;
73 const auto trajectoryFollowingControllerParams = configData.params;
76 configBuffer_updateConfigToAdditionalTask.reinitAllBuffers(configData);
77 configBuffer_updateConfigToOnPublish.reinitAllBuffers(configData);
79 trajectoryFollowingController.emplace(trajectoryFollowingControllerParams);
93 const IceUtil::Time& timeSinceLastIteration)
103 robotStateBuffer_rtToAdditionalTask.getWriteBuffer().global_T_robot.matrix() =
105 robotStateBuffer_rtToAdditionalTask.commitWrite();
110 const Ice::Current& iceCurrent)
116 configBuffer_updateConfigToAdditionalTask.getWriteBuffer() =
updateConfig;
117 configBuffer_updateConfigToAdditionalTask.commitWrite();
119 configBuffer_updateConfigToOnPublish.getWriteBuffer() =
updateConfig;
120 configBuffer_updateConfigToOnPublish.commitWrite();
129 ARMARX_CHECK(trajectoryFollowingController.has_value());
131 const auto& configBuffer =
132 configBuffer_updateConfigToAdditionalTask.getUpToDateReadBuffer();
136 if (configBuffer.targets.trajectory.points().empty())
140 filteredTwist.reset();
152 trajectoryFollowingController->updateParams(configBuffer.params);
156 trajectoryFollowingController->control(
157 configBuffer.targets.trajectory,
158 robotStateBuffer_rtToAdditionalTask.getUpToDateReadBuffer().global_T_robot);
162 const float alpha = configBuffer.params.alpha;
163 filteredTwist.linear =
164 alpha * filteredTwist.linear + (1. - alpha) * result.
twist.
linear.head<2>();
165 filteredTwist.angular =
166 alpha * filteredTwist.angular + (1. - alpha) * result.
twist.
angular.z();
175 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().target = filteredTwist;
176 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().dropPointVelocity =
178 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().currentOrientation =
180 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().desiredOrientation =
182 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().orientationError =
184 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().positionError =
186 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().isFinalSegment =
188 targetBuffer_additionalTaskToOnPublish.getWriteBuffer().global_T_robot =
189 robotStateBuffer_rtToAdditionalTask.getReadBuffer().global_T_robot;
190 targetBuffer_additionalTaskToOnPublish.commitWrite();
200 const auto& debugStuff = targetBuffer_additionalTaskToOnPublish.getUpToDateReadBuffer();
201 const auto& config = configBuffer_updateConfigToOnPublish.getUpToDateReadBuffer();
204 datafields[
"vx"] =
new Variant(debugStuff.target.linear.x());
205 datafields[
"vy"] =
new Variant(debugStuff.target.linear.y());
206 datafields[
"v_linear"] =
new Variant(debugStuff.target.linear.norm());
207 datafields[
"vyaw"] =
new Variant(debugStuff.target.angular);
208 datafields[
"trajectory_points"] =
new Variant(config.targets.trajectory.points().size());
210 datafields[
"drop_point_velocity"] =
new Variant(debugStuff.dropPointVelocity);
212 datafields[
"orientationError"] =
new Variant(debugStuff.orientationError);
213 datafields[
"desiredOrientation"] =
new Variant(debugStuff.desiredOrientation);
214 datafields[
"currentOrientation"] =
new Variant(debugStuff.currentOrientation);
215 datafields[
"isFinalSegment"] =
new Variant(debugStuff.isFinalSegment);
217 datafields[
"positionError"] =
new Variant(debugStuff.positionError);
219 datafields[
"global_T_robot.x"] =
new Variant(debugStuff.global_T_robot.translation().x());
220 datafields[
"global_T_robot.y"] =
new Variant(debugStuff.global_T_robot.translation().y());
221 datafields[
"global_T_robot.o"] =
222 new Variant(simox::math::mat4f_to_rpy(debugStuff.global_T_robot.matrix()).z());
224 datafields[
"limitLinear"] =
new Variant(config.params.limits.linear);
225 datafields[
"limitAngular"] =
new Variant(config.params.limits.angular);
227 debugObservers->setDebugChannel(
236 ARMARX_INFO <<
"PlatformGlobalTrajectoryController::onInitNJointController";
239 "PlatformGlobalTrajectoryControllerAdditionalTask",
245 <<
"Create a new thread alone PlatformGlobalTrajectoryController controller";
246 while (
getState() == eManagedIceObjectStarted)
253 c.waitForCycleDuration();
257 ARMARX_INFO <<
"PlatformGlobalTrajectoryController::onInitNJointController done.";
264 filteredTwist.reset();
266 robotStateBuffer_rtToAdditionalTask.getWriteBuffer().global_T_robot.matrix() =
268 robotStateBuffer_rtToAdditionalTask.commitWrite();
276 rtReady.store(
false);
This util class helps with keeping a cycle time during a control cycle.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
ArmarXObjectSchedulerPtr getObjectScheduler() const
int getState() const
Retrieve current state of the ManagedIceObject.
bool isControllerActive(const Ice::Current &=Ice::emptyCurrent) const final override
void runTask(const std::string &taskName, Task &&task)
Executes a given task in a separate thread from the Application ThreadPool.
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
const Target & rtGetControlStruct() const
void writeControlStruct()
bool rtUpdateControlStruct()
Target & getWriterControlStruct()
void reinitTripleBuffer(const Target &initial)
The Variant class is described here: Variants.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::shared_ptr< class Robot > RobotPtr
::IceInternal::Handle< Dict > DictPtr
const simox::meta::EnumNames< ControllerType > ControllerTypeNames
@ PlatformGlobalTrajectory
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
IceUtil::Handle< class RobotUnit > RobotUnitPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
detail::ControlThreadOutputBufferEntry SensorAndControl
core::GlobalTrajectoryPoint dropPoint