-
Notifications
You must be signed in to change notification settings - Fork 0
Obstacles to world_model #21
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
Open
garygra
wants to merge
1
commit into
master
Choose a base branch
from
obstacles-to-ml4kp-world
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <launch> | ||
| <group ns="test"> | ||
|
|
||
| <node pkg="task_planning" name="obstacles_to_ml4kp_world" type="obstacles_to_ml4kp_world" output="screen"> | ||
| <param name="obstacle_frames" type="yaml" value="[C0_marker_200,C0_marker_201]" /> | ||
| <param name="world_frame" value="world" /> | ||
| <param name="robot_frame" value="robot_0" /> | ||
| </node> | ||
| </group> | ||
| </launch> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #include <unordered_set> | ||
|
|
||
| #include <ml4kp_bridge/defs.h> | ||
| #include "prx_models/MushrPlanner.h" | ||
| #include "prx_models/mj_mushr.hpp" | ||
| #include "motion_planning/replanner_service.hpp" | ||
| #include "motion_planning/planner_client.hpp" | ||
| #include <utils/std_utils.cpp> | ||
| #include <utils/rosparams_utils.hpp> | ||
| #include <utils/dbg_utils.hpp> | ||
| #include <ros/ros.h> | ||
| #include <ros/package.h> | ||
| #include <prx/utilities/geometry/basic_geoms/box.hpp> | ||
| #include <tf2_msgs/TFMessage.h> | ||
| #include <tf2_eigen/tf2_eigen.h> | ||
| #include <tf2_ros/transform_broadcaster.h> | ||
| #include <tf2/LinearMath/Quaternion.h> | ||
| #include <tf2_ros/transform_listener.h> | ||
|
|
||
| tf2_ros::Buffer tf_buffer; | ||
| bool get_obstacle_pose(const std::string& world_frame, const std::string& obstacle_frame, | ||
| geometry_msgs::TransformStamped& tf) | ||
| { | ||
| try | ||
| { | ||
| tf = tf_buffer.lookupTransform(world_frame, obstacle_frame, ros::Time(0)); | ||
|
|
||
| return true; | ||
| } | ||
| catch (tf2::TransformException& ex) | ||
| { | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| ros::init(argc, argv, "obstacles_to_ml4kp_world"); | ||
| ros::NodeHandle nh("~"); | ||
| prx::simulation_step = 0.01; | ||
|
|
||
| const std::string root{ ros::this_node::getNamespace() }; | ||
| prx::init_random(112392); | ||
|
|
||
| tf2_ros::TransformListener tf_listener(tf_buffer); | ||
|
|
||
| std::vector<std::string> obstacle_frames; | ||
| std::string world_frame, robot_frame; | ||
| ROS_PARAM_SETUP(nh, obstacle_frames); | ||
| ROS_PARAM_SETUP(nh, world_frame); | ||
| ROS_PARAM_SETUP(nh, robot_frame); | ||
|
|
||
| const std::string plant_name{ "mushr" }; | ||
| const std::string plant_path{ "mushr" }; | ||
| auto plant = prx::system_factory_t::create_system(plant_name, plant_path); | ||
| prx_assert(plant != nullptr, "Failed to create plant"); | ||
|
|
||
| prx::world_model_t planning_model({ plant }, {}); | ||
| const std::string context_name{ "planner_context" }; | ||
| planning_model.create_context(context_name, { plant_name }, {}); | ||
| auto planning_context = planning_model.get_context(context_name); | ||
| auto ss = planning_context.first->get_state_space(); | ||
| auto cs = planning_context.first->get_control_space(); | ||
| std::vector<double> min_control_limits = { -1., -0.5 }; | ||
| std::vector<double> max_control_limits = { 1., 0.5 }; | ||
| cs->set_bounds(min_control_limits, max_control_limits); | ||
|
|
||
| ros::Rate rate(30); | ||
| geometry_msgs::TransformStamped tf; | ||
|
|
||
| bool pose_received{ false }; | ||
| // Eigen::Vector3d box_dims{ 0.32, 1.0, 0.28 }; | ||
| Eigen::Vector3d box_dims{ 0.41, 0.32, 0.28 }; | ||
|
|
||
| std::unordered_set<std::string> obstacle_set{}; | ||
|
|
||
| std::ofstream ofs_obstacles; // ("/tmp/ml4kp_world_obstacles.txt", std::ofstream::trunc); | ||
| std::size_t iters{ 0 }; | ||
| prx::trajectory_t traj{ ss }; | ||
|
|
||
| while (ros::ok()) | ||
| { | ||
| ofs_obstacles = std::ofstream("/tmp/ml4kp_world_obstacles.txt", std::ofstream::trunc); | ||
| for (auto obstacle : obstacle_frames) | ||
| { | ||
| if (get_obstacle_pose(world_frame, obstacle, tf)) | ||
| { | ||
| prx::transform_t pose{ tf2::transformToEigen(tf) }; | ||
| // pose.translation()[2] *= 2; // Make Z double, as ml4kp considers the center and this returns the top | ||
| pose.translation()[2] = box_dims[2] / 2; // Make Z half the height of box to "Zero" it | ||
|
|
||
| if (obstacle_set.count(obstacle) == 0) | ||
| { | ||
| planning_model.emplace_obstacle<prx::box_t>(context_name, obstacle, box_dims[0], box_dims[1], box_dims[2], | ||
| pose); | ||
| obstacle_set.insert(obstacle); | ||
| } | ||
| else | ||
| { | ||
| const std::shared_ptr<prx::movable_object_t> box_movable{ planning_model.obstacle(obstacle) }; | ||
| std::shared_ptr<prx::transform_t> box_tf{ box_movable->transform_ptr("body") }; | ||
| *box_tf = pose; // Move it out so there is no collision | ||
| // DEBUG_VARS(obstacle, pose.translation().transpose()); | ||
| } | ||
| } | ||
| // ofs_obstacles << pose.translation()[0]; | ||
| } | ||
| if (get_obstacle_pose(world_frame, robot_frame, tf)) | ||
| { | ||
| prx_models::copy(*(ss), tf); | ||
| traj.copy_onto_back(ss); | ||
| // DEBUG_VARS(robot_frame, *ss); | ||
| } | ||
| rate.sleep(); | ||
| } | ||
|
|
||
| auto obstacles = planning_model.get_obstacles(); | ||
| prx::three_js_group_t* vis_group = new prx::three_js_group_t({ plant }, { obstacles }); | ||
| prx::space_point_t default_state{ ss->make_point() }; | ||
| ss->copy(default_state, Eigen::Vector4d::Zero()); | ||
|
|
||
| vis_group->add_animation(traj, ss, default_state); | ||
|
|
||
| // std::string body_name = plant_name + "/" + "body"; | ||
|
|
||
| vis_group->output_html("ros_ml4kp.html"); | ||
|
|
||
| return 0; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for putting this together. For the integration with planning + control, I think it would be useful to have an example of a class that implements:
shared_ptrto theplanning_contextorworld_model_tdynamically so that the replanner is always using the latest information available to itLet me know if this is too much work for this PR.