Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rosjava_actionlib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Sebastian Ebert
rosjava_actionlib
Commits
6a5bb264
Commit
6a5bb264
authored
9 years ago
by
Ernesto Corbellini
Browse files
Options
Downloads
Patches
Plain Diff
Updated test client.
parent
6e967a1d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/rosjava_actionlib/rosjava_actionlib/src/main/java/com/github/ekumen/rosjava_actionlib/TestClient.java
+44
-39
44 additions, 39 deletions
.../java/com/github/ekumen/rosjava_actionlib/TestClient.java
with
44 additions
and
39 deletions
src/rosjava_actionlib/rosjava_actionlib/src/main/java/com/github/ekumen/rosjava_actionlib/TestClient.java
+
44
−
39
View file @
6a5bb264
...
@@ -21,6 +21,7 @@ import org.ros.namespace.GraphName;
...
@@ -21,6 +21,7 @@ import org.ros.namespace.GraphName;
import
org.ros.node.AbstractNodeMain
;
import
org.ros.node.AbstractNodeMain
;
import
org.ros.node.ConnectedNode
;
import
org.ros.node.ConnectedNode
;
import
org.ros.internal.message.Message
;
import
org.ros.internal.message.Message
;
import
org.ros.message.Duration
;
import
actionlib_tutorials.FibonacciActionGoal
;
import
actionlib_tutorials.FibonacciActionGoal
;
import
actionlib_tutorials.FibonacciActionFeedback
;
import
actionlib_tutorials.FibonacciActionFeedback
;
import
actionlib_tutorials.FibonacciActionResult
;
import
actionlib_tutorials.FibonacciActionResult
;
...
@@ -31,7 +32,6 @@ import actionlib_msgs.GoalStatusArray;
...
@@ -31,7 +32,6 @@ import actionlib_msgs.GoalStatusArray;
import
actionlib_msgs.GoalID
;
import
actionlib_msgs.GoalID
;
import
actionlib_msgs.GoalStatus
;
import
actionlib_msgs.GoalStatus
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
/**
/**
...
@@ -39,9 +39,14 @@ import org.apache.commons.logging.LogFactory;
...
@@ -39,9 +39,14 @@ import org.apache.commons.logging.LogFactory;
* @author Ernesto Corbellini ecorbellini@ekumenlabs.com
* @author Ernesto Corbellini ecorbellini@ekumenlabs.com
*/
*/
public
class
TestClient
extends
AbstractNodeMain
implements
ActionClientListener
<
FibonacciActionFeedback
,
FibonacciActionResult
>
{
public
class
TestClient
extends
AbstractNodeMain
implements
ActionClientListener
<
FibonacciActionFeedback
,
FibonacciActionResult
>
{
static
{
// comment this line if you want logs activated
System
.
setProperty
(
"org.apache.commons.logging.Log"
,
"org.apache.commons.logging.impl.NoOpLog"
);
}
private
ActionClient
ac
=
null
;
private
ActionClient
ac
=
null
;
private
volatile
boolean
resultReceived
=
false
;
private
volatile
boolean
resultReceived
=
false
;
private
Log
log
=
LogFactory
.
getLog
(
ActionClient
.
class
)
;
private
Log
log
;
@Override
@Override
public
GraphName
getDefaultNodeName
()
{
public
GraphName
getDefaultNodeName
()
{
...
@@ -52,48 +57,49 @@ public class TestClient extends AbstractNodeMain implements ActionClientListener
...
@@ -52,48 +57,49 @@ public class TestClient extends AbstractNodeMain implements ActionClientListener
public
void
onStart
(
ConnectedNode
node
)
{
public
void
onStart
(
ConnectedNode
node
)
{
ac
=
new
ActionClient
<
FibonacciActionGoal
,
FibonacciActionFeedback
,
FibonacciActionResult
>(
node
,
"/fibonacci"
,
FibonacciActionGoal
.
_TYPE
,
FibonacciActionFeedback
.
_TYPE
,
FibonacciActionResult
.
_TYPE
);
ac
=
new
ActionClient
<
FibonacciActionGoal
,
FibonacciActionFeedback
,
FibonacciActionResult
>(
node
,
"/fibonacci"
,
FibonacciActionGoal
.
_TYPE
,
FibonacciActionFeedback
.
_TYPE
,
FibonacciActionResult
.
_TYPE
);
FibonacciActionGoal
goalMessage
;
FibonacciActionGoal
goalMessage
;
int
repeat
=
3
;
GoalID
gid
;
int
i
=
0
;
Duration
serverTimeout
=
new
Duration
(
20
)
;
String
goalId
=
"fibonacci_test_"
;
boolean
serverStarted
;
log
=
node
.
getLog
();
// Attach listener for the callbacks
// Attach listener for the callbacks
ac
.
attachListener
(
this
);
ac
.
attachListener
(
this
);
System
.
out
.
println
(
"\nWaiting for action server to start..."
);
System
.
out
.
println
(
"Waiting for actionlib server to start..."
);
serverStarted
=
ac
.
waitForActionServerToStart
(
new
Duration
(
20
));
ac
.
waitForActionServerToStart
();
if
(
serverStarted
)
{
System
.
out
.
println
(
"actionlib server started."
);
System
.
out
.
println
(
"Action server started.\n"
);
}
else
{
System
.
out
.
println
(
"No actionlib server found after waiting for "
+
serverTimeout
.
totalNsecs
()/
1
e9
+
" seconds!"
);
System
.
exit
(
1
);
}
// Create Fibonacci goal message
// Create Fibonacci goal message
//goalMessage = (FibonacciActionGoal)ac.newGoalMessage();
//FibonacciGoal fibonacciGoal = goalMessage.getGoal();
// set Fibonacci parameter
//fibonacciGoal.setOrder(6);
/*for (i = 0; i < repeat; i++) {
//sleep(10000);
System.out.println("Sending goal #" + i + "...");
goalMessage
=
(
FibonacciActionGoal
)
ac
.
newGoalMessage
();
goalMessage
=
(
FibonacciActionGoal
)
ac
.
newGoalMessage
();
goalMessage.getGoal().setOrder(i*3);
FibonacciGoal
fibonacciGoal
=
goalMessage
.
getGoal
();
ac.sendGoal(goalMessage, goalId + i);
// set Fibonacci parameter
System.out.println("Goal sent.");
fibonacciGoal
.
setOrder
(
3
);
resultReceived = false;
System
.
out
.
println
(
"Sending goal..."
);
}*/
// send another message and cancel it
goalId
+=
i
;
goalMessage
=
(
FibonacciActionGoal
)
ac
.
newGoalMessage
();
goalMessage
.
getGoal
().
setOrder
(
3
);
//System.out.println("Sending goal ID: " + goalId + "...");
//ac.sendGoal(goalMessage, goalId);
ac
.
sendGoal
(
goalMessage
);
ac
.
sendGoal
(
goalMessage
);
GoalID
gid
=
ac
.
getGoalId
(
goalMessage
);
gid
=
ac
.
getGoalId
(
goalMessage
);
System
.
out
.
println
(
"Goal sent. Goal ID: "
+
gid
);
System
.
out
.
println
(
"Sent goal with ID: "
+
gid
.
getId
());
//sleep(1000);
System
.
out
.
println
(
"Waiting for goal to complete..."
);
//System.out.println("Cancelling goal ID: " + goalId);
while
(
ac
.
getGoalState
()
!=
ClientStateMachine
.
ClientStates
.
DONE
)
{
//ac.sendCancel(gid);
sleep
(
1
);
sleep
(
5000
);
}
System
.
out
.
println
(
"Goal completed!\n"
);
System
.
out
.
println
(
"Sending a new goal..."
);
ac
.
sendGoal
(
goalMessage
);
gid
=
ac
.
getGoalId
(
goalMessage
);
System
.
out
.
println
(
"Sent goal with ID: "
+
gid
.
getId
());
System
.
out
.
println
(
"Cancelling this goal..."
);
ac
.
sendCancel
(
gid
);
while
(
ac
.
getGoalState
()
!=
ClientStateMachine
.
ClientStates
.
DONE
)
{
sleep
(
1
);
}
System
.
out
.
println
(
"Goal cancelled succesfully.\n"
);
System
.
out
.
println
(
"Bye!"
);
System
.
exit
(
0
);
System
.
exit
(
0
);
}
}
...
@@ -104,11 +110,10 @@ public class TestClient extends AbstractNodeMain implements ActionClientListener
...
@@ -104,11 +110,10 @@ public class TestClient extends AbstractNodeMain implements ActionClientListener
int
i
;
int
i
;
resultReceived
=
true
;
resultReceived
=
true
;
System
.
out
.
print
(
"Got Fibonacci result sequence: "
);
System
.
out
.
print
(
"Got Fibonacci result sequence!"
);
for
(
i
=
0
;
i
<
sequence
.
length
;
i
++)
for
(
i
=
0
;
i
<
sequence
.
length
;
i
++)
System
.
out
.
print
(
Integer
.
toString
(
sequence
[
i
])
+
" "
);
System
.
out
.
print
(
Integer
.
toString
(
sequence
[
i
])
+
" "
);
System
.
out
.
print
(
"
\n
"
);
System
.
out
.
print
ln
(
""
);
}
}
@Override
@Override
...
...
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