grasp_candidate_drawer.cpp
Go to the documentation of this file.
2 
3 #include <utility>
4 
5 #include <SimoxUtility/math/pose/pose.h>
6 #include <VirtualRobot/Nodes/RobotNode.h>
7 
9 
10 namespace armarx
11 {
13  const VirtualRobot::RobotPtr& robot) :
14  rnh(std::move(rnh)), robot{robot}
15  {
16  }
17 
18  void
20  {
21  _color_offset = 0;
22  }
23 
24  void
25  grasp_candidate_drawer::draw(const armarx::grasping::GraspCandidatePtr& gc,
27  {
28  draw(gc, l, simox::color::GlasbeyLUT::at(_color_offset, 255));
29  }
30 
31  void
33  {
34  draw(gch, l, simox::color::GlasbeyLUT::at(_color_offset, 255));
35  }
36 
37  void
38  grasp_candidate_drawer::draw(const armarx::grasping::GraspCandidatePtr& gc,
40  const armarx::viz::Color& color)
41  {
44  draw(armarx::GraspCandidateHelper{gc, robot}, l, color);
45  }
46 
47  void
50  const armarx::viz::Color& color)
51  {
55  const auto& s = side(gch);
56  const std::string name = "grasp_" + s.name + "_" + std::to_string(_color_offset++);
57  l.add(armarx::viz::Robot(name + "_robot")
58  .file(s.hand_model_package, s.hand_model_path)
59  .overrideColor(color)
60  .pose(gch.getGraspPoseInGlobal() * s.tcp_2_hroot));
61  const Eigen::Vector3f targ = gch.getGraspPositionInGlobal();
62  const Eigen::Vector3f appr = gch.getApproachVector();
63  const Eigen::Vector3f from = targ - appr * length_approach;
64  l.add(armarx::viz::Arrow(name + "_approach")
65  .color(color)
66  .width(width_approach)
67  .fromTo(from, targ));
68  }
69 
70  void
73  float ax_len,
74  float ax_width,
75  const armarx::viz::Color& color_up,
76  const armarx::viz::Color& color_trans)
77  {
78  draw(side.name, side, l, ax_len, ax_width, color_up, color_trans);
79  }
80 
81  void
82  grasp_candidate_drawer::draw(const std::string& name,
85  float ax_len,
86  float ax_width,
87  const armarx::viz::Color& color_up,
88  const armarx::viz::Color& color_trans)
89  {
90  draw(side,
91  l,
92  side.nh_arm_w_rob.getTCP()->getGlobalPose(),
93  ax_len,
94  ax_width,
95  color_up,
96  color_trans);
97  }
98 
99  void
102  const Eigen::Matrix4f& gpose,
103  float ax_len,
104  float ax_width,
105  const armarx::viz::Color& color_up,
106  const armarx::viz::Color& color_trans)
107  {
108  draw("", side, l, gpose, ax_len, ax_width, color_up, color_trans);
109  }
110 
111  void
112  grasp_candidate_drawer::draw(const std::string& name,
115  const Eigen::Matrix4f& gpose,
116  float ax_len,
117  float ax_width,
118  const armarx::viz::Color& color_up,
119  const armarx::viz::Color& color_trans)
120  {
121  const Eigen::Vector3f hand_up =
122  simox::math::orientation(gpose) * side.hand_up.normalized() * ax_len;
123 
124  const Eigen::Vector3f transversal_outward =
125  simox::math::orientation(gpose) * side.hand_transverse.normalized() * ax_len;
126 
127  const Eigen::Vector3f tcp_pos = simox::math::position(gpose);
128 
129  l.add(armarx::viz::Arrow(name + "hand_up")
130  .color(color_up)
131  .width(ax_width)
132  .fromTo(tcp_pos, tcp_pos + hand_up));
133  l.add(armarx::viz::Arrow(name + "transversal_outward")
134  .color(color_trans)
135  .width(ax_width)
136  .fromTo(tcp_pos, tcp_pos + transversal_outward));
137  }
138 
139  const grasp_candidate_drawer::side_data&
140  grasp_candidate_drawer::side(const armarx::GraspCandidateHelper& gch)
141  {
142  ARMARX_TRACE;
143  const std::string& s = gch.getGraspCandidate()->side;
144  if (_sides.count(s))
145  {
146  return _sides.at(s);
147  }
148  ARMARX_TRACE;
150  const auto nh = rnh->getArm(s);
151  const auto nh_w_rob = nh.addRobot(robot);
152  auto& data = _sides[s];
153  data.name = s;
154  data.hand_model_package = nh.getHandModelPackage();
155  data.hand_model_path = nh.getHandModelPath();
156  data.tcp_2_hroot = nh_w_rob.getTcp2HandRootTransform();
157  return data;
158  }
159 } // namespace armarx
armarx::GraspCandidateHelper::getGraspCandidate
const grasping::GraspCandidatePtr getGraspCandidate() const
Definition: GraspCandidateHelper.h:62
armarx::grasp_candidate_drawer::length_approach
float length_approach
Definition: grasp_candidate_drawer.h:74
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
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:12
armarx::viz::Arrow
Definition: Elements.h:196
armarx::box_to_grasp_candidates::side_data::nh_arm_w_rob
armarx::RobotNameHelper::RobotArm nh_arm_w_rob
Definition: box_to_grasp_candidates.h:97
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::box_to_grasp_candidates::side_data
Definition: box_to_grasp_candidates.h:93
armarx::GraspCandidateHelper::getApproachVector
Eigen::Vector3f getApproachVector() const
Definition: GraspCandidateHelper.cpp:93
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::box_to_grasp_candidates::side_data::name
std::string name
Definition: box_to_grasp_candidates.h:95
armarx::RobotNameHelperPtr
std::shared_ptr< class RobotNameHelper > RobotNameHelperPtr
Definition: RobotNameHelper.h:32
armarx::GraspCandidateHelper
Definition: GraspCandidateHelper.h:37
armarx::RobotArm::getTCP
VirtualRobot::RobotNodePtr getTCP() const
Definition: RobotNameHelper.cpp:371
armarx::GraspCandidateHelper::getGraspPositionInGlobal
Eigen::Vector3f getGraspPositionInGlobal() const
Definition: GraspCandidateHelper.cpp:87
armarx::box_to_grasp_candidates::side_data::hand_up
Eigen::Vector3f hand_up
Definition: box_to_grasp_candidates.h:99
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::grasp_candidate_drawer::width_approach
float width_approach
Definition: grasp_candidate_drawer.h:75
armarx::viz::Color
Definition: Color.h:12
armarx::grasp_candidate_drawer::reset_colors
void reset_colors()
Definition: grasp_candidate_drawer.cpp:19
armarx::viz::Robot::overrideColor
Robot & overrideColor(Color c)
Definition: Robot.h:50
grasp_candidate_drawer.h
armarx::viz::Robot
Definition: Robot.h:10
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::grasp_candidate_drawer::robot
VirtualRobot::RobotPtr robot
Definition: grasp_candidate_drawer.h:73
armarx::grasp_candidate_drawer::draw
void draw(const armarx::grasping::GraspCandidatePtr &gc, armarx::viz::Layer &l)
Definition: grasp_candidate_drawer.cpp:25
armarx::GraspCandidateHelper::getGraspPoseInGlobal
Eigen::Matrix4f getGraspPoseInGlobal() const
Definition: GraspCandidateHelper.cpp:72
armarx::viz::ElementOps::pose
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition: ElementOps.h:176
std
Definition: Application.h:66
armarx::grasp_candidate_drawer::rnh
armarx::RobotNameHelperPtr rnh
Definition: grasp_candidate_drawer.h:72
armarx::box_to_grasp_candidates::side_data::hand_transverse
Eigen::Vector3f hand_transverse
Definition: box_to_grasp_candidates.h:100
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:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19