Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Trajopt_Ifopt option to all examples #389

Merged
merged 25 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6c52ae1
Add cartesian waypoints to fixed indices
rjoomen Dec 14, 2023
6b22fcb
- Added convex_solver_settings with proper defaults to TrajOptIfoptDe…
rjoomen Nov 28, 2023
699c89f
fixup
rjoomen Nov 28, 2023
2d21596
Restore previous verbosity behaviour
rjoomen Nov 28, 2023
2e9f2ae
Added ifopt option to car_seat_example
rjoomen Oct 2, 2023
1eba9af
Added missing parameters
rjoomen Oct 2, 2023
2af56e3
Fix collision_cost_config->collision_coeff_data
rjoomen Oct 6, 2023
7928fcd
Added ifopt option to pick_and_place_example
rjoomen Oct 6, 2023
44f526b
Added ifopt option to puzzle_piece_example
rjoomen Oct 10, 2023
7b2d802
Fix missing ifopt_ initializer and task_name
rjoomen Oct 10, 2023
1d5a9a7
Adapt to latest trajopt
rjoomen Oct 13, 2023
ff19472
clang-format
rjoomen Nov 28, 2023
7324cb0
Revert "Add cartesian waypoints to fixed indices"
rjoomen Dec 21, 2023
bd9f7d4
Add Ifopt to puzzle_piece_auxillary_axes example
rjoomen Jan 9, 2024
fb0c5a6
Add FreespaceIfoptPipeline
rjoomen Jan 9, 2024
24cd74a
Add Ifopt to freespace_hybrid_example
rjoomen Jan 9, 2024
1fbec97
- Added new TrajoptIfopt solver profiles
rjoomen Jan 9, 2024
f826669
Revert "- Added convex_solver_settings with proper defaults to TrajOp…
rjoomen Jan 9, 2024
8973532
Fix for revert of convex_solver_settings
rjoomen Jan 9, 2024
4a3f57a
Added unit tests for ifopt examples
rjoomen Jan 10, 2024
c9fccfc
Disable pick_and_place_example TrajoptIfopt unit test
rjoomen Jan 10, 2024
debf109
Update number of plugins in unit test
rjoomen Jan 17, 2024
e4d9ff3
Enabled remaining ifopt example unit tests and enabled puzzle piece a…
rjoomen Feb 16, 2024
6789153
Fix pick and place ifopt example version
Levi-Armstrong Feb 17, 2024
97fb925
Update Unstable CI names
Levi-Armstrong Feb 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:

jobs:
ci:
name: ${{ matrix.distro }}
name: ${{ matrix.distro }}-unstable
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <string>
#include <vector>
#include <memory>
#include <Eigen/Geometry>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

Expand All @@ -44,7 +43,9 @@ class CarSeatExample : public Example
{
public:
CarSeatExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter = nullptr);
tesseract_visualization::Visualization::Ptr plotter = nullptr,
bool ifopt = false,
bool debug = false);
~CarSeatExample() override = default;
CarSeatExample(const CarSeatExample&) = default;
CarSeatExample& operator=(const CarSeatExample&) = default;
Expand All @@ -54,6 +55,8 @@ class CarSeatExample : public Example
bool run() override final;

private:
bool ifopt_;
bool debug_;
std::unordered_map<std::string, std::unordered_map<std::string, double>> saved_positions_;

static std::unordered_map<std::string, std::unordered_map<std::string, double>> getPredefinedPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#define TESSERACT_EXAMPLES_FREESPACE_HYBRID_EXAMPLE_H

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <string>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_examples/example.h>

Expand All @@ -44,6 +41,8 @@ class FreespaceHybridExample : public Example
public:
FreespaceHybridExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter = nullptr,
bool ifopt = false,
bool debug = false,
double range = 0.01,
double planning_time = 60.0);
~FreespaceHybridExample() override = default;
Expand All @@ -55,6 +54,8 @@ class FreespaceHybridExample : public Example
bool run() override final;

private:
bool ifopt_;
bool debug_;
double range_;
double planning_time_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class PickAndPlaceExample : public Example
public:
PickAndPlaceExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter = nullptr,
bool ifopt = false,
bool debug = false,
double box_size = 0.2,
std::array<double, 2> box_position = { 0.15, 0.4 });
~PickAndPlaceExample() override = default;
Expand All @@ -56,6 +58,8 @@ class PickAndPlaceExample : public Example
bool run() override final;

private:
bool ifopt_;
bool debug_;
double box_size_;
std::array<double, 2> box_position_;
static tesseract_environment::Command::Ptr addBox(double box_x, double box_y, double box_side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class PuzzlePieceAuxillaryAxesExample : public Example
{
public:
PuzzlePieceAuxillaryAxesExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter = nullptr);
tesseract_visualization::Visualization::Ptr plotter = nullptr,
bool ifopt = false,
bool debug = false);
~PuzzlePieceAuxillaryAxesExample() override = default;
PuzzlePieceAuxillaryAxesExample(const PuzzlePieceAuxillaryAxesExample&) = default;
PuzzlePieceAuxillaryAxesExample& operator=(const PuzzlePieceAuxillaryAxesExample&) = default;
Expand All @@ -57,6 +59,8 @@ class PuzzlePieceAuxillaryAxesExample : public Example
bool run() override final;

private:
bool ifopt_;
bool debug_;
static tesseract_common::VectorIsometry3d
makePuzzleToolPoses(const tesseract_common::ResourceLocator::ConstPtr& locator);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <tesseract_common/macros.h>
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <string>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_common/types.h>
Expand All @@ -45,7 +44,9 @@ class PuzzlePieceExample : public Example
{
public:
PuzzlePieceExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter = nullptr);
tesseract_visualization::Visualization::Ptr plotter = nullptr,
bool ifopt = false,
bool debug = false);
~PuzzlePieceExample() override = default;
PuzzlePieceExample(const PuzzlePieceExample&) = default;
PuzzlePieceExample& operator=(const PuzzlePieceExample&) = default;
Expand All @@ -55,6 +56,8 @@ class PuzzlePieceExample : public Example
bool run() override final;

private:
bool ifopt_;
bool debug_;
static tesseract_common::VectorIsometry3d
makePuzzleToolPoses(const tesseract_common::ResourceLocator::ConstPtr& locator);
};
Expand Down
2 changes: 2 additions & 0 deletions tesseract_examples/src/basic_cartesian_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ bool BasicCartesianExample::run()

if (debug_)
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG);
else
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO);

// Create Task Composer Plugin Factory
const std::string share_dir(TESSERACT_TASK_COMPOSER_DIR);
Expand Down
100 changes: 78 additions & 22 deletions tesseract_examples/src/car_seat_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_motion_planners/trajopt/profile/trajopt_default_composite_profile.h>
#include <tesseract_motion_planners/trajopt/profile/trajopt_default_solver_profile.h>
#include <tesseract_motion_planners/trajopt_ifopt/profile/trajopt_ifopt_default_composite_profile.h>
#include <tesseract_motion_planners/trajopt_ifopt/profile/trajopt_ifopt_default_plan_profile.h>
#include <tesseract_motion_planners/trajopt_ifopt/profile/trajopt_ifopt_default_solver_profile.h>
#include <tesseract_motion_planners/core/utils.h>
#include <tesseract_visualization/markers/toolpath_marker.h>

Expand All @@ -58,6 +61,7 @@ using namespace tesseract_visualization;
using namespace tesseract_planning;
using tesseract_common::ManipulatorInfo;

static const std::string TRAJOPT_IFOPT_DEFAULT_NAMESPACE = "TrajOptIfoptMotionPlannerTask";
static const std::string TRAJOPT_DEFAULT_NAMESPACE = "TrajOptMotionPlannerTask";
namespace tesseract_examples
{
Expand Down Expand Up @@ -112,8 +116,10 @@ Commands addSeats(const tesseract_common::ResourceLocator::ConstPtr& locator)
}

CarSeatExample::CarSeatExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter)
: Example(std::move(env), std::move(plotter))
tesseract_visualization::Visualization::Ptr plotter,
bool ifopt,
bool debug)
: Example(std::move(env), std::move(plotter)), ifopt_(ifopt), debug_(debug)
{
}

Expand Down Expand Up @@ -215,7 +221,10 @@ Eigen::VectorXd CarSeatExample::getPositionVectorXd(const JointGroup& joint_grou

bool CarSeatExample::run()
{
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG);
if (debug_)
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG);
else
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO);

// Create Task Composer Plugin Factory
const std::string share_dir(TESSERACT_TASK_COMPOSER_DIR);
Expand Down Expand Up @@ -245,25 +254,70 @@ bool CarSeatExample::run()
// Create Executor
auto executor = factory.createTaskComposerExecutor("TaskflowExecutor");

// Create TrajOpt Profile
auto trajopt_composite_profile = std::make_shared<TrajOptDefaultCompositeProfile>();
trajopt_composite_profile->collision_constraint_config.enabled = true;
trajopt_composite_profile->collision_constraint_config.safety_margin = 0.00;
trajopt_composite_profile->collision_constraint_config.safety_margin_buffer = 0.005;
trajopt_composite_profile->collision_constraint_config.coeff = 10;
trajopt_composite_profile->collision_cost_config.safety_margin = 0.005;
trajopt_composite_profile->collision_cost_config.safety_margin_buffer = 0.01;
trajopt_composite_profile->collision_cost_config.coeff = 50;

auto trajopt_solver_profile = std::make_shared<TrajOptDefaultSolverProfile>();
trajopt_solver_profile->opt_info.max_iter = 200;
trajopt_solver_profile->opt_info.min_approx_improve = 1e-3;
trajopt_solver_profile->opt_info.min_trust_box_size = 1e-3;

// Create profile dictionary
auto profiles = std::make_shared<ProfileDictionary>();
profiles->addProfile<TrajOptCompositeProfile>(TRAJOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_composite_profile);
profiles->addProfile<TrajOptSolverProfile>(TRAJOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_solver_profile);
if (ifopt_)
{
// Create TrajOpt_Ifopt Profile
auto trajopt_ifopt_composite_profile = std::make_shared<TrajOptIfoptDefaultCompositeProfile>();
trajopt_ifopt_composite_profile->collision_constraint_config->type =
tesseract_collision::CollisionEvaluatorType::LVS_CONTINUOUS;
trajopt_ifopt_composite_profile->collision_constraint_config->contact_manager_config =
tesseract_collision::ContactManagerConfig(0.00);
trajopt_ifopt_composite_profile->collision_constraint_config->collision_margin_buffer = 0.005;
trajopt_ifopt_composite_profile->collision_constraint_config->collision_coeff_data =
trajopt_common::CollisionCoeffData(1);
trajopt_ifopt_composite_profile->collision_cost_config->type =
tesseract_collision::CollisionEvaluatorType::LVS_CONTINUOUS;
trajopt_ifopt_composite_profile->collision_cost_config->contact_manager_config =
tesseract_collision::ContactManagerConfig(0.005);
trajopt_ifopt_composite_profile->collision_cost_config->collision_margin_buffer = 0.01;
trajopt_ifopt_composite_profile->collision_cost_config->collision_coeff_data =
trajopt_common::CollisionCoeffData(50);
trajopt_ifopt_composite_profile->smooth_velocities = false;
trajopt_ifopt_composite_profile->velocity_coeff = Eigen::VectorXd::Ones(1);
trajopt_ifopt_composite_profile->smooth_accelerations = true;
trajopt_ifopt_composite_profile->acceleration_coeff = Eigen::VectorXd::Ones(1);
trajopt_ifopt_composite_profile->smooth_jerks = true;
trajopt_ifopt_composite_profile->jerk_coeff = Eigen::VectorXd::Ones(1);
trajopt_ifopt_composite_profile->longest_valid_segment_length = 0.1;

auto trajopt_ifopt_plan_profile = std::make_shared<TrajOptIfoptDefaultPlanProfile>();
trajopt_ifopt_plan_profile->cartesian_coeff = Eigen::VectorXd::Ones(6);
trajopt_ifopt_plan_profile->joint_coeff = Eigen::VectorXd::Ones(8);

auto trajopt_ifopt_solver_profile = std::make_shared<TrajOptIfoptDefaultSolverProfile>();
trajopt_ifopt_solver_profile->opt_info.max_iterations = 200;
trajopt_ifopt_solver_profile->opt_info.min_approx_improve = 1e-3;
trajopt_ifopt_solver_profile->opt_info.min_trust_box_size = 1e-3;

profiles->addProfile<TrajOptIfoptCompositeProfile>(
TRAJOPT_IFOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_ifopt_composite_profile);
profiles->addProfile<TrajOptIfoptPlanProfile>(
TRAJOPT_IFOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_ifopt_plan_profile);
profiles->addProfile<TrajOptIfoptSolverProfile>(
TRAJOPT_IFOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_ifopt_solver_profile);
}
else
{
// Create TrajOpt Profile
auto trajopt_composite_profile = std::make_shared<TrajOptDefaultCompositeProfile>();
trajopt_composite_profile->collision_constraint_config.enabled = true;
trajopt_composite_profile->collision_constraint_config.safety_margin = 0.00;
trajopt_composite_profile->collision_constraint_config.safety_margin_buffer = 0.005;
trajopt_composite_profile->collision_constraint_config.coeff = 10;
trajopt_composite_profile->collision_cost_config.safety_margin = 0.005;
trajopt_composite_profile->collision_cost_config.safety_margin_buffer = 0.01;
trajopt_composite_profile->collision_cost_config.coeff = 50;

auto trajopt_solver_profile = std::make_shared<TrajOptDefaultSolverProfile>();
trajopt_solver_profile->opt_info.max_iter = 200;
trajopt_solver_profile->opt_info.min_approx_improve = 1e-3;
trajopt_solver_profile->opt_info.min_trust_box_size = 1e-3;

profiles->addProfile<TrajOptCompositeProfile>(TRAJOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_composite_profile);
profiles->addProfile<TrajOptSolverProfile>(TRAJOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_solver_profile);
}

// Solve Trajectory
CONSOLE_BRIDGE_logInform("Car Seat Demo Started");
Expand Down Expand Up @@ -297,7 +351,8 @@ bool CarSeatExample::run()
CONSOLE_BRIDGE_logInform("Freespace plan to pick seat 1 example");

// Create task
TaskComposerNode::UPtr task = factory.createTaskComposerNode("TrajOptPipeline");
const std::string task_name = (ifopt_) ? "TrajOptIfoptPipeline" : "TrajOptPipeline";
TaskComposerNode::UPtr task = factory.createTaskComposerNode(task_name);
const std::string output_key = task->getOutputKeys().front();

// Create Task Composer Problem
Expand Down Expand Up @@ -381,7 +436,8 @@ bool CarSeatExample::run()
CONSOLE_BRIDGE_logInform("Freespace plan to pick seat 1 example");

// Create task
TaskComposerNode::UPtr task = factory.createTaskComposerNode("TrajOptPipeline");
const std::string task_name = (ifopt_) ? "TrajOptIfoptPipeline" : "TrajOptPipeline";
TaskComposerNode::UPtr task = factory.createTaskComposerNode(task_name);
const std::string output_key = task->getOutputKeys().front();

// Create Task Composer Problem
Expand Down
2 changes: 1 addition & 1 deletion tesseract_examples/src/car_seat_example_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int /*argc*/, char** /*argv*/)
if (!env->init(urdf_path, srdf_path, locator))
exit(1);

CarSeatExample example(env, nullptr);
CarSeatExample example(env, nullptr, false);
if (!example.run())
exit(1);
}
39 changes: 35 additions & 4 deletions tesseract_examples/src/freespace_hybrid_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
#include <tesseract_command_language/utils.h>

#include <tesseract_motion_planners/ompl/profile/ompl_default_plan_profile.h>
#include <tesseract_motion_planners/trajopt_ifopt/profile/trajopt_ifopt_default_composite_profile.h>
#include <tesseract_motion_planners/core/utils.h>
#include <tesseract_task_composer/planning/planning_task_composer_problem.h>
#include <tesseract_task_composer/core/task_composer_context.h>
Expand All @@ -56,14 +57,21 @@ using namespace tesseract_planning;
using tesseract_common::ManipulatorInfo;

static const std::string OMPL_DEFAULT_NAMESPACE = "OMPLMotionPlannerTask";
static const std::string TRAJOPT_IFOPT_DEFAULT_NAMESPACE = "TrajOptIfoptMotionPlannerTask";

namespace tesseract_examples
{
FreespaceHybridExample::FreespaceHybridExample(tesseract_environment::Environment::Ptr env,
tesseract_visualization::Visualization::Ptr plotter,
bool ifopt,
bool debug,
double range,
double planning_time)
: Example(std::move(env), std::move(plotter)), range_(range), planning_time_(planning_time)
: Example(std::move(env), std::move(plotter))
, ifopt_(ifopt)
, debug_(debug)
, range_(range)
, planning_time_(planning_time)
{
}

Expand Down Expand Up @@ -93,6 +101,11 @@ Command::Ptr FreespaceHybridExample::addSphere()

bool FreespaceHybridExample::run()
{
if (debug_)
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG);
else
console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO);

// Add sphere to environment
Command::Ptr cmd = addSphere();
if (!env_->applyCommand(cmd))
Expand Down Expand Up @@ -163,19 +176,37 @@ bool FreespaceHybridExample::run()
// Create Executor
auto executor = factory.createTaskComposerExecutor("TaskflowExecutor");

// Create profile dictionary
auto profiles = std::make_shared<ProfileDictionary>();

// Create OMPL Profile
auto ompl_profile = std::make_shared<OMPLDefaultPlanProfile>();
auto ompl_planner_config = std::make_shared<RRTConnectConfigurator>();
ompl_planner_config->range = range_;
ompl_profile->planning_time = planning_time_;
ompl_profile->planners = { ompl_planner_config, ompl_planner_config };

// Create profile dictionary
auto profiles = std::make_shared<ProfileDictionary>();
profiles->addProfile<OMPLPlanProfile>(OMPL_DEFAULT_NAMESPACE, "FREESPACE", ompl_profile);

if (ifopt_)
{
// Create TrajOpt_Ifopt Profile
auto trajopt_ifopt_composite_profile = std::make_shared<TrajOptIfoptDefaultCompositeProfile>();
trajopt_ifopt_composite_profile->collision_constraint_config->contact_manager_config =
tesseract_collision::ContactManagerConfig(0.025);
trajopt_ifopt_composite_profile->collision_cost_config->contact_manager_config =
tesseract_collision::ContactManagerConfig(0.025);
trajopt_ifopt_composite_profile->velocity_coeff = Eigen::VectorXd::Ones(1);
trajopt_ifopt_composite_profile->acceleration_coeff = Eigen::VectorXd::Ones(1);
trajopt_ifopt_composite_profile->jerk_coeff = Eigen::VectorXd::Ones(1);

profiles->addProfile<TrajOptIfoptCompositeProfile>(
TRAJOPT_IFOPT_DEFAULT_NAMESPACE, "FREESPACE", trajopt_ifopt_composite_profile);
}

// Create task
TaskComposerNode::UPtr task = factory.createTaskComposerNode("FreespacePipeline");
const std::string task_name = (ifopt_) ? "FreespaceIfoptPipeline" : "FreespacePipeline";
TaskComposerNode::UPtr task = factory.createTaskComposerNode(task_name);
const std::string output_key = task->getOutputKeys().front();

// Create Task Composer Problem
Expand Down
Loading
Loading