Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <ros/ros.h>
00014 #include <actionlib/client/simple_action_client.h>
00015 #include <actionlib/client/terminal_state.h>
00016 #include <behavior_tree_core/BTAction.h>
00017
00018
00019 int main(int argc, char **argv)
00020 {
00021 ros::init(argc, argv, "test_condition");
00022
00023
00024
00025 actionlib::SimpleActionClient<behavior_tree_core::BTAction> ac("condition", true);
00026 behavior_tree_core::BTResult node_result;
00027 ROS_INFO("Waiting for action server to start.");
00028
00029 ac.waitForServer();
00030
00031 behavior_tree_core::BTGoal goal;
00032
00033 int command = 0;
00034 bool isRunning = false;
00035
00036
00037
00038 while (command != 3)
00039 {
00040 ROS_INFO("Send a command: 1:Evaluate the condition | 3:exit the program");
00041 std::cin >> command;
00042
00043 switch (command)
00044 {
00045 case 1:
00046 if (!isRunning)
00047 {
00048 ROS_INFO("I am running the request");
00049 ac.sendGoal(goal);
00050 isRunning = true;
00051 ac.waitForResult(ros::Duration(30.0));
00052 node_result = *(ac.getResult());
00053 ROS_INFO("Condition evaluated, status: %d", node_result.status);
00054 }
00055 else
00056 {
00057 ROS_INFO("I am re-running the request");
00058 ac.cancelGoal();
00059 ac.sendGoal(goal);
00060 ac.waitForResult(ros::Duration(30.0));
00061 node_result = *(ac.getResult());
00062
00063 ROS_INFO("Condition evaluated, status: %d", node_result.status);
00064 }
00065 break;
00066 case 2:
00067 break;
00068 default:
00069 break;
00070 }
00071 }
00072 return 0;
00073 }