grasp_candidate_drawer.cpp
Go to the documentation of this file.
1 #include <SimoxUtility/math/pose/pose.h>
2 
4 
5 #include <utility>
6 
8 
9 namespace armarx
10 {
13  const VirtualRobot::RobotPtr& robot)
14  : rnh(std::move(rnh)), robot{robot}
15  {}
16 
18  {
19  _color_offset = 0;
20  }
21 
22  void grasp_candidate_drawer::draw(const armarx::grasping::GraspCandidatePtr& gc, armarx::viz::Layer& l)
23  {
24  draw(gc, l, simox::color::GlasbeyLUT::at(_color_offset, 255));
25  }
27  {
28  draw(gch, l, simox::color::GlasbeyLUT::at(_color_offset, 255));
29  }
30  void grasp_candidate_drawer::draw(const armarx::grasping::GraspCandidatePtr& gc, armarx::viz::Layer& l, const armarx::viz::Color& color)
31  {
34  draw(armarx::GraspCandidateHelper{gc, robot}, l, color);
35  }
37  {
41  const auto& s = side(gch);
42  const std::string name = "grasp_" + s.name + "_" + std::to_string(_color_offset++);
43  l.add(armarx::viz::Robot(name + "_robot")
44  .file(s.hand_model_package, s.hand_model_path)
45  .overrideColor(color)
46  .pose(gch.getGraspPoseInGlobal() * s.tcp_2_hroot));
47  const Eigen::Vector3f targ = gch.getGraspPositionInGlobal();
48  const Eigen::Vector3f appr = gch.getApproachVector();
49  const Eigen::Vector3f from = targ - appr * length_approach;
50  l.add(armarx::viz::Arrow(name + "_approach")
51  .color(color)
52  .width(width_approach)
53  .fromTo(from, targ));
54  }
55 
58  float ax_len, float ax_width,
59  const armarx::viz::Color& color_up, const armarx::viz::Color& color_trans)
60  {
61  draw(side.name, side, l, ax_len, ax_width, color_up, color_trans);
62  }
64  const std::string& name,
66  float ax_len, float ax_width,
67  const armarx::viz::Color& color_up, const armarx::viz::Color& color_trans)
68  {
69  draw(side, l, side.nh_arm_w_rob.getTCP()->getGlobalPose(),
70  ax_len, ax_width, color_up, color_trans);
71  }
74  const Eigen::Matrix4f& gpose, float ax_len, float ax_width,
75  const armarx::viz::Color& color_up, const armarx::viz::Color& color_trans)
76  {
77  draw("", side, l, gpose, ax_len, ax_width, color_up, color_trans);
78  }
80  const std::string& name,
82  const Eigen::Matrix4f& gpose, float ax_len, float ax_width,
83  const armarx::viz::Color& color_up, const armarx::viz::Color& color_trans)
84  {
85  const Eigen::Vector3f hand_up =
86  simox::math::orientation(gpose) * side.hand_up.normalized() * ax_len;
87 
88  const Eigen::Vector3f transversal_outward =
89  simox::math::orientation(gpose) * side.hand_transverse.normalized() * ax_len;
90 
91  const Eigen::Vector3f tcp_pos = simox::math::position(gpose);
92 
93  l.add(armarx::viz::Arrow(name + "hand_up")
94  .color(color_up)
95  .width(ax_width)
96  .fromTo(tcp_pos, tcp_pos + hand_up));
97  l.add(armarx::viz::Arrow(name + "transversal_outward")
98  .color(color_trans)
99  .width(ax_width)
100  .fromTo(tcp_pos, tcp_pos + transversal_outward));
101  }
102 
103  const grasp_candidate_drawer::side_data&
104  grasp_candidate_drawer::side(const armarx::GraspCandidateHelper& gch)
105  {
106  ARMARX_TRACE;
107  const std::string& s = gch.getGraspCandidate()->side;
108  if (_sides.count(s))
109  {
110  return _sides.at(s);
111  }
112  ARMARX_TRACE;
114  const auto nh = rnh->getArm(s);
115  const auto nh_w_rob = nh.addRobot(robot);
116  auto& data = _sides[s];
117  data.name = s;
118  data.hand_model_package = nh.getHandModelPackage();
119  data.hand_model_path = nh.getHandModelPath();
120  data.tcp_2_hroot = nh_w_rob.getTcp2HandRootTransform();
121  return data;
122  }
123 }
armarx::GraspCandidateHelper::getGraspCandidate
const grasping::GraspCandidatePtr getGraspCandidate() const
Definition: GraspCandidateHelper.h:61
armarx::grasp_candidate_drawer::length_approach
float length_approach
Definition: grasp_candidate_drawer.h:60
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
trace.h
armarx::grasp_candidate_drawer::grasp_candidate_drawer
grasp_candidate_drawer(armarx::RobotNameHelperPtr rnh, const VirtualRobot::RobotPtr &robot)
Definition: grasp_candidate_drawer.cpp:11
armarx::viz::Arrow
Definition: Elements.h:198
armarx::box_to_grasp_candidates::side_data::nh_arm_w_rob
armarx::RobotNameHelper::RobotArm nh_arm_w_rob
Definition: box_to_grasp_candidates.h:79
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:29
armarx::box_to_grasp_candidates::side_data
Definition: box_to_grasp_candidates.h:75
armarx::GraspCandidateHelper::getApproachVector
Eigen::Vector3f getApproachVector() const
Definition: GraspCandidateHelper.cpp:80
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::box_to_grasp_candidates::side_data::name
std::string name
Definition: box_to_grasp_candidates.h:77
armarx::RobotNameHelperPtr
std::shared_ptr< class RobotNameHelper > RobotNameHelperPtr
Definition: RobotNameHelper.h:34
armarx::GraspCandidateHelper
Definition: GraspCandidateHelper.h:38
armarx::RobotArm::getTCP
VirtualRobot::RobotNodePtr getTCP() const
Definition: RobotNameHelper.cpp:329
armarx::GraspCandidateHelper::getGraspPositionInGlobal
Eigen::Vector3f getGraspPositionInGlobal() const
Definition: GraspCandidateHelper.cpp:75
armarx::box_to_grasp_candidates::side_data::hand_up
Eigen::Vector3f hand_up
Definition: box_to_grasp_candidates.h:81
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::grasp_candidate_drawer::width_approach
float width_approach
Definition: grasp_candidate_drawer.h:61
armarx::viz::Color
Definition: Color.h:13
armarx::grasp_candidate_drawer::reset_colors
void reset_colors()
Definition: grasp_candidate_drawer.cpp:17
armarx::viz::Robot::overrideColor
Robot & overrideColor(Color c)
Definition: Robot.h:36
grasp_candidate_drawer.h
armarx::viz::Robot
Definition: Robot.h:9
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::grasp_candidate_drawer::robot
VirtualRobot::RobotPtr robot
Definition: grasp_candidate_drawer.h:59
armarx::grasp_candidate_drawer::draw
void draw(const armarx::grasping::GraspCandidatePtr &gc, armarx::viz::Layer &l)
Definition: grasp_candidate_drawer.cpp:22
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::GraspCandidateHelper::getGraspPoseInGlobal
Eigen::Matrix4f getGraspPoseInGlobal() const
Definition: GraspCandidateHelper.cpp:64
armarx::viz::ElementOps::pose
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition: ElementOps.h:159
std
Definition: Application.h:66
armarx::grasp_candidate_drawer::rnh
armarx::RobotNameHelperPtr rnh
Definition: grasp_candidate_drawer.h:58
armarx::box_to_grasp_candidates::side_data::hand_transverse
Eigen::Vector3f hand_transverse
Definition: box_to_grasp_candidates.h:82
armarx::viz::Layer
Definition: Layer.h:12
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18