-
Notifications
You must be signed in to change notification settings - Fork 27
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
Implement collision checker node #301
Open
DaikiMaekawa
wants to merge
9
commits into
start-jsk:hydro-devel
Choose a base branch
from
DaikiMaekawa:imp-collision-checker
base: hydro-devel
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d26ef5a
Provisional Implemented collision checker
DaikiMaekawa 9e616d5
Add function of cancel moving
DaikiMaekawa 62bdfa2
Fix error of target link libraries
DaikiMaekawa ca83850
Testing collision checker
DaikiMaekawa 97c228e
Calling clearPoseTargets method
DaikiMaekawa 1d9c24d
Delete unnecessary comments
DaikiMaekawa 4981c86
fix copyrights mismatch
DaikiMaekawa c359e1e
Re-implemented as class
DaikiMaekawa a98f015
Add build target
DaikiMaekawa 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 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 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,198 @@ | ||
/* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2014, Daiki Maekawa and TORK (Tokyo Opensource Robotics Kyokai Association) | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of JSK Lab, University of Tokyo. nor the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copyrights mismatch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, It's copy/pasted from the other program. That is set right here. |
||
* names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <vector> | ||
|
||
#include <ros/ros.h> | ||
|
||
#include <moveit/robot_model_loader/robot_model_loader.h> | ||
#include <moveit/planning_scene/planning_scene.h> | ||
#include <control_msgs/FollowJointTrajectoryAction.h> | ||
#include <moveit/move_group_interface/move_group.h> | ||
#include <moveit/controller_manager/controller_manager.h> | ||
|
||
#include <moveit/kinematic_constraints/utils.h> | ||
#include <eigen_conversions/eigen_msg.h> | ||
|
||
#include <moveit/planning_scene_monitor/current_state_monitor.h> | ||
#include <moveit/planning_scene_monitor/planning_scene_monitor.h> | ||
|
||
/* | ||
|
||
template<typename T> | ||
class ActionBasedControllerHandle : public moveit_controller_manager::MoveItControllerHandle | ||
{ | ||
public: | ||
ActionBasedControllerHandle(const std::string &name, const std::string &ns) : | ||
moveit_controller_manager::MoveItControllerHandle(name), | ||
namespace_(ns), | ||
done_(true) | ||
{ | ||
controller_action_client_.reset(new actionlib::SimpleActionClient<T>(name_ +"/" + namespace_, true)); | ||
unsigned int attempts = 0; | ||
while (ros::ok() && !controller_action_client_->waitForServer(ros::Duration(5.0)) && ++attempts < 3) | ||
ROS_INFO_STREAM("Waiting for " << name_ + "/" + namespace_ << " to come up"); | ||
if (!controller_action_client_->isServerConnected()) | ||
{ | ||
ROS_ERROR_STREAM("Action client not connected: " << name_ + "/" + namespace_); | ||
controller_action_client_.reset(); | ||
} | ||
last_exec_ = moveit_controller_manager::ExecutionStatus::SUCCEEDED; | ||
} | ||
bool isConnected() const | ||
{ | ||
return controller_action_client_; | ||
} | ||
virtual bool cancelExecution() | ||
{ | ||
if (!controller_action_client_) | ||
return false; | ||
if (!done_) | ||
{ | ||
ROS_INFO_STREAM("Cancelling execution for " << name_); | ||
controller_action_client_->cancelGoal(); | ||
last_exec_ = moveit_controller_manager::ExecutionStatus::PREEMPTED; | ||
done_ = true; | ||
} | ||
return true; | ||
} | ||
virtual bool waitForExecution(const ros::Duration &timeout = ros::Duration(0)) | ||
{ | ||
if (controller_action_client_ && !done_) | ||
return controller_action_client_->waitForResult(timeout); | ||
return true; | ||
} | ||
virtual moveit_controller_manager::ExecutionStatus getLastExecutionStatus() | ||
{ | ||
return last_exec_; | ||
} | ||
protected: | ||
void finishControllerExecution(const actionlib::SimpleClientGoalState& state) | ||
{ | ||
ROS_DEBUG_STREAM("Controller " << name_ << " is done with state " << state.toString() << ": " << state.getText()); | ||
if (state == actionlib::SimpleClientGoalState::SUCCEEDED) | ||
last_exec_ = moveit_controller_manager::ExecutionStatus::SUCCEEDED; | ||
else | ||
if (state == actionlib::SimpleClientGoalState::ABORTED) | ||
last_exec_ = moveit_controller_manager::ExecutionStatus::ABORTED; | ||
else | ||
if (state == actionlib::SimpleClientGoalState::PREEMPTED) | ||
last_exec_ = moveit_controller_manager::ExecutionStatus::PREEMPTED; | ||
else | ||
last_exec_ = moveit_controller_manager::ExecutionStatus::FAILED; | ||
done_ = true; | ||
} | ||
|
||
moveit_controller_manager::ExecutionStatus last_exec_; | ||
std::string namespace_; | ||
bool done_; | ||
boost::shared_ptr<actionlib::SimpleActionClient<T> > controller_action_client_; | ||
}; | ||
|
||
*/ | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
ros::init(argc, argv, "collision_checker"); | ||
ros::AsyncSpinner spinner(1); | ||
spinner.start(); | ||
|
||
//ActionBasedControllerHandle<control_msgs::FollowJointTrajectoryAction> action_controller = ActionBasedControllerHandle(, "larm_controller") | ||
|
||
moveit::planning_interface::MoveGroup group_r("right_arm"); | ||
moveit::planning_interface::MoveGroup group_l("left_arm"); | ||
|
||
robot_model_loader::RobotModelLoader robot_model_loader("robot_description"); | ||
robot_model::RobotModelPtr kinematic_model = robot_model_loader.getModel(); | ||
planning_scene::PlanningScene planning_scene(kinematic_model); | ||
|
||
planning_scene_monitor::PlanningSceneMonitor psm("robot_description"); | ||
psm.startStateMonitor("joint_states"); | ||
collision_detection::AllowedCollisionMatrix acm = planning_scene.getAllowedCollisionMatrix(); | ||
|
||
collision_detection::CollisionRequest collision_request; | ||
collision_detection::CollisionResult collision_result; | ||
collision_request.contacts = true; | ||
collision_request.max_contacts = 1000; | ||
|
||
while(!(psm.getStateMonitor()->waitForCurrentState(1.0))); | ||
robot_state::RobotStatePtr current_state = psm.getStateMonitor()->getCurrentState(); | ||
robot_state::RobotState planning_state = planning_scene.getCurrentStateNonConst(); | ||
double *pos = current_state->getVariablePositions(); | ||
planning_state.setVariablePositions(pos); | ||
planning_scene.checkCollision(collision_request, collision_result, *current_state, acm); | ||
collision_detection::CollisionResult::ContactMap::const_iterator it; | ||
for(it = collision_result.contacts.begin(); it != collision_result.contacts.end(); ++it){ | ||
acm.setEntry(it->first.first, it->first.second, true); | ||
ROS_INFO("Contact between: %s and %s now allowed.", it->first.first.c_str(), it->first.second.c_str()); | ||
} | ||
|
||
collision_detection::CollisionResult old_collision_result; | ||
geometry_msgs::PoseStamped pose_r = group_r.getCurrentPose(); | ||
geometry_msgs::PoseStamped pose_l = group_l.getCurrentPose(); | ||
|
||
while(ros::ok()){ | ||
if(psm.getStateMonitor()->waitForCurrentState(1.0)){ | ||
collision_result.clear(); | ||
current_state = psm.getStateMonitor()->getCurrentState(); | ||
planning_state = planning_scene.getCurrentStateNonConst(); | ||
pos = current_state->getVariablePositions(); | ||
planning_state.setVariablePositions(pos); | ||
planning_scene.checkCollision(collision_request, collision_result, *current_state, acm); | ||
ROS_INFO_STREAM("Test : Current state is " | ||
<< (collision_result.collision ? "in" : "not in") | ||
<< " self collision"); | ||
|
||
for(it = collision_result.contacts.begin(); it != collision_result.contacts.end(); ++it){ | ||
ROS_INFO("Contact between: %s and %s", | ||
it->first.first.c_str(), | ||
it->first.second.c_str()); | ||
} | ||
|
||
if(!old_collision_result.collision && collision_result.collision){ | ||
group_r.clearPoseTargets(); | ||
group_l.clearPoseTargets(); | ||
|
||
//TODO: Stop Motion | ||
|
||
//group_r.setPoseTarget(group_r.getCurrentPose()); | ||
//group_l.setPoseTarget(group_l.getCurrentPose()); | ||
} | ||
|
||
old_collision_result = collision_result; | ||
} | ||
} | ||
|
||
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.
From next time please try not to mix formatting change and the feature addition.
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.
I got it.