|
From: <tpr...@us...> - 2009-06-23 01:22:34
|
Revision: 17474
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=17474&view=rev
Author: tpratkanis
Date: 2009-06-23 00:33:43 +0000 (Tue, 23 Jun 2009)
Log Message:
-----------
Add new handlePreempt method to robot actions. This allows you to create an event handler that triggers when preemption occurs.
Modified Paths:
--------------
pkg/trunk/common/robot_actions/include/robot_actions/action.h
pkg/trunk/highlevel/test_robot_actions/test/utest.cc
Modified: pkg/trunk/common/robot_actions/include/robot_actions/action.h
===================================================================
--- pkg/trunk/common/robot_actions/include/robot_actions/action.h 2009-06-23 00:22:26 UTC (rev 17473)
+++ pkg/trunk/common/robot_actions/include/robot_actions/action.h 2009-06-23 00:33:43 UTC (rev 17474)
@@ -78,6 +78,11 @@
* @param feedback The feedback message. At the end of the function, this will be published.
*/
virtual ResultStatus execute(const Goal& goal, Feedback& feedback) = 0;
+
+ /**
+ * @brief Blocking, user specified code for preemption. By defualt, it does nothing. Please keep in mind that this function will be called on termination.
+ */
+ virtual void handlePreempt() {}
/**
* @brief Called by the user to check if the action has a new goal.
@@ -117,6 +122,7 @@
*/
void preempt() {
_preempt_request = true;
+ handlePreempt();
ROS_DEBUG("[%s]Preempt requested\n", getName().c_str());
while(isActive()) {
ros::Duration d; d.fromSec(0.001);
@@ -190,7 +196,7 @@
}
virtual ~Action(){
- ROS_ASSERT_MSG(_terminated, "Actions must be terminated before they are deleted, or there will be a segfault. In this case, action '%s' terminated was terminated before it was deleted.", _name.c_str());
+ ROS_ASSERT_MSG(_terminated, "Actions must be terminated before they are deleted, or there will be a segfault. In this case, action '%s' was not terminated before it was deleted.", _name.c_str());
if(_action_thread != NULL){
_action_thread->join();
delete _action_thread;
Modified: pkg/trunk/highlevel/test_robot_actions/test/utest.cc
===================================================================
--- pkg/trunk/highlevel/test_robot_actions/test/utest.cc 2009-06-23 00:22:26 UTC (rev 17473)
+++ pkg/trunk/highlevel/test_robot_actions/test/utest.cc 2009-06-23 00:33:43 UTC (rev 17474)
@@ -17,9 +17,10 @@
class MyAction: public robot_actions::Action<Float32, Float32> {
public:
- MyAction(std::string name): robot_actions::Action<Float32, Float32>(name), _use_deactivate_wait(false) {}
+ MyAction(std::string name): robot_actions::Action<Float32, Float32>(name), _use_deactivate_wait(false), _handled_preempt(false) {}
bool _use_deactivate_wait;
+ bool _handled_preempt;
const static int FAIL_IF = 30;
@@ -63,6 +64,11 @@
return waitForDeactivation(feedback);
}
+
+ virtual void handlePreempt() {
+ _handled_preempt = true;
+ }
+
};
/**
@@ -108,6 +114,7 @@
// Activate
a.activate(g);
ASSERT_EQ(c._status.value, foo.ACTIVE);
+ ASSERT_EQ(a._handled_preempt, false);
// Sleep for longer than the goal. Should be finished
ros::Duration d;
@@ -123,6 +130,7 @@
a.preempt();
d.sleep();
ASSERT_EQ(c._status.value == foo.PREEMPTED, true);
+ ASSERT_EQ(a._handled_preempt, true);
ASSERT_EQ(c._value < g.data, true);
// Message adapter connects an action to a ros message context
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|