28#include <ArmarXCore/interface/core/BasicVectorTypesHelpers.h>
75 <<
" is not a valid joint.";
84 <<
" is not a valid joint.";
91 <<
" is not a valid node.";
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() -
179 .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());
252 bool oldEnabledGui =
_guiTab.getValue<
bool>(
"enabled").get();
253 std::string oldFrameGui =
_guiTab.getValue<std::string>(
"tracking_frame").get();
265 oldFrameGui !=
_guiTab.getValue<std::string>(
"tracking_frame").get())
274 if (
_guiTab.getButton(
"button_look_at_frame").clicked())
279 if (
_guiTab.getButton(
"button_look_at_global_point").clicked())
282 Vector3f{
_guiTab.getValue<
float>(
"global_point_x").get(),
283 _guiTab.getValue<
float>(
"global_point_y").get(),
284 _guiTab.getValue<
float>(
"global_point_z").get()});
287 if (
_guiTab.getButton(
"button_look_at_robot_point").clicked())
290 Vector3f{
_guiTab.getValue<
float>(
"robot_point_x").get(),
291 _guiTab.getValue<
float>(
"robot_point_y").get(),
292 _guiTab.getValue<
float>(
"robot_point_z").get()});
295 if (
_guiTab.getButton(
"button_scan_in_configuration_space").clicked())
298 _guiTab.getValue<
float>(
"scan_in_configuration_space_yaw_from").get(),
299 _guiTab.getValue<
float>(
"scan_in_configuration_space_yaw_to").get(),
300 {_guiTab.getValue<float>(
"scan_in_configuration_space_pitch").get()},
301 _guiTab.getValue<
float>(
"scan_in_configuration_space_velocity").get());
304 if (
_guiTab.getButton(
"button_scan_in_workspace").clicked())
307 {{
_guiTab.getValue<
float>(
"scan_in_workspace_from_x").get(),
308 _guiTab.getValue<
float>(
"scan_in_workspace_from_y").get(),
309 _guiTab.getValue<
float>(
"scan_in_workspace_from_z").get()},
310 {
_guiTab.getValue<
float>(
"scan_in_workspace_to_x").get(),
311 _guiTab.getValue<
float>(
"scan_in_workspace_to_y").get(),
312 _guiTab.getValue<
float>(
"scan_in_workspace_to_z").get()}},
313 _guiTab.getValue<
float>(
"scan_in_workspace_velocity").get(),
314 _guiTab.getValue<
float>(
"scan_in_workspace_acceleration").get());
319 RemoteGui::WidgetPtr rootLayout = rootLayoutBuilder;
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};
455 while (std::abs(
headYawJoint->getJointValue() - yaw) >
static_cast<float>(
M_PI / 180.) ||
459 <<
" pitch: " <<
headPitchJoint->getJointValue() <<
" -> " << pitch;
462 nanosleep(&req,
nullptr);
473 const Ice::FloatSeq& pitchValues,
482 velocity = std::abs(velocity);
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))
529 std::swap(yawFrom, 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));
559 while (std::abs(target.currentYawPos - target.desiredYawPos) >
560 static_cast<float>(
M_PI / 180.) ||
561 std::abs(target.currentPitchPos - target.desiredPitchPos) >
562 static_cast<float>(
M_PI / 180.))
564 ARMARX_INFO <<
"yaw: " << target.currentYawPos <<
" - " << target.desiredYawPos
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());
652 std::abs(currentYaw - yaw) >
headYawJoint->getJointLimitHi() -
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;
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},
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
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)