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

Planning scene transcription #23

Merged
merged 30 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
649910f
local changes stash apply
kamiradi Jul 11, 2024
071032e
[WIP] Demo attempts the drake pipeline
kamiradi Jul 11, 2024
ffa7384
[BUG] cmake configure error in demo/CMakeLists.txt
kamiradi Jul 12, 2024
4ee8524
[WIP] Error message for unset robot description
kamiradi Jul 12, 2024
4dcb216
[BUG] robot description subcriber behaviour test
kamiradi Jul 12, 2024
2a7b83b
[WIP] Loads urdf from drake model
kamiradi Jul 14, 2024
72367d7
[WIP] Transcribes basic optimization problem
kamiradi Jul 15, 2024
382bea4
[FT] Basic motion plan success
kamiradi Jul 15, 2024
cb0e8ca
cleans up a few comments
kamiradi Jul 15, 2024
8da844f
Cleanup configs
sjahr Jul 16, 2024
ad817c2
Get robot description working
sjahr Jul 16, 2024
48d7b73
Merge pull request #2 from sjahr/dev
kamiradi Jul 16, 2024
dfbebcb
[FIX] resolves review comments
kamiradi Jul 16, 2024
5f81ac7
[FIX] review comments and joint velocities
kamiradi Jul 17, 2024
03770c0
Merge branch 'moveit:main' into dev
kamiradi Jul 17, 2024
bfc5bc6
[WIP] visualisation attempt
kamiradi Jul 23, 2024
8a54709
Hacked MeshCat together
sea-bass Jul 24, 2024
7821927
Merge pull request #3 from sea-bass/hack-meshcat
kamiradi Jul 26, 2024
616883f
[WIP] adds planning scene block next to robot
kamiradi Jul 26, 2024
f3682b0
[WIP] collision scene transcription
kamiradi Jul 26, 2024
1699412
[WIP] debugging plannign scene
kamiradi Jul 27, 2024
795acbf
[WIP] segmentation fault
kamiradi Jul 29, 2024
f9fbc24
[WIP] smart pointers and pointer scoping
kamiradi Jul 30, 2024
41a5898
[WIP] sanity check pass
kamiradi Jul 30, 2024
829ca42
Motion Planning with collision checking
kamiradi Jul 31, 2024
8760c40
review comment refactor
kamiradi Aug 1, 2024
9f5bd78
review comments refactored v2
kamiradi Aug 2, 2024
d849a6a
Merge branch 'main' into dev
kamiradi Aug 2, 2024
590d951
code format check
kamiradi Aug 2, 2024
fad34b6
pre-commit related changes
kamiradi Aug 3, 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
16 changes: 10 additions & 6 deletions demo/src/pipeline_testbench_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <moveit/moveit_cpp/planning_component.h>

#include <geometry_msgs/msg/point_stamped.h>
#include <geometry_msgs/msg/pose.h>

#include <moveit_visual_tools/moveit_visual_tools.h>

Expand Down Expand Up @@ -103,6 +104,13 @@ class Demo
text_pose.translation().z() = 1.75;
visual_tools_.publishText(text_pose, "Pipeline Testbench", rvt::WHITE, rvt::XLARGE);
visual_tools_.trigger();

geometry_msgs::msg::Pose block_pose;
block_pose.position.z = 0.5;
block_pose.position.y = -0.3;
block_pose.position.x = 0.3;
visual_tools_.publishCollisionBlock(block_pose, "test_block", 0.15);
sjahr marked this conversation as resolved.
Show resolved Hide resolved

}

bool loadPlanningSceneAndQuery()
Expand Down Expand Up @@ -322,12 +330,8 @@ int main(int argc, char** argv)
RCLCPP_INFO(LOGGER, "Starting Pipeline Testbench example ...");
for (const auto& motion_plan_req : demo.getMotionPlanRequests())
{
demo.planAndVisualize(
{
{ "ompl", "RRTConnectkConfigDefault" },
{ "stomp", "stomp" },
{ "drake", ""} },
motion_plan_req);
demo.planAndVisualize({ { "ompl", "RRTConnectkConfigDefault" }, { "stomp", "stomp" }, { "drake", "" } },
motion_plan_req);
}

demo.getVisualTools().prompt("Press 'next' in the RvizVisualToolsGui window to finish the demo");
Expand Down
103 changes: 65 additions & 38 deletions include/ktopt_interface/ktopt_planning_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,90 @@
#include "drake/multibody/plant/multibody_plant.h"
#include "drake/planning/trajectory_optimization/kinematic_trajectory_optimization.h"
#include "drake/solvers/solve.h"
#include "drake/geometry/meshcat.h"
#include "drake/geometry/meshcat_visualizer.h"
#include "drake/geometry/drake_visualizer.h"
#include "drake/geometry/meshcat_params.h"
#include "drake/geometry/geometry_frame.h"
#include "drake/geometry/geometry_instance.h"
#include "drake/geometry/geometry_roles.h"
#include "drake/geometry/proximity_properties.h"
#include "drake/visualization/visualization_config.h"
#include "drake/visualization/visualization_config_functions.h"
#include <drake/multibody/inverse_kinematics/minimum_distance_lower_bound_constraint.h>

namespace ktopt_interface
{
// declare all namespaces to be used
using drake::multibody::MultibodyPlant;
using drake::multibody::AddMultibodyPlantSceneGraph;
using drake::geometry::Meshcat;
using drake::geometry::MeshcatParams;
using drake::geometry::MeshcatVisualizer;
using drake::geometry::MeshcatVisualizerParams;
using drake::geometry::SceneGraph;
using drake::systems::DiagramBuilder;
using drake::geometry::FrameId;
using drake::geometry::SourceId;
using drake::geometry::GeometryId;
using drake::geometry::GeometryInstance;
using drake::geometry::GeometryFrame;
using drake::geometry::AddRigidHydroelasticProperties;
using drake::geometry::IllustrationProperties;
using drake::geometry::ProximityProperties;
using drake::geometry::PerceptionProperties;
using drake::geometry::Role;
using drake::geometry::Box;
using drake::multibody::AddMultibodyPlantSceneGraph;
using drake::multibody::MultibodyPlant;
using drake::multibody::PackageMap;
using drake::multibody::Parser;
using drake::multibody::MultibodyPlant;
using drake::multibody::MinimumDistanceLowerBoundConstraint;
using drake::planning::trajectory_optimization::KinematicTrajectoryOptimization;
using drake::solvers::Solve;
using drake::systems::Diagram;
using drake::systems::Context;
using drake::multibody::PackageMap;
using Eigen::VectorXd;
using drake::systems::Diagram;
using drake::systems::DiagramBuilder;
using drake::visualization::ApplyVisualizationConfig;
using drake::visualization::VisualizationConfig;
using drake::math::RigidTransformd;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::Vector3d;
using Joints = std::vector<const moveit::core::JointModel*>;

class KTOptPlanningContext : public planning_interface::PlanningContext
{
public:
KTOptPlanningContext(
const std::string& name,
const std::string& group_name,
const ktopt_interface::Params& params);

void solve(
planning_interface::MotionPlanResponse& res) override;
void solve(
planning_interface::MotionPlanDetailedResponse& res) override;
KTOptPlanningContext(const std::string& name, const std::string& group_name, const ktopt_interface::Params& params);

bool terminate() override;
void clear() override;
void solve(planning_interface::MotionPlanResponse& res) override;
void solve(planning_interface::MotionPlanDetailedResponse& res) override;

void setRobotDescription(std::string robot_description);
VectorXd toDrakePositions(
const moveit::core::RobotState& state,
const Joints& joints);
void setJointPositions(
const VectorXd& values,
const Joints& joints,
moveit::core::RobotState& state);
void setJointVelocities(
const VectorXd& values,
const Joints& joints,
moveit::core::RobotState& state);
bool terminate() override;
void clear() override;

void setRobotDescription(std::string robot_description);
VectorXd toDrakePositions(const moveit::core::RobotState& state, const Joints& joints);
void setJointPositions(const VectorXd& values, const Joints& joints, moveit::core::RobotState& state);
void setJointVelocities(const VectorXd& values, const Joints& joints, moveit::core::RobotState& state);
void transcribePlanningScene(const planning_scene::PlanningScene& planning_scene);

private:
const ktopt_interface::Params params_;
std::string robot_description_;
const ktopt_interface::Params params_;
std::string robot_description_;

// drake related variables
// SceneGraph<double>* scene_graph_{};
// MultibodyPlant<double>* plant_{};
std::unique_ptr<Diagram<double>> diagram_;
std::unique_ptr<DiagramBuilder<double>> builder;
std::unique_ptr<Context<double>> diagram_context_;
// Context<double>* plant_context_{};
// Context<double>* visualizer_context_{};
sjahr marked this conversation as resolved.
Show resolved Hide resolved
VectorXd nominal_q_;
std::string OCTOMAP_NS = "<octomap>";
sjahr marked this conversation as resolved.
Show resolved Hide resolved

// drake related variables
SceneGraph<double>* scene_graph_{};
MultibodyPlant<double>* plant_{};
std::unique_ptr<Context<double>> diagram_context_;
Context<double>* plant_context_;
VectorXd nominal_q_;
// visualization
std::shared_ptr<Meshcat> meshcat_;
MeshcatVisualizer<double>* visualizer_;
};
} // namespace ktopt_interface
} // namespace ktopt_interface
24 changes: 12 additions & 12 deletions src/ktopt_planner_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ class KTOptPlannerManager : public planning_interface::PlannerManager
node_ = node;
param_listener_ = std::make_shared<ktopt_interface::ParamListener>(node, parameter_namespace);


// set QoS to transient local to get messages that have already been published
// (if robot state publisher starts before planner)
// set QoS to transient local to get messages that have already been published
// (if robot state publisher starts before planner)
robot_description_subscriber_ = node_->create_subscription<std_msgs::msg::String>(
"robot_description", rclcpp::QoS(1).transient_local(), [this](const std_msgs::msg::String::SharedPtr msg){
if (robot_description_.empty())
{
robot_description_ = msg->data;
RCLCPP_INFO(getLogger(), "Robot description set");
}
});
"robot_description", rclcpp::QoS(1).transient_local(), [this](const std_msgs::msg::String::SharedPtr msg) {
if (robot_description_.empty())
{
robot_description_ = msg->data;
RCLCPP_INFO(getLogger(), "Robot description set");
}
});
RCLCPP_INFO(getLogger(), "KTOpt planner manager initialized!");
return true;
}

bool canServiceRequest(const planning_interface::MotionPlanRequest& req) const override
{
if(robot_description_.empty()){
if (robot_description_.empty())
{
RCLCPP_ERROR(getLogger(), "Robot description is empty, do you have a robot state publisher running?");
return false;
}
Expand Down Expand Up @@ -93,8 +93,8 @@ class KTOptPlannerManager : public planning_interface::PlannerManager
std::shared_ptr<KTOptPlanningContext> planning_context =
std::make_shared<KTOptPlanningContext>("KTOPT", req.group_name, params);
// set robot description
planning_context->setRobotDescription(robot_description_);
planning_context->setPlanningScene(planning_scene);
planning_context->setRobotDescription(robot_description_);
planning_context->setMotionPlanRequest(req);

return planning_context;
Expand Down
Loading