se2ez
ik.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <se2ez/core.h>
4 
5 using namespace se2ez;
6 
7 void testTree(const RobotPtr &robot)
8 {
9  TreeIK ik(robot, robot->getEEs());
10  SE2EZ_INFORM("Testing IK Tree");
11 
12  auto state = std::make_shared<State>(robot);
13 
15  {"ee", tf::toIsometry(Eigen::Vector3d{2, 1, math::pi})} //
16  };
17 
19  {"ee", IKSolver::POSITION} //
20  };
21 
22  if (ik.solve(state, goal, request))
23  {
24  SE2EZ_INFORM("Tree IK Success!");
25  state->fk(robot);
26 
27  std::cout << state->printFrames(robot) << std::endl;
28  std::cout << tf::printVector(state->data) << std::endl;
29  }
30  else
31  SE2EZ_ERROR("Tree IK Failed!");
32 }
33 
34 void testChain(const RobotPtr &robot)
35 {
36  ChainIK ik(robot, "ee");
37  SE2EZ_INFORM("Testing IK Chain");
38 
39  auto state = std::make_shared<State>(robot);
40 
41  if (ik.solve(state, tf::toIsometry(Eigen::Vector3d{2, 1, math::pi}), IKSolver::POSITION))
42  {
43  SE2EZ_INFORM("Chain IK Success!");
44  state->fk(robot);
45 
46  std::cout << state->printFrames(robot) << std::endl;
47  std::cout << tf::printVector(state->data) << std::endl;
48  }
49  else
50  SE2EZ_ERROR("Chain IK Failed!");
51 }
52 
53 int main(int argc, char **argv)
54 {
55  if (argc < 2)
56  {
57  std::cout << "Please give filename to load!" << std::endl;
58  return -1;
59  }
60 
61  auto robot = io::loadRobot(std::string(argv[1]));
62  if (!robot)
63  return -1;
64 
65  std::cout << robot->printTree() << std::endl;
66 
67  testTree(robot);
68  testChain(robot);
69 }
X- and Y-axis components.
Definition: ik.h:47
RobotPtr loadRobot(const std::string &filename)
Loads a robot from a YAML file.
Definition: yaml.cpp:303
Convenience wrapper around TreeIK for solving chains with a single tip frame.
Definition: ik.h:216
static const double pi
Definition: math.h:32
int main(int argc, char **argv)
Definition: ik.cpp:53
bool solve(StatePtr state, const Eigen::Isometry2d &frame, Request request=ALL)
Solve an IK request.
Definition: ik.cpp:238
T endl(T... args)
#define SE2EZ_INFORM(fmt,...)
Definition: log.h:43
Eigen::Isometry2d toIsometry(double x, double y, double theta)
Converts a translation (x, y) and rotation from X-axis (theta) into a transform.
Definition: math.cpp:11
A shared pointer wrapper for se2ez::Robot.
std::string printVector(const Eigen::VectorXd &v, unsigned int precision=4)
Returns a string of a vector&#39;s contents.
Definition: math.cpp:90
Main namespace.
Definition: collision.h:11
#define SE2EZ_ERROR(fmt,...)
Definition: log.h:39
void testTree(const RobotPtr &robot)
Definition: ik.cpp:7
void testChain(const RobotPtr &robot)
Definition: ik.cpp:34