Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iri_action_server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
ros
iri_core
iri_action_server
Commits
a0829841
Commit
a0829841
authored
13 years ago
by
Joan Perez Ibarz
Browse files
Options
Downloads
Patches
Plain Diff
- first working version for iri action server: including stop callback, preempt handling
parent
49eecde3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/iri_action_server/iri_action_server.h
+48
-17
48 additions, 17 deletions
include/iri_action_server/iri_action_server.h
with
48 additions
and
17 deletions
include/iri_action_server/iri_action_server.h
+
48
−
17
View file @
a0829841
...
...
@@ -47,10 +47,11 @@ class IriActionServer
private:
boost
::
function
<
void
(
const
GoalConstPtr
&
)
>
start_action_callback_
;
boost
::
function
<
void
()
>
stop_action_callback_
;
boost
::
function
<
bool
()
>
is_finished_callback_
;
boost
::
function
<
bool
()
>
has_succeed_callback_
;
boost
::
function
<
void
(
ResultPtr
&
)
>
get_result_callback_
;
boost
::
function
<
void
(
FeedbackPtr
&
)
>
publish
_feedback_callback_
;
boost
::
function
<
void
(
FeedbackPtr
&
)
>
get
_feedback_callback_
;
void
executeCallback
(
const
GoalConstPtr
&
goal
);
...
...
@@ -87,13 +88,15 @@ class IriActionServer
*/
~
IriActionServer
(
void
);
void
start
(
void
);
void
setLoopRate
(
ros
::
Rate
r
);
void
registerStartCallback
(
boost
::
function
<
void
(
const
GoalConstPtr
&
)
>
cb
);
void
registerStopCallback
(
boost
::
function
<
void
()
>
cb
);
void
registerIsFinishedCallback
(
boost
::
function
<
bool
()
>
cb
);
void
registerHasSucceedCallback
(
boost
::
function
<
bool
()
>
cb
);
void
registerGetResultCallback
(
boost
::
function
<
void
(
ResultPtr
&
)
>
cb
);
void
register
Publish
FeedbackCallback
(
boost
::
function
<
void
(
FeedbackPtr
&
)
>
cb
);
void
register
Get
FeedbackCallback
(
boost
::
function
<
void
(
FeedbackPtr
&
)
>
cb
);
};
...
...
@@ -103,13 +106,13 @@ IriActionServer<ActionSpec>::IriActionServer(ros::NodeHandle & nh, const std::st
as_
(
nh
,
action_name_
,
boost
::
bind
(
&
IriActionServer
<
ActionSpec
>::
executeCallback
,
this
,
_1
),
false
),
loop_rate_
(
10
)
{
// launch action server
as_
.
start
();
ROS_DEBUG
(
"IriActionServer::Constructor"
);
}
template
<
class
ActionSpec
>
IriActionServer
<
ActionSpec
>::~
IriActionServer
(
void
)
{
ROS_DEBUG
(
"IriActionServer::Destructor"
);
}
template
<
class
ActionSpec
>
...
...
@@ -119,19 +122,30 @@ void IriActionServer<ActionSpec>::setLoopRate(ros::Rate r)
}
template
<
class
ActionSpec
>
void
IriActionServer
<
ActionSpec
>::
executeCallback
(
const
GoalConstPtr
&
goal
)
void
IriActionServer
<
ActionSpec
>::
start
(
void
)
{
ROS_DEBUG
(
"IriActionServer::Start"
);
// check if all callbacks have been registered
if
(
!
start_action_callback_
||
!
is_finished_callback_
||
!
has_succeed_callback_
||
!
get_result_callback_
||
!
publish_feedback_callback_
)
if
(
start_action_callback_
&&
stop_action_callback_
&&
is_finished_callback_
&&
has_succeed_callback_
&&
get_result_callback_
&&
get_feedback_callback_
)
{
ROS_ERROR
(
"Some Callbacks have not been registered yet!"
);
return
;
// launch action server
as_
.
start
()
;
}
else
ROS_FATAL
(
"Some Callbacks have not been registered yet!"
);
}
template
<
class
ActionSpec
>
void
IriActionServer
<
ActionSpec
>::
executeCallback
(
const
GoalConstPtr
&
goal
)
{
ROS_DEBUG
(
"IriActionServer::executeCallback::start"
);
// init action
start_action_callback_
(
goal
);
...
...
@@ -141,30 +155,40 @@ void IriActionServer<ActionSpec>::executeCallback(const GoalConstPtr& goal)
// while action is active
while
(
is_active
)
{
ROS_DEBUG
(
"IriActionServer::executeCallback::Active!"
);
// check if preempt has been requested
// and if ROS connection is OK
if
(
as_
.
isPreemptRequested
()
||
!
ros
::
ok
()
)
{
ROS_DEBUG
(
"IriActionServer::executeCallback::PREEMPTED!"
);
is_active
=
false
;
// stop action
stop_action_callback_
();
as_
.
setPreempted
();
}
// check if action has finished
else
if
(
is_finished_callback_
()
)
{
ROS_DEBUG
(
"IriActionServer::executeCallback::FINISH!"
);
is_active
=
false
;
// get action result
ResultPtr
result
;
ResultPtr
result
(
new
Result
)
;
get_result_callback_
(
result
);
// action has been successfully accomplished
if
(
has_succeed_callback_
()
)
{
ROS_DEBUG
(
"IriActionServer::executeCallback::SUCCEED!"
);
// set action as succeeded
as_
.
setSucceeded
(
*
result
);
}
// action needs to be aborted
else
{
ROS_DEBUG
(
"IriActionServer::executeCallback::ABORTED!"
);
// set action as aborted
as_
.
setAborted
(
*
result
);
}
...
...
@@ -172,9 +196,10 @@ void IriActionServer<ActionSpec>::executeCallback(const GoalConstPtr& goal)
// action has not finished yet
else
{
ROS_DEBUG
(
"IriActionServer::executeCallback::feedback"
);
// get action feedback and publish it
FeedbackPtr
feedback
;
publish
_feedback_callback_
(
feedback
);
FeedbackPtr
feedback
(
new
Feedback
)
;
get
_feedback_callback_
(
feedback
);
as_
.
publishFeedback
(
*
feedback
);
}
...
...
@@ -189,6 +214,12 @@ void IriActionServer<ActionSpec>::registerStartCallback(boost::function<void (co
start_action_callback_
=
cb
;
}
template
<
class
ActionSpec
>
void
IriActionServer
<
ActionSpec
>::
registerStopCallback
(
boost
::
function
<
void
()
>
cb
)
{
stop_action_callback_
=
cb
;
}
template
<
class
ActionSpec
>
void
IriActionServer
<
ActionSpec
>::
registerIsFinishedCallback
(
boost
::
function
<
bool
()
>
cb
)
{
...
...
@@ -208,9 +239,9 @@ void IriActionServer<ActionSpec>::registerGetResultCallback(boost::function<void
}
template
<
class
ActionSpec
>
void
IriActionServer
<
ActionSpec
>::
register
Publish
FeedbackCallback
(
boost
::
function
<
void
(
FeedbackPtr
&
)
>
cb
)
void
IriActionServer
<
ActionSpec
>::
register
Get
FeedbackCallback
(
boost
::
function
<
void
(
FeedbackPtr
&
)
>
cb
)
{
publish
_feedback_callback_
=
cb
;
get
_feedback_callback_
=
cb
;
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment