00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00044 #include "planning_environment/monitors/planning_monitor.h"
00045 #include <std_msgs/Byte.h>
00046
00047 #include <iostream>
00048 #include <sstream>
00049 #include <string>
00050 #include <map>
00051
00052 class ViewStateValidity
00053 {
00054 public:
00055
00056 ViewStateValidity(void) : last_(-1)
00057 {
00058 collisionModels_ = new planning_environment::CollisionModels("robot_description");
00059 if (collisionModels_->loadedModels())
00060 {
00061 stateValidityPublisher_ = nh_.advertise<std_msgs::Byte>("state_validity", 1);
00062 planningMonitor_ = new planning_environment::PlanningMonitor(collisionModels_, &tf_);
00063 planningMonitor_->getEnvironmentModel()->setVerbose(true);
00064 planningMonitor_->setOnAfterMapUpdateCallback(boost::bind(&ViewStateValidity::afterWorldUpdate, this, _1, _2));
00065 planningMonitor_->setOnStateUpdateCallback(boost::bind(&ViewStateValidity::stateUpdate, this));
00066 }
00067 }
00068
00069 virtual ~ViewStateValidity(void)
00070 {
00071 if (planningMonitor_)
00072 delete planningMonitor_;
00073 if (collisionModels_)
00074 delete collisionModels_;
00075 }
00076
00077 protected:
00078
00079 void afterWorldUpdate(const mapping_msgs::CollisionMapConstPtr &collisionMap, bool clear)
00080 {
00081 last_ = -1;
00082 }
00083
00084 void stateUpdate(void)
00085 {
00086 motion_planning_msgs::ArmNavigationErrorCodes error_code;
00087 motion_planning_msgs::RobotState empty_state;
00088 bool valid = planningMonitor_->isStateValid(empty_state, planning_environment::PlanningMonitor::COLLISION_TEST,false,error_code);
00089 std_msgs::Byte msg;
00090 msg.data = valid ? 1 : 0;
00091 if (last_ != msg.data)
00092 {
00093 last_ = msg.data;
00094 stateValidityPublisher_.publish(msg);
00095 if (valid && error_code.val == error_code.SUCCESS)
00096 ROS_INFO("State is valid");
00097 else
00098 ROS_WARN("State is in collision");
00099 }
00100 }
00101
00102 private:
00103
00104 int last_;
00105 ros::NodeHandle nh_;
00106 ros::Publisher stateValidityPublisher_;
00107 tf::TransformListener tf_;
00108 planning_environment::CollisionModels *collisionModels_;
00109 planning_environment::PlanningMonitor *planningMonitor_;
00110 };
00111
00112 int main(int argc, char **argv)
00113 {
00114 ros::init(argc, argv, "view_state_validity");
00115
00116 ViewStateValidity validator;
00117 ros::spin();
00118
00119 return 0;
00120 }