|
30 | 30 | #include <tesseract_command_language/move_instruction.h>
|
31 | 31 | #include <tesseract_command_language/plan_instruction.h>
|
32 | 32 | #include <tesseract_command_language/instruction_type.h>
|
| 33 | +#include <trajopt_ifopt/trajopt_ifopt.h> |
| 34 | +#include <trajopt_ifopt/utils/ifopt_utils.h> |
33 | 35 |
|
34 | 36 | namespace tesseract_planning
|
35 | 37 | {
|
36 |
| -//TrajOptDefaultPlanProfile::TrajOptDefaultPlanProfile(const tinyxml2::XMLElement& xml_element) |
37 |
| -//{ |
38 |
| -// const tinyxml2::XMLElement* cartesian_coeff_element = xml_element.FirstChildElement("CartesianCoeff"); |
39 |
| -// const tinyxml2::XMLElement* joint_coeff_element = xml_element.FirstChildElement("JointCoeff"); |
40 |
| -// const tinyxml2::XMLElement* term_type_element = xml_element.FirstChildElement("Term"); |
41 |
| -// const tinyxml2::XMLElement* cnt_error_fn_element = xml_element.FirstChildElement("ConstraintErrorFunctions"); |
42 |
| - |
43 |
| -// tinyxml2::XMLError status; |
44 |
| - |
45 |
| -// if (cartesian_coeff_element) |
46 |
| -// { |
47 |
| -// std::vector<std::string> cart_coeff_tokens; |
48 |
| -// std::string cart_coeff_string; |
49 |
| -// status = tesseract_common::QueryStringText(cartesian_coeff_element, cart_coeff_string); |
50 |
| -// if (status != tinyxml2::XML_NO_ATTRIBUTE && status != tinyxml2::XML_SUCCESS) |
51 |
| -// throw std::runtime_error("TrajoptPlanProfile: Error parsing CartesianCoeff string"); |
52 |
| - |
53 |
| -// boost::split(cart_coeff_tokens, cart_coeff_string, boost::is_any_of(" "), boost::token_compress_on); |
54 |
| - |
55 |
| -// if (!tesseract_common::isNumeric(cart_coeff_tokens)) |
56 |
| -// throw std::runtime_error("TrajoptPlanProfile: CartesianCoeff are not all numeric values."); |
57 |
| - |
58 |
| -// cartesian_coeff.resize(static_cast<long>(cart_coeff_tokens.size())); |
59 |
| -// for (std::size_t i = 0; i < cart_coeff_tokens.size(); ++i) |
60 |
| -// tesseract_common::toNumeric<double>(cart_coeff_tokens[i], cartesian_coeff[static_cast<long>(i)]); |
61 |
| -// } |
62 |
| - |
63 |
| -// if (joint_coeff_element) |
64 |
| -// { |
65 |
| -// std::vector<std::string> joint_coeff_tokens; |
66 |
| -// std::string joint_coeff_string; |
67 |
| -// status = tesseract_common::QueryStringText(joint_coeff_element, joint_coeff_string); |
68 |
| -// if (status != tinyxml2::XML_NO_ATTRIBUTE && status != tinyxml2::XML_SUCCESS) |
69 |
| -// throw std::runtime_error("TrajoptPlanProfile: Error parsing JointCoeff string"); |
70 |
| - |
71 |
| -// boost::split(joint_coeff_tokens, joint_coeff_string, boost::is_any_of(" "), boost::token_compress_on); |
72 |
| - |
73 |
| -// if (!tesseract_common::isNumeric(joint_coeff_tokens)) |
74 |
| -// throw std::runtime_error("TrajoptPlanProfile: JointCoeff are not all numeric values."); |
75 |
| - |
76 |
| -// joint_coeff.resize(static_cast<long>(joint_coeff_tokens.size())); |
77 |
| -// for (std::size_t i = 0; i < joint_coeff_tokens.size(); ++i) |
78 |
| -// tesseract_common::toNumeric<double>(joint_coeff_tokens[i], joint_coeff[static_cast<long>(i)]); |
79 |
| -// } |
80 |
| - |
81 |
| -// if (term_type_element) |
82 |
| -// { |
83 |
| -// int type = static_cast<int>(trajopt::TermType::TT_CNT); |
84 |
| -// status = term_type_element->QueryIntAttribute("type", &type); |
85 |
| -// if (status != tinyxml2::XML_SUCCESS) |
86 |
| -// throw std::runtime_error("TrajoptPlanProfile: Error parsing Term type attribute."); |
87 |
| - |
88 |
| -// term_type = static_cast<trajopt::TermType>(type); |
89 |
| -// } |
90 |
| - |
91 |
| -// if (cnt_error_fn_element) |
92 |
| -// { |
93 |
| -// std::string error_fn_name; |
94 |
| -// status = tesseract_common::QueryStringAttribute(cnt_error_fn_element, "type", error_fn_name); |
95 |
| -// if (status != tinyxml2::XML_SUCCESS) |
96 |
| -// throw std::runtime_error("TrajoptPlanProfile: Error parsing ConstraintErrorFunctions plugin attribute."); |
97 |
| - |
98 |
| -// // TODO: Implement plugin capabilities |
99 |
| -// } |
100 |
| -//} |
101 |
| -//void TrajOptDefaultPlanProfile::apply(TrajOptIfoptProblem& problem, |
102 |
| -// const Eigen::Isometry3d& cartesian_waypoint, |
103 |
| -// const Instruction& parent_instruction, |
104 |
| -// const ManipulatorInfo& manip_info, |
105 |
| -// const std::vector<std::string>& active_links, |
106 |
| -// int index) |
107 |
| -//{ |
108 |
| -// assert(isPlanInstruction(parent_instruction)); |
109 |
| -// const auto* base_instruction = parent_instruction.cast_const<PlanInstruction>(); |
110 |
| -// assert(!(manip_info.isEmpty() && base_instruction->getManipulatorInfo().isEmpty())); |
111 |
| -// const ManipulatorInfo& mi = |
112 |
| -// (base_instruction->getManipulatorInfo().isEmpty()) ? manip_info : base_instruction->getManipulatorInfo(); |
113 |
| - |
114 |
| -// trajopt::TermInfo::Ptr ti{ nullptr }; |
115 |
| - |
116 |
| -// /* Check if this cartesian waypoint is dynamic |
117 |
| -// * (i.e. defined relative to a frame that will move with the kinematic chain) |
118 |
| -// */ |
119 |
| -// auto it = std::find(active_links.begin(), active_links.end(), mi.working_frame); |
120 |
| -// if (it != active_links.end()) |
121 |
| -// { |
122 |
| -// ti = createDynamicCartesianWaypointTermInfo( |
123 |
| -// cartesian_waypoint, index, mi.working_frame, mi.tcp, cartesian_coeff, pci.kin->getTipLinkName(), term_type); |
124 |
| -// } |
125 |
| -// else |
126 |
| -// { |
127 |
| -// ti = createCartesianWaypointTermInfo( |
128 |
| -// cartesian_waypoint, index, mi.working_frame, mi.tcp, cartesian_coeff, pci.kin->getTipLinkName(), term_type); |
129 |
| -// } |
130 |
| - |
131 |
| -// if (term_type == trajopt::TermType::TT_CNT) |
132 |
| -// pci.cnt_infos.push_back(ti); |
133 |
| -// else |
134 |
| -// pci.cost_infos.push_back(ti); |
135 |
| -//} |
136 |
| - |
137 |
| -//void TrajOptDefaultPlanProfile::apply(TrajOptIfoptProblem& problem, |
138 |
| -// const Eigen::VectorXd& joint_waypoint, |
139 |
| -// const Instruction& /*parent_instruction*/, |
140 |
| -// const ManipulatorInfo& /*manip_info*/, |
141 |
| -// const std::vector<std::string>& /*active_links*/, |
142 |
| -// int index) |
143 |
| -//{ |
144 |
| -// auto ti = createJointWaypointTermInfo(joint_waypoint, index, joint_coeff, term_type); |
145 |
| - |
146 |
| -// if (term_type == trajopt::TermType::TT_CNT) |
147 |
| -// pci.cnt_infos.push_back(ti); |
148 |
| -// else |
149 |
| -// pci.cost_infos.push_back(ti); |
150 |
| -//} |
151 |
| - |
152 |
| -//tinyxml2::XMLElement* TrajOptDefaultPlanProfile::toXML(tinyxml2::XMLDocument& doc) const |
153 |
| -//{ |
154 |
| -// Eigen::IOFormat eigen_format(Eigen::StreamPrecision, 0, " ", " "); |
155 |
| - |
156 |
| -// tinyxml2::XMLElement* xml_planner = doc.NewElement("Planner"); |
157 |
| -// xml_planner->SetAttribute("type", std::to_string(1).c_str()); |
158 |
| - |
159 |
| -// tinyxml2::XMLElement* xml_trajopt = doc.NewElement("TrajoptPlanProfile"); |
160 |
| - |
161 |
| -// tinyxml2::XMLElement* xml_cart_coeff = doc.NewElement("CartesianCoefficients"); |
162 |
| -// std::stringstream cart_coeff; |
163 |
| -// cart_coeff << cartesian_coeff.format(eigen_format); |
164 |
| -// xml_cart_coeff->SetText(cart_coeff.str().c_str()); |
165 |
| -// xml_trajopt->InsertEndChild(xml_cart_coeff); |
166 |
| - |
167 |
| -// tinyxml2::XMLElement* xml_joint_coeff = doc.NewElement("JointCoefficients"); |
168 |
| -// std::stringstream jnt_coeff; |
169 |
| -// jnt_coeff << joint_coeff.format(eigen_format); |
170 |
| -// xml_joint_coeff->SetText(jnt_coeff.str().c_str()); |
171 |
| -// xml_trajopt->InsertEndChild(xml_joint_coeff); |
172 |
| - |
173 |
| -// tinyxml2::XMLElement* xml_term_type = doc.NewElement("Term"); |
174 |
| -// xml_term_type->SetAttribute("type", static_cast<int>(term_type)); |
175 |
| -// xml_trajopt->InsertEndChild(xml_term_type); |
176 |
| - |
177 |
| -// xml_planner->InsertEndChild(xml_trajopt); |
| 38 | +void TrajOptIfoptDefaultPlanProfile::apply(TrajOptIfoptProblem& problem, |
| 39 | + const CartesianWaypoint& cartesian_waypoint, |
| 40 | + const Instruction& parent_instruction, |
| 41 | + const ManipulatorInfo& manip_info, |
| 42 | + const std::vector<std::string>& active_links, |
| 43 | + int index) |
| 44 | +{ |
| 45 | + assert(isPlanInstruction(parent_instruction)); |
| 46 | + const auto* base_instruction = parent_instruction.cast_const<PlanInstruction>(); |
| 47 | + assert(!(manip_info.isEmpty() && base_instruction->getManipulatorInfo().isEmpty())); |
| 48 | + const ManipulatorInfo& mi = |
| 49 | + (base_instruction->getManipulatorInfo().empty()) ? manip_info : base_instruction->getManipulatorInfo(); |
| 50 | + |
| 51 | + /* Check if this cartesian waypoint is dynamic |
| 52 | + * (i.e. defined relative to a frame that will move with the kinematic chain) |
| 53 | + */ |
| 54 | + auto it = std::find(active_links.begin(), active_links.end(), mi.working_frame); |
| 55 | + if (it != active_links.end()) |
| 56 | + { |
| 57 | + CONSOLE_BRIDGE_logWarn("Dynamic cartesian terms are not supported by trajopt_ifopt. PRs welcome"); |
| 58 | + } |
| 59 | + else |
| 60 | + { |
| 61 | + auto ti = createCartesianWaypointTermInfo( |
| 62 | + cartesian_waypoint, index, mi.working_frame, mi.tcp, cartesian_coeff, problem.manip_fwd_kin->getTipLinkName()); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +void TrajOptIfoptDefaultPlanProfile::apply(TrajOptIfoptProblem& problem, |
| 67 | + const JointWaypoint& joint_waypoint, |
| 68 | + const Instruction& /*parent_instruction*/, |
| 69 | + const ManipulatorInfo& /*manip_info*/, |
| 70 | + const std::vector<std::string>& /*active_links*/, |
| 71 | + int index) |
| 72 | +{ |
| 73 | + auto idx = static_cast<std::size_t>(index); |
| 74 | + switch (term_type) |
| 75 | + { |
| 76 | + case TrajOptIfoptTermType::CONSTRAINT: |
| 77 | + addJointPositionConstraint(problem.nlp, joint_waypoint, problem.vars[idx], joint_coeff); |
| 78 | + break; |
| 79 | + case TrajOptIfoptTermType::SQUARED_COST: |
| 80 | + addJointPositionConstraint(problem.nlp, joint_waypoint, problem.vars[idx], joint_coeff); |
| 81 | + break; |
| 82 | + } |
| 83 | +} |
178 | 84 |
|
179 |
| -// return xml_planner; |
180 |
| -//} |
181 | 85 | } // namespace tesseract_planning
|
0 commit comments