Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <geometry_msgs/Twist.h>
00003
00004 #include <predicate_manager/predicate_manager.h>
00005 #include <predicate_manager/dependencies.h>
00006 #include <predicate_manager/prop_logic_predicate.h>
00007 #include <predicate_manager/prop_logic_event.h>
00008 #include <predicate_manager/prop_and.h>
00009 #include <predicate_manager/prop_pv.h>
00010 #include <predicate_manager/prop_not.h>
00011
00012 #include <topological_tools/topological_predicate.h>
00013
00014 using namespace std;
00015 using namespace ros;
00016 using namespace predicate_manager;
00017 using namespace topological_tools;
00018
00019
00020 class PatrolHalfwayThroughPred : public Predicate
00021 {
00022 public:
00023 PatrolHalfwayThroughPred() :
00024 Predicate ( "PatrolHalfwayThrough",Dependencies()
00025 .add ( "IsInElevatorHallway" )
00026 .add ( "IsInSoccerField" ) )
00027 {}
00028
00029 void update()
00030 {
00031 if ( getValue() )
00032 {
00033 if ( getDependencyValue ( "IsInSoccerField" ) )
00034 setValue ( false );
00035 }
00036 else
00037 {
00038 if ( getDependencyValue ( "IsInElevatorHallway" ) )
00039 setValue ( true );
00040 }
00041 }
00042 };
00043
00048 class IsMovingPredicate : public Predicate
00049 {
00050 public:
00051 IsMovingPredicate() :
00052 Predicate ( "IsMoving" ),
00053 vel_subs_ ( nh_.subscribe ( "cmd_vel", 10, &IsMovingPredicate::velocityCallback, this ) ),
00054 is_moving_forward_ ( false )
00055 {}
00056
00057 void velocityCallback ( const geometry_msgs::TwistConstPtr& msg )
00058 {
00059 bool val = msg->linear.x > 0.1;
00060 if ( val != is_moving_forward_ )
00061 {
00062 is_moving_forward_ = val;
00063 update();
00064 }
00065 }
00066
00067 void update()
00068 {
00069 setValue ( is_moving_forward_ );
00070 }
00071
00072 private:
00073 NodeHandle nh_;
00074 Subscriber vel_subs_;
00075 bool is_moving_forward_;
00076 };
00077
00078
00079 int main ( int argc, char** argv )
00080 {
00081 init ( argc, argv, "predicates" );
00082
00083 string label_target = "pose_label";
00084
00085 PredicateManager pm;
00086
00088 TopologicalPredicate isInSoccerField ( label_target, "IsInSoccerField" );
00089 TopologicalPredicate isInLRM ( label_target, "IsInLRM" );
00090 TopologicalPredicate isInCoffeeRoom ( label_target, "IsInCoffeeRoom" );
00091 TopologicalPredicate isInSouthCorridor ( label_target, "IsInSouthCorridor" );
00092 TopologicalPredicate isInWestCorridor ( label_target, "IsInWestCorridor" );
00093 TopologicalPredicate isInElevatorHallway ( label_target, "IsInElevatorHallway" );
00094 PatrolHalfwayThroughPred patrolHalfwayThrough;
00095
00097 IsMovingPredicate isMoving;
00099 PropLogicPredicate plp ( "IsMovingInSouthCorridor", And ( PV ( "IsInSouthCorridor" ),PV ( "IsMoving" ) ) );
00100
00103 PropLogicEvent ple ( "PatrolCompleted",Not ( "PatrolHalfwayThrough" ) );
00104
00106 pm.addPredicate ( isInSoccerField );
00107 pm.addPredicate ( isInLRM );
00108 pm.addPredicate ( isInCoffeeRoom );
00109 pm.addPredicate ( isInSouthCorridor );
00110 pm.addPredicate ( isInWestCorridor );
00111 pm.addPredicate ( isInElevatorHallway );
00112 pm.addPredicate ( patrolHalfwayThrough );
00113
00114 pm.addPredicate ( isMoving );
00115 pm.addPredicate ( plp );
00116 pm.addEvent ( ple );
00117
00119 pm.spin();
00120
00121 return 0;
00122 }