Skip to content

Commit

Permalink
Add toleranced waypoints to TrajOpt Solver
Browse files Browse the repository at this point in the history
  • Loading branch information
marrts committed Feb 26, 2024
1 parent febcd0f commit 66673ac
Show file tree
Hide file tree
Showing 12 changed files with 556 additions and 119 deletions.
8 changes: 6 additions & 2 deletions tesseract_examples/src/basic_cartesian_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@ bool BasicCartesianExample::run()
profiles->addProfile<TrajOptCompositeProfile>(TRAJOPT_DEFAULT_NAMESPACE, "cartesian_program", composite_profile);

auto plan_profile = std::make_shared<TrajOptDefaultPlanProfile>();
plan_profile->cartesian_coeff = Eigen::VectorXd::Ones(6);
plan_profile->joint_coeff = Eigen::VectorXd::Ones(7);
plan_profile->cartesian_cost_config.enabled = false;
plan_profile->cartesian_constraint_config.enabled = true;
plan_profile->cartesian_constraint_config.coeff = Eigen::VectorXd::Ones(6);
plan_profile->joint_cost_config.enabled = false;
plan_profile->joint_constraint_config.enabled = true;
plan_profile->joint_constraint_config.coeff = Eigen::VectorXd::Ones(7);
profiles->addProfile<TrajOptPlanProfile>(TRAJOPT_DEFAULT_NAMESPACE, "RASTER", plan_profile);
profiles->addProfile<TrajOptPlanProfile>(TRAJOPT_DEFAULT_NAMESPACE, "freespace_profile", plan_profile);
}
Expand Down
10 changes: 6 additions & 4 deletions tesseract_examples/src/glass_upright_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ bool GlassUprightExample::run()
profiles->addProfile<TrajOptCompositeProfile>(TRAJOPT_DEFAULT_NAMESPACE, "UPRIGHT", composite_profile);

auto plan_profile = std::make_shared<TrajOptDefaultPlanProfile>();
plan_profile->cartesian_coeff = Eigen::VectorXd::Constant(6, 1, 5);
plan_profile->cartesian_coeff(0) = 0;
plan_profile->cartesian_coeff(1) = 0;
plan_profile->cartesian_coeff(2) = 0;
plan_profile->cartesian_cost_config.enabled = false;
plan_profile->cartesian_constraint_config.enabled = true;
plan_profile->cartesian_constraint_config.coeff = Eigen::VectorXd::Constant(6, 1, 5);
plan_profile->cartesian_constraint_config.coeff(0) = 0;
plan_profile->cartesian_constraint_config.coeff(1) = 0;
plan_profile->cartesian_constraint_config.coeff(2) = 0;

// Add profile to Dictionary
profiles->addProfile<TrajOptPlanProfile>(TRAJOPT_DEFAULT_NAMESPACE, "UPRIGHT", plan_profile);
Expand Down
4 changes: 3 additions & 1 deletion tesseract_examples/src/pick_and_place_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ bool PickAndPlaceExample::run()
{
// Create TrajOpt Profile
auto trajopt_plan_profile = std::make_shared<TrajOptDefaultPlanProfile>();
trajopt_plan_profile->cartesian_coeff = Eigen::VectorXd::Constant(6, 1, 10);
trajopt_plan_profile->cartesian_cost_config.enabled = false;
trajopt_plan_profile->cartesian_constraint_config.enabled = true;
trajopt_plan_profile->cartesian_constraint_config.coeff = Eigen::VectorXd::Constant(6, 1, 10);

auto trajopt_composite_profile = std::make_shared<TrajOptDefaultCompositeProfile>();
trajopt_composite_profile->longest_valid_segment_length = 0.05;
Expand Down
10 changes: 6 additions & 4 deletions tesseract_examples/src/puzzle_piece_auxillary_axes_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ bool PuzzlePieceAuxillaryAxesExample::run()
{
// Create TrajOpt Profile
auto trajopt_plan_profile = std::make_shared<tesseract_planning::TrajOptDefaultPlanProfile>();
trajopt_plan_profile->cartesian_coeff = Eigen::VectorXd::Constant(6, 1, 5);
trajopt_plan_profile->cartesian_coeff(3) = 2;
trajopt_plan_profile->cartesian_coeff(4) = 2;
trajopt_plan_profile->cartesian_coeff(5) = 0;
trajopt_plan_profile->cartesian_cost_config.enabled = false;
trajopt_plan_profile->cartesian_constraint_config.enabled = true;
trajopt_plan_profile->cartesian_constraint_config.coeff = Eigen::VectorXd::Constant(6, 1, 5);
trajopt_plan_profile->cartesian_constraint_config.coeff(3) = 2;
trajopt_plan_profile->cartesian_constraint_config.coeff(4) = 2;
trajopt_plan_profile->cartesian_constraint_config.coeff(5) = 0;

auto trajopt_composite_profile = std::make_shared<TrajOptDefaultCompositeProfile>();
trajopt_composite_profile->collision_constraint_config.enabled = false;
Expand Down
6 changes: 4 additions & 2 deletions tesseract_examples/src/puzzle_piece_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ bool PuzzlePieceExample::run()
{
// Create TrajOpt Profile
auto trajopt_plan_profile = std::make_shared<TrajOptDefaultPlanProfile>();
trajopt_plan_profile->cartesian_coeff = Eigen::VectorXd::Constant(6, 1, 10);
trajopt_plan_profile->cartesian_coeff(5) = 0;
trajopt_plan_profile->cartesian_cost_config.enabled = false;
trajopt_plan_profile->cartesian_constraint_config.enabled = true;
trajopt_plan_profile->cartesian_constraint_config.coeff = Eigen::VectorXd::Constant(6, 1, 10);
trajopt_plan_profile->cartesian_constraint_config.coeff(5) = 0;

auto trajopt_composite_profile = std::make_shared<TrajOptDefaultCompositeProfile>();
trajopt_composite_profile->collision_constraint_config.enabled = false;
Expand Down
1 change: 1 addition & 0 deletions tesseract_motion_planners/trajopt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ find_package(trajopt_sco REQUIRED)
add_library(
${PROJECT_NAME}_trajopt
src/trajopt_collision_config.cpp
src/trajopt_waypoint_config.cpp
src/trajopt_motion_planner.cpp
src/trajopt_utils.cpp
src/profile/trajopt_default_plan_profile.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <Eigen/Geometry>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_motion_planners/trajopt/trajopt_waypoint_config.h>
#include <tesseract_motion_planners/trajopt/profile/trajopt_profile.h>

namespace tesseract_planning
Expand All @@ -51,9 +52,10 @@ class TrajOptDefaultPlanProfile : public TrajOptPlanProfile
TrajOptDefaultPlanProfile(TrajOptDefaultPlanProfile&&) = default;
TrajOptDefaultPlanProfile& operator=(TrajOptDefaultPlanProfile&&) = default;

Eigen::VectorXd cartesian_coeff{ Eigen::VectorXd::Constant(1, 1, 5) };
Eigen::VectorXd joint_coeff{ Eigen::VectorXd::Constant(1, 1, 5) };
trajopt::TermType term_type{ trajopt::TermType::TT_CNT };
CartesianWaypointConfig cartesian_cost_config;
CartesianWaypointConfig cartesian_constraint_config;
JointWaypointConfig joint_cost_config;
JointWaypointConfig joint_constraint_config;

/** @brief Error function that is set as a constraint for each timestep.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ trajopt::TermInfo::Ptr createCartesianWaypointTermInfo(int index,
const std::string& tcp_frame,
const Eigen::Isometry3d& tcp_offset,
const Eigen::VectorXd& coeffs,
trajopt::TermType type);

trajopt::TermInfo::Ptr createDynamicCartesianWaypointTermInfo(int index,
const std::string& working_frame,
const Eigen::Isometry3d& c_wp,
const std::string& tcp_frame,
const Eigen::Isometry3d& tcp_offset,
const Eigen::VectorXd& coeffs,
trajopt::TermType type);
trajopt::TermType type,
Eigen::VectorXd lower_tolerance = Eigen::VectorXd::Zero(6),
Eigen::VectorXd upper_tolerance = Eigen::VectorXd::Zero(6));

trajopt::TermInfo::Ptr
createDynamicCartesianWaypointTermInfo(int index,
const std::string& working_frame,
const Eigen::Isometry3d& c_wp,
const std::string& tcp_frame,
const Eigen::Isometry3d& tcp_offset,
const Eigen::VectorXd& coeffs,
trajopt::TermType type,
Eigen::VectorXd lower_tolerance = Eigen::VectorXd::Zero(6),
Eigen::VectorXd upper_tolerance = Eigen::VectorXd::Zero(6));

trajopt::TermInfo::Ptr createNearJointStateTermInfo(const Eigen::VectorXd& target,
const std::vector<std::string>& joint_names,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @file trajopt_waypoint_config.h
* @brief TrajOpt waypoint configuration settings
*
* @author Tyler Marr
* @date November 2, 2023
* @version TODO
* @bug No known bugs
*
* @copyright Copyright (c) 2023, Southwest Research Institute
*
* @par License
* Software License Agreement (Apache License)
* @par
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* @par
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TESSERACT_MOTION_PLANNERS_TRAJOPT_CONFIG_TRAJOPT_WAYPOINT_CONFIG_H
#define TESSERACT_MOTION_PLANNERS_TRAJOPT_CONFIG_TRAJOPT_WAYPOINT_CONFIG_H

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <trajopt/problem_description.hpp>
#include <tinyxml2.h>
#include <boost/algorithm/string.hpp>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_common/utils.h>

namespace tesseract_planning
{
/**
* @brief Config settings for cartesian waypoints
*/
struct CartesianWaypointConfig
{
CartesianWaypointConfig() = default;
CartesianWaypointConfig(const tinyxml2::XMLElement& xml_element);

/** @brief If true, a cost/constraint term will be added to the problem. Default: true*/
bool enabled = true;

/** @brief If true, will override existing waypoint tolerance with described tolerance here. Default: false
* This is useful if you want to have a smaller tolerance for the cost than the constraint.*/
bool use_tolerance_override = false;

/** @brief Distance below waypoint that is allowed. Should be size = 6. First 3 elements are dx, dy, dz. The last 3
* elements are angle axis error allowed (Eigen::AngleAxisd.axis() * Eigen::AngleAxisd.angle()) */
Eigen::VectorXd lower_tolerance;
/** @brief Distance above waypoint that is allowed. Should be size = 6. First 3 elements are dx, dy, dz. The last 3
* elements are angle axis error allowed (Eigen::AngleAxisd.axis() * Eigen::AngleAxisd.angle())*/
Eigen::VectorXd upper_tolerance;

/** @brief coefficients corresponsing to dx, dy, dz, rx, ry, rz*/
Eigen::VectorXd coeff{ Eigen::VectorXd::Constant(1, 1, 5) };

tinyxml2::XMLElement* toXML(tinyxml2::XMLDocument& doc) const;
};

/**
* @brief Config settings for joint waypoints.
*/
struct JointWaypointConfig
{
JointWaypointConfig() = default;
JointWaypointConfig(const tinyxml2::XMLElement& xml_element);

/** @brief If true, a cost/constraint term will be added to the problem. Default: true*/
bool enabled = true;

/** @brief If true, will override existing waypoint tolerance with described tolerance here. Default: false
* This is useful if you want to have a smaller tolerance for the cost than the constraint.*/
bool use_tolerance_override = false;

/** @brief Distance below waypoint that is allowed. Should be size of joints in a joint state*/
Eigen::VectorXd lower_tolerance;
/** @brief Distance above waypoint that is allowed. Should be size of joints in a joint state*/
Eigen::VectorXd upper_tolerance;

/** @brief coefficients corresponsing to joint values*/
Eigen::VectorXd coeff{ Eigen::VectorXd::Constant(1, 1, 5) };

tinyxml2::XMLElement* toXML(tinyxml2::XMLDocument& doc) const;
};
} // namespace tesseract_planning

#endif // TESSERACT_MOTION_PLANNERS_TRAJOPT_CONFIG_TRAJOPT_WAYPOINT_CONFIG_H
Loading

0 comments on commit 66673ac

Please sign in to comment.