MovePlatformToPose.cpp
Go to the documentation of this file.
1 #include "MovePlatformToPose.h"
2 
3 #include "util/PlatformUtil.h"
4 
6 
7 namespace armarx::skills
8 {
9  namespace
10  {
11  platform_control::arondto::MovePlatformToPoseAcceptedType GetDefaultParameterization()
12  {
13  platform_control::arondto::MovePlatformToPoseAcceptedType ret;
14  ret.orientationalAccuracy = 0.1;
15  ret.positionalAccuracy = 100;
16  return ret;
17  }
18  }
19 
20  SkillDescription MovePlatformToPose::Description = skills::SkillDescription{
21  "MovePlatformToPosition", "Move a platform unit to target pos.",
23  platform_control::arondto::MovePlatformToPoseAcceptedType::ToAronType(),
24  GetDefaultParameterization().toAron()
25  };
26 
28  PlatformControlSkill(mns, arviz, Description.skillName, context),
29  mixin::RobotReadingSkillMixin(mns),
30  PeriodicSimpleSpecializedSkill<ArgType>(Description, armarx::core::time::Frequency::Hertz(10))
31  {
32  }
33 
34  Skill::InitResult MovePlatformToPose::init(const SpecializedInitInput& in)
35  {
36  // setup memory reader
38 
39  return {.status = TerminatedSkillStatus::Succeeded};
40  }
41 
42  Skill::ExitResult MovePlatformToPose::exit(const SpecializedExitInput& in)
43  {
45  clearLayer();
46 
47  return {.status = TerminatedSkillStatus::Succeeded};
48  }
49 
50  PeriodicSkill::StepResult MovePlatformToPose::step(const SpecializedMainInput& in)
51  {
52  clearLayer();
53 
54  {
55  auto l = arviz.layer(layerName);
56  auto a = armarx::viz::Sphere("MovePlatformToPose::targetPose");
57  a.pose(in.parameters.pose);
58  a.radius(40);
59  a.color(viz::Color::yellow());
60  l.add(a);
61  arviz.commit(l);
62  }
63 
64  auto robot = robotReader.getSynchronizedRobot(in.parameters.robotName, armem::Time::Now(), VirtualRobot::RobotIO::RobotDescription::eStructure);
65  if (!robot)
66  {
67  ARMARX_WARNING << "Unable to get robot from robotstatememory. Abort.";
68  return {ActiveOrTerminatedSkillStatus::Failed, nullptr};
69  }
70 
71  FramedPosePtr robotPose = new FramedPose(robot->getRootNode()->getPoseInRootFrame(),
72  robot->getRootNode()->getName(),
73  robot->getName());
74  auto robotPoseGlobalEigen = robotPose->toGlobalEigen(robot);
75 
76  float targetX = in.parameters.pose(0,3);
77  float targetY = in.parameters.pose(1,3);
78 
79  Eigen::Matrix3f targetRotMat = in.parameters.pose.block<3, 3>(0, 0);
80  Eigen::Vector3f targetRotMatX = targetRotMat * Eigen::Vector3f::UnitX();
81  float targetOri = atan2(targetRotMatX[1], targetRotMatX[0]);
82  if (targetOri > M_PI) // normalize
83  {
84  targetOri = - 2 * M_PI + targetOri;
85  }
86 
87  float robotX = robotPoseGlobalEigen(0,3);
88  float robotY = robotPoseGlobalEigen(1,3);
89 
90  Eigen::Matrix3f robotRotMat = robotPoseGlobalEigen.block<3, 3>(0, 0);
91  Eigen::Vector3f robotRotMatX = robotRotMat * Eigen::Vector3f::UnitX();
92  float robotOri = atan2(robotRotMatX[1], robotRotMatX[0]);
93  if (robotOri > M_PI) // normalize
94  {
95  robotOri = - 2 * M_PI + robotOri;
96  }
97 
98  ARMARX_INFO << deactivateSpam() << "Platform current pose: (" << robotX << ", " << robotY << ", " << robotOri << ")";
99  ARMARX_INFO << deactivateSpam() << "Platform target: (" << targetX << ", " << targetY << ", " << targetOri << ")";
100 
101  float translationalError = (robotPoseGlobalEigen.block<3,1>(0,3) - Eigen::Vector3f(targetX, targetY, 0)).norm();
102  float orientationalError = targetOri - robotOri;
103 
104  // transform alpha to [-pi, pi)
105  while (orientationalError < -M_PI)
106  {
107  orientationalError += 2 * M_PI;
108  }
109 
110  while (orientationalError >= M_PI)
111  {
112  orientationalError -= 2 * M_PI;
113  }
114 
115  ARMARX_INFO << deactivateSpam() << "Platform target position error: (" << translationalError << ")";
116  ARMARX_INFO << deactivateSpam() << "Platform target orientation error: (" << orientationalError << ")";
117 
118  if (translationalError > in.parameters.positionalAccuracy or orientationalError > in.parameters.orientationalAccuracy)
119  {
120  ARMARX_INFO << deactivateSpam() << "Platform position accuracy (" << in.parameters.positionalAccuracy << ")";
121  ARMARX_INFO << deactivateSpam() << "Platform orientation accuracy: (" << in.parameters.orientationalAccuracy << ")";
122  context.platformUnitPrx->moveTo(targetX, targetY, targetOri, in.parameters.positionalAccuracy*0.8, in.parameters.orientationalAccuracy*0.8);
123  return {ActiveOrTerminatedSkillStatus::Running, nullptr};
124  }
126  }
127 }
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:80
armarx::skills::SimpleSpecializedSkill< platform_control::arondto::MovePlatformToPoseAcceptedType >::init
Skill::InitResult init() final
Definition: SimpleSpecializedSkill.h:62
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::skills::TerminatedSkillStatus::Succeeded
@ Succeeded
armarx::skills::ActiveOrTerminatedSkillStatus::Succeeded
@ Succeeded
armarx::skills::ActiveOrTerminatedSkillStatus::Failed
@ Failed
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
armarx::skills
This file is part of ArmarX.
Definition: PeriodicUpdateWidget.cpp:11
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::skills::mixin::RobotReadingSkillMixin::robotReader
armem::robot_state::VirtualRobotReader robotReader
Definition: RobotReadingSkillMixin.h:11
armarx::FramedPosePtr
IceInternal::Handle< FramedPose > FramedPosePtr
Definition: FramedPose.h:250
armarx::skills::MovePlatformToPose::Description
static SkillDescription Description
Definition: MovePlatformToPose.h:66
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:17
armarx::armem::robot_state::RobotReader::connect
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: RobotReader.cpp:48
armarx::skills::MovePlatformToPose::ArgType
platform_control::arondto::MovePlatformToPoseAcceptedType ArgType
Definition: MovePlatformToPose.h:53
armarx::viz::Sphere
Definition: Elements.h:134
MovePlatformToPose.h
armarx::skills::mixin::ArvizSkillMixin::arviz
armarx::viz::Client arviz
Definition: ArvizSkillMixin.h:11
armarx::skills::SimpleSpecializedSkill< platform_control::arondto::MovePlatformToPoseAcceptedType >::exit
Skill::ExitResult exit() final
Definition: SimpleSpecializedSkill.h:81
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::skills::MovePlatformToPose::MovePlatformToPose
MovePlatformToPose(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, PlatformControlSkillContext &context)
Definition: MovePlatformToPose.cpp:27
M_PI
#define M_PI
Definition: MathTools.h:17
FramedPose.h
armarx::skills::PlatformControlSkill
Definition: PlatformControlSkill.h:56
armarx::viz::Color::yellow
static Color yellow(int y=255, int a=255)
Red + Green.
Definition: Color.h:104
armarx::skills::PlatformControlSkill::context
PlatformControlSkillContext & context
Definition: PlatformControlSkill.h:76
armarx::skills::mixin::ArvizSkillMixin::layerName
std::string layerName
Definition: ArvizSkillMixin.h:12
armarx::armem::robot_state::VirtualRobotReader::getSynchronizedRobot
VirtualRobot::RobotPtr getSynchronizedRobot(const std::string &name, const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure, bool blocking=true)
armarx::skills::PlatformControlSkillContext
Definition: PlatformControlSkill.h:45
PlatformUtil.h
armarx::skills::ActiveOrTerminatedSkillStatus::Running
@ Running
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
armarx::skills::PlatformControlSkill::stopPlatformMovement
TerminatedSkillStatus stopPlatformMovement()
Definition: PlatformControlSkill.h:69
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::skills::mixin::ArvizSkillMixin::clearLayer
void clearLayer()
Definition: ArvizSkillMixin.h:20
armarx::skills::Skill::InitResult
A result struct for skill initialization.
Definition: Skill.h:36
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::skills::PlatformControlSkillContext::platformUnitPrx
PlatformUnitInterfacePrx platformUnitPrx
Definition: PlatformControlSkill.h:48
armarx::Logging::deactivateSpam
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.
Definition: Logging.cpp:92
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:73
armarx::viz::Client
Definition: Client.h:109
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55
norm
double norm(const Point &a)
Definition: point.hpp:94