28#include <ArmarXCore/interface/core/BasicVectorTypesHelpers.h>
77 <<
" is not a valid joint.";
86 <<
" is not a valid joint.";
93 <<
" is not a valid node.";
131 .steps(2 * 1000000000 / 10)
136 .steps(2 * 1000000000 / 10)
141 .steps(2 * 1000000000 / 10)
152 .steps(2 * 1000000000 / 10)
157 .steps(2 * 1000000000 / 10)
162 .steps(2 * 1000000000 / 10)
174 .steps(
static_cast<int>((
headYawJoint->getJointLimitHi() -
181 .steps(
static_cast<int>((
headYawJoint->getJointLimitHi() -
195 .steps(
static_cast<int>(6 / 0.1))
207 .steps(2 * 1000000000 / 10)
212 .steps(2 * 1000000000 / 10)
217 .steps(2 * 1000000000 / 10)
223 .steps(2 * 1000000000 / 10)
228 .steps(2 * 1000000000 / 10)
233 .steps(2 * 1000000000 / 10)
239 .steps(
static_cast<int>(6 / 0.1))
245 .steps(
static_cast<int>(8 / 0.1))
249 rootLayoutBuilder.
addChild(
new RemoteGui::VSpacer());
254 bool oldEnabledGui =
_guiTab.getValue<
bool>(
"enabled").get();
255 std::string oldFrameGui =
_guiTab.getValue<std::string>(
"tracking_frame").get();
267 oldFrameGui !=
_guiTab.getValue<std::string>(
"tracking_frame").get())
276 if (
_guiTab.getButton(
"button_look_at_frame").clicked())
281 if (
_guiTab.getButton(
"button_look_at_global_point").clicked())
284 Vector3f{
_guiTab.getValue<
float>(
"global_point_x").get(),
285 _guiTab.getValue<
float>(
"global_point_y").get(),
286 _guiTab.getValue<
float>(
"global_point_z").get()});
289 if (
_guiTab.getButton(
"button_look_at_robot_point").clicked())
292 Vector3f{
_guiTab.getValue<
float>(
"robot_point_x").get(),
293 _guiTab.getValue<
float>(
"robot_point_y").get(),
294 _guiTab.getValue<
float>(
"robot_point_z").get()});
297 if (
_guiTab.getButton(
"button_scan_in_configuration_space").clicked())
300 _guiTab.getValue<
float>(
"scan_in_configuration_space_yaw_from").get(),
301 _guiTab.getValue<
float>(
"scan_in_configuration_space_yaw_to").get(),
302 {_guiTab.getValue<float>(
"scan_in_configuration_space_pitch").get()},
303 _guiTab.getValue<
float>(
"scan_in_configuration_space_velocity").get());
306 if (
_guiTab.getButton(
"button_scan_in_workspace").clicked())
309 {{
_guiTab.getValue<
float>(
"scan_in_workspace_from_x").get(),
310 _guiTab.getValue<
float>(
"scan_in_workspace_from_y").get(),
311 _guiTab.getValue<
float>(
"scan_in_workspace_from_z").get()},
312 {
_guiTab.getValue<
float>(
"scan_in_workspace_to_x").get(),
313 _guiTab.getValue<
float>(
"scan_in_workspace_to_y").get(),
314 _guiTab.getValue<
float>(
"scan_in_workspace_to_z").get()}},
315 _guiTab.getValue<
float>(
"scan_in_workspace_velocity").get(),
316 _guiTab.getValue<
float>(
"scan_in_workspace_acceleration").get());
321 RemoteGui::WidgetPtr rootLayout = rootLayoutBuilder;
437 const float currentYawVel =
441 const float currentPitchVel =
446 FrameTracking::HeadState headState;
447 headState.currentYawPos = currentYaw;
448 headState.currentYawVel = currentYawVel;
449 headState.currentPitchPos = currentPitch;
450 headState.currentPitchVel = currentPitchVel;
453 headState.desiredYawPos = yaw;
454 headState.desiredPitchPos = pitch;
456 struct timespec req = {0, 30 * 1000000L};
457 while (std::abs(
headYawJoint->getJointValue() - yaw) >
static_cast<float>(
M_PI / 180.) ||
461 <<
" pitch: " <<
headPitchJoint->getJointValue() <<
" -> " << pitch;
464 nanosleep(&req,
nullptr);
475 const Ice::FloatSeq& pitchValues,
484 velocity = std::abs(velocity);
489 {{
headYawJoint->getName(), ControlMode::eVelocityControl},
494 bool wasGreater =
headYawJoint->getJointValue() > yawFrom;
495 float yawVelocityToInit = wasGreater ? -velocity : velocity;
500 while ((wasGreater &&
headYawJoint->getJointValue() > yawFrom) ||
501 (!wasGreater &&
headYawJoint->getJointValue() < yawFrom))
507 for (
const auto& p : pitchValues)
511 float velocityPitch = wasGreaterP ? -velocity : velocity;
521 bool wasGreaterY = yawFrom > yawTo;
522 float velocityYaw = wasGreaterY ? -velocity : velocity;
525 while ((wasGreaterY &&
headYawJoint->getJointValue() > yawTo) ||
526 (!wasGreaterY &&
headYawJoint->getJointValue() < yawTo))
531 std::swap(yawFrom, yawTo);
554 {{
headYawJoint->getName(), ControlMode::eVelocityControl},
556 struct timespec req = {0, 30 * 1000000L};
557 for (
const auto& p : points)
559 auto pEigen =
localRobot->toLocalCoordinateSystemVec(ToEigen(p));
561 while (std::abs(target.currentYawPos - target.desiredYawPos) >
562 static_cast<float>(
M_PI / 180.) ||
563 std::abs(target.currentPitchPos - target.desiredPitchPos) >
564 static_cast<float>(
M_PI / 180.))
566 ARMARX_INFO <<
"yaw: " << target.currentYawPos <<
" - " << target.desiredYawPos
567 <<
" pitch: " << target.currentPitchPos <<
" - "
568 << target.desiredPitchPos;
573 nanosleep(&req,
nullptr);
610 auto posInRobotFrame =
localRobot->toLocalCoordinateSystemVec(frame->getGlobalPosition());
624 float diff = std::abs(head_state.desiredPitchPos - head_state.currentPitchPos) +
625 std::abs(head_state.currentYawPos - head_state.desiredYawPos);
626 return max_diff > diff;
629 FrameTracking::HeadState
633 auto posInRobotFrame =
localRobot->toLocalCoordinateSystemVec(frame->getGlobalPosition());
636 if (std::sqrt(posInRobotFrame.x() * posInRobotFrame.x() +
637 posInRobotFrame.y() * posInRobotFrame.y()) < 300.f)
639 return FrameTracking::HeadState{
true, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
644 FrameTracking::HeadState
647 float yaw = -std::atan2(point.x(), point.y());
654 std::abs(currentYaw - yaw) >
headYawJoint->getJointLimitHi() -
656 static_cast<float>(
M_PI) / 8)
661 const auto pointInPitchJointFrame =
headPitchJoint->toLocalCoordinateSystemVec(
662 localRobot->toGlobalCoordinateSystemVec(point));
663 const Eigen::Vector2f pj{pointInPitchJointFrame.y(), pointInPitchJointFrame.z()};
664 const float headHeightRealativeToPitchJoint =
666 float pitch =
headPitchJoint->getJointValue() - std::asin(pj.x() / pj.norm()) +
667 std::asin(headHeightRealativeToPitchJoint / pj.norm());
674 <<
" using yaw=" << yaw <<
" and pitch=" << pitch;
676 const float currentYawVel =
680 const float currentPitchVel =
685 FrameTracking::HeadState headState;
686 headState.currentYawPos = currentYaw;
687 headState.desiredYawPos = yaw;
688 headState.currentYawVel = currentYawVel;
689 headState.currentPitchPos = currentPitch;
690 headState.desiredPitchPos = pitch;
691 headState.currentPitchVel = currentPitchVel;
709 float desiredYawVelocity =
712 headState.currentYawVel,
716 headState.currentYawPos,
717 headState.desiredYawPos,
719 float desiredPitchVelocity =
722 headState.currentPitchVel,
726 headState.currentPitchPos,
727 headState.desiredPitchPos,
741 {{
headYawJoint->getName(), ControlMode::ePositionControl},
766 {{
headYawJoint->getName(), ControlMode::eVelocityControl},
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Brief description of class FrameTracking.
void onInitComponent() override
void setFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
void lookAtFrame(const std::string &frameName, const Ice::Current &=Ice::emptyCurrent) override
VirtualRobot::RobotPtr localRobot
void onDisconnectComponent() override
RobotStateComponentInterfacePrx robotStateComponent
void _enableTracking(bool enable)
void enableTracking(bool enable, const Ice::Current &=Ice::emptyCurrent) override
void scanInWorkspace(const ::armarx::Vector3fSeq &points, float maxVelocity, float acceleration, const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void lookAtPointInGlobalFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
void scanInConfigurationSpace(float yawFrom, float yawTo, const ::Ice::FloatSeq &pitchValues, float velocity, const Ice::Current &=Ice::emptyCurrent) override
RemoteGui::TabProxy _guiTab
void _doPositionControl(const HeadState &headstate)
std::string getFrame(const Ice::Current &=Ice::emptyCurrent) const override
std::atomic< bool > enabled
HeadState _calculateJointAnglesContinously(const std::string &frame)
bool isLookingAtPointInGlobalFrame(const Vector3f &point, float max_diff, const Ice::Current &=Ice::emptyCurrent) override
bool _looksAtPoint(const Eigen::Vector3f &point, float max_diff)
void lookAtPointInRobotFrame(const Vector3f &point, const Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
VirtualRobot::RobotNodePtr headYawJoint
KinematicUnitObserverInterfacePrx kinematicUnitObserverInterfacePrx
void _lookAtFrame(const std::string &frame)
VirtualRobot::RobotNodePtr cameraNode
RemoteGuiInterfacePrx _remoteGui
void syncronizeLocalClone()
SimplePeriodicTask ::pointer_type _guiTask
void _doVelocityControl(const HeadState &headstate, float maxYawVelocity, float yawAcceleration, float maxPitchVelocity, float pitchAcceleration)
void onExitComponent() override
PeriodicTask< FrameTracking >::pointer_type processorTask
void _lookAtPoint(const Eigen::Vector3f &point)
HeadState _calculateJointAngles(const Eigen::Vector3f &point)
VirtualRobot::RobotNodePtr headPitchJoint
KinematicUnitInterfacePrx kinematicUnitInterfacePrx
void moveJointsTo(float yaw, float pitch, const Ice::Current &=Ice::emptyCurrent) override
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.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
detail::CheckBoxBuilder makeCheckBox(std::string const &name)
detail::ComboBoxBuilder makeComboBox(std::string const &name)
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
detail::FloatSpinBoxBuilder makeFloatSpinBox(std::string const &name)
detail::LabelBuilder makeTextLabel(std::string const &text)
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
detail::ButtonBuilder makeButton(std::string const &name)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
SimplePeriodicTask(Ts...) -> SimplePeriodicTask< std::function< void(void)> >
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
float positionThroughVelocityControlWithAccelerationBounds(float dt, float maxDt, float currentV, float maxV, float acceleration, float deceleration, float currentPosition, float targetPosition, float p)
Derived & addChild(WidgetPtr const &child)