28 #include <ArmarXCore/interface/core/BasicVectorTypesHelpers.h>
40 usingProxy(getProperty<std::string>(
"RobotStateComponentName").getValue());
41 usingProxy(getProperty<std::string>(
"KinematicUnitName").getValue());
42 usingProxy(getProperty<std::string>(
"KinematicUnitObserverName").getValue());
43 if (!getProperty<std::string>(
"RemoteGuiName").getValue().
empty())
45 usingProxy(getProperty<std::string>(
"RemoteGuiName").getValue());
49 frameName = getProperty<std::string>(
"FrameOnStartup").getValue();
62 getProperty<std::string>(
"RobotStateComponentName").getValue());
64 getProperty<std::string>(
"KinematicUnitName").getValue());
66 getProperty<std::string>(
"KinematicUnitObserverName").getValue());
70 localRobot->getRobotNode(getProperty<std::string>(
"HeadYawJoint").getValue());
74 ARMARX_ERROR << getProperty<std::string>(
"HeadYawJoint").getValue()
75 <<
" is not a valid joint.";
79 localRobot->getRobotNode(getProperty<std::string>(
"HeadPitchJoint").getValue());
83 ARMARX_ERROR << getProperty<std::string>(
"HeadPitchJoint").getValue()
84 <<
" is not a valid joint.";
90 ARMARX_ERROR << getProperty<std::string>(
"CameraNode").getValue()
91 <<
" is not a valid node.";
96 _enableTracking(getProperty<bool>(
"EnableTrackingOnStartup").getValue());
98 if (!getProperty<std::string>(
"RemoteGuiName").getValue().
empty())
101 getProperty<std::string>(
"RemoteGuiName").getValue());
129 .steps(2 * 1000000000 / 10)
134 .steps(2 * 1000000000 / 10)
139 .steps(2 * 1000000000 / 10)
150 .steps(2 * 1000000000 / 10)
155 .steps(2 * 1000000000 / 10)
160 .steps(2 * 1000000000 / 10)
172 .steps(
static_cast<int>((
headYawJoint->getJointLimitHi() -
193 .
steps(
static_cast<int>(6 / 0.1))
205 .steps(2 * 1000000000 / 10)
210 .steps(2 * 1000000000 / 10)
215 .steps(2 * 1000000000 / 10)
221 .steps(2 * 1000000000 / 10)
226 .steps(2 * 1000000000 / 10)
231 .steps(2 * 1000000000 / 10)
237 .steps(
static_cast<int>(6 / 0.1))
243 .steps(
static_cast<int>(8 / 0.1))
247 rootLayoutBuilder.
addChild(
new RemoteGui::VSpacer());
253 std::string oldFrameGui =
_guiTab.
getValue<std::string>(
"tracking_frame").get();
300 {_guiTab.getValue<float>(
"scan_in_configuration_space_pitch").get()},
301 _guiTab.
getValue<
float>(
"scan_in_configuration_space_velocity").get());
435 const float currentYawVel =
439 const float currentPitchVel =
444 FrameTracking::HeadState headState;
445 headState.currentYawPos = currentYaw;
446 headState.currentYawVel = currentYawVel;
447 headState.currentPitchPos = currentPitch;
448 headState.currentPitchVel = currentPitchVel;
451 headState.desiredYawPos = yaw;
452 headState.desiredPitchPos = pitch;
454 struct timespec req = {0, 30 * 1000000L};
459 <<
" pitch: " <<
headPitchJoint->getJointValue() <<
" -> " << pitch;
462 nanosleep(&req,
nullptr);
473 const Ice::FloatSeq& pitchValues,
487 {{
headYawJoint->getName(), ControlMode::eVelocityControl},
492 bool wasGreater =
headYawJoint->getJointValue() > yawFrom;
493 float yawVelocityToInit = wasGreater ? -velocity : velocity;
498 while ((wasGreater &&
headYawJoint->getJointValue() > yawFrom) ||
499 (!wasGreater &&
headYawJoint->getJointValue() < yawFrom))
505 for (
const auto& p : pitchValues)
509 float velocityPitch = wasGreaterP ? -velocity : velocity;
519 bool wasGreaterY = yawFrom > yawTo;
520 float velocityYaw = wasGreaterY ? -velocity : velocity;
523 while ((wasGreaterY &&
headYawJoint->getJointValue() > yawTo) ||
524 (!wasGreaterY &&
headYawJoint->getJointValue() < yawTo))
552 {{
headYawJoint->getName(), ControlMode::eVelocityControl},
554 struct timespec req = {0, 30 * 1000000L};
555 for (
const auto& p : points)
557 auto pEigen =
localRobot->toLocalCoordinateSystemVec(ToEigen(p));
560 static_cast<float>(
M_PI / 180.) ||
562 static_cast<float>(
M_PI / 180.))
565 <<
" pitch: " <<
target.currentPitchPos <<
" - "
566 <<
target.desiredPitchPos;
571 nanosleep(&req,
nullptr);
608 auto posInRobotFrame =
localRobot->toLocalCoordinateSystemVec(frame->getGlobalPosition());
622 float diff =
std::abs(head_state.desiredPitchPos - head_state.currentPitchPos) +
623 std::abs(head_state.currentYawPos - head_state.desiredYawPos);
624 return max_diff > diff;
627 FrameTracking::HeadState
631 auto posInRobotFrame =
localRobot->toLocalCoordinateSystemVec(frame->getGlobalPosition());
634 if (
std::sqrt(posInRobotFrame.x() * posInRobotFrame.x() +
635 posInRobotFrame.y() * posInRobotFrame.y()) < 300.f)
637 return FrameTracking::HeadState{
true, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
642 FrameTracking::HeadState
645 float yaw = -std::atan2(point.x(), point.y());
654 static_cast<float>(
M_PI) / 8)
659 const auto pointInPitchJointFrame =
headPitchJoint->toLocalCoordinateSystemVec(
660 localRobot->toGlobalCoordinateSystemVec(point));
661 const Eigen::Vector2f pj{pointInPitchJointFrame.y(), pointInPitchJointFrame.z()};
662 const float headHeightRealativeToPitchJoint =
664 float pitch =
headPitchJoint->getJointValue() - std::asin(pj.x() / pj.norm()) +
665 std::asin(headHeightRealativeToPitchJoint / pj.norm());
672 <<
" using yaw=" << yaw <<
" and pitch=" << pitch;
674 const float currentYawVel =
678 const float currentPitchVel =
683 FrameTracking::HeadState headState;
684 headState.currentYawPos = currentYaw;
685 headState.desiredYawPos = yaw;
686 headState.currentYawVel = currentYawVel;
687 headState.currentPitchPos = currentPitch;
688 headState.desiredPitchPos = pitch;
689 headState.currentPitchVel = currentPitchVel;
695 float maxYawVelocity,
696 float yawAcceleration,
697 float maxPitchVelocity,
698 float pitchAcceleration)
707 float desiredYawVelocity =
710 headState.currentYawVel,
714 headState.currentYawPos,
715 headState.desiredYawPos,
717 float desiredPitchVelocity =
720 headState.currentPitchVel,
724 headState.currentPitchPos,
725 headState.desiredPitchPos,
739 {{
headYawJoint->getName(), ControlMode::ePositionControl},
764 {{
headYawJoint->getName(), ControlMode::eVelocityControl},