PointingIK.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "Side.h"
6 #include <simox/control/impl/simox/robot/Robot.h>
7 #include <simox/example/method/PointingIK.h>
8 
10 {
11 
12  /**
13  * @brief IK to compute trajectory for a pointing gesture.
14  *
15  * Wrapper for simox-control's method::example::PointingIK. Computes a trajectory for a
16  * pointing gesture that lines up the forearm with a target. Uses the robot's human mapping to
17  * obtain relevant joints: All arm-joints until (excluding) the wrist are being used.
18  *
19  * This class keeps an internal robot model. Each call to @ref optimize() optimizes the joint
20  * configuration regarding pointing towards the target. @ref isTargetReached() returns whether
21  * the robot in the latest configuration already points at the target. @ref getTrajectory()
22  * returns the sequence of generated configurations as Trajectory.
23  *
24  * Example usage:
25  *
26  * @code
27  * ik = PointingIK(...);
28  *
29  * while (not ik.isTargetReached()) {
30  * if (ik.optimize) < 1e-6 {
31  * return nullptr;
32  * }
33  * }
34  * return ik.getTrajectory();
35  * @endcode
36  *
37  * @ingroup Library-pointing
38  */
39  class PointingIK
40  {
41  public:
42  /**
43  * @brief Initialize a new PointingIK.
44  * @param robot Robot model with current robot configuration to be used by the IK. Must
45  * provide a human mapping.
46  * @param side Side of the arm to point with.
47  * @param target Target position to point at in the global coordinate system (mm).
48  */
49  PointingIK(VirtualRobot::RobotPtr robot, Side side, Eigen::Vector3f& target);
50 
51  /**
52  * @return Whether the robot in the latest joint configuration (from @ref optimize())
53  * already points at the target.
54  */
55  bool isTargetReached();
56 
57  /**
58  * @brief Optimizes the joint configuration of the internal robot model regarding pointing
59  * towards the target.
60  * @return Difference between the previous and new joint configurations. May be used to
61  * determine if the IK is unable to find a solution.
62  */
63  double optimize();
64 
65  /**
66  * @brief Constructs a trajectory containing the sequence of joint configurations from the
67  * calls to @ref optimize().
68  *
69  * Neither the trajectory nor the end configuration are guaranteed to be self-
70  * collision free. Furthermore, the trajectories aren't efficient in reaching the end
71  * configuration.
72  *
73  * `getTrajectory()->size()` will equal the number of calls to @ref optimize() plus one for
74  * the initial joint configuration
75  *
76  * @return The constructed trajectory.
77  */
79 
80  private:
81  std::unique_ptr<simox::control::simox::robot::Robot> reducedRobot_;
82  std::unique_ptr<simox::control::method::example::PointingIK> ik_;
83 
84  std::vector<std::vector<double>> trajData; // actuated joints x timesteps
85  void appendTrajData(const Eigen::VectorXd& jointValues);
86  };
87 
88 } // namespace armarx::control::pointing::core
armarx::control::pointing::core
Definition: Pointing.cpp:13
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
IceInternal::Handle< Trajectory >
armarx::control::pointing::core::Side
Side
Describes the side of an arm.
Definition: Side.h:10
armarx::control::pointing::core::PointingIK::getTrajectory
armarx::TrajectoryPtr getTrajectory()
Constructs a trajectory containing the sequence of joint configurations from the calls to optimize().
Definition: PointingIK.cpp:57
armarx::control::pointing::core::PointingIK::isTargetReached
bool isTargetReached()
Definition: PointingIK.cpp:42
armarx::control::pointing::core::PointingIK::optimize
double optimize()
Optimizes the joint configuration of the internal robot model regarding pointing towards the target.
Definition: PointingIK.cpp:48
Trajectory.h
armarx::control::pointing::core::PointingIK
IK to compute trajectory for a pointing gesture.
Definition: PointingIK.h:39
Side.h
armarx::control::pointing::core::PointingIK::PointingIK
PointingIK(VirtualRobot::RobotPtr robot, Side side, Eigen::Vector3f &target)
Initialize a new PointingIK.
Definition: PointingIK.cpp:9
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18