Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CCF Immersive Sorting Demo
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
CeTI
ROS
CeTI Cobotic Framework
CCF Immersive Sorting Demo
Commits
b8f4c2fa
Commit
b8f4c2fa
authored
3 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
add settings and ros message interface to dummy selection provider
parent
ab88f031
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
src/dummy_selection_provider.cpp
+55
-26
55 additions, 26 deletions
src/dummy_selection_provider.cpp
with
55 additions
and
26 deletions
src/dummy_selection_provider.cpp
+
55
−
26
View file @
b8f4c2fa
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
#include
"ros/ros.h"
#include
"ros/ros.h"
#include
"std_msgs/String.h"
#include
"std_msgs/String.h"
#include
"ccf/util/NodeUtil.h"
#include
<nng/nng.h>
#include
<nng/nng.h>
#include
<nng/protocol/pair1/pair.h>
#include
<nng/protocol/pair1/pair.h>
...
@@ -51,6 +53,9 @@ int main(int argc, char **argv) {
...
@@ -51,6 +53,9 @@ int main(int argc, char **argv) {
ros
::
NodeHandle
n
(
"ccf"
);
ros
::
NodeHandle
n
(
"ccf"
);
auto
autoselect
=
CetiRosToolbox
::
getPrivateParameter
<
bool
>
(
"autoselect"
,
"false"
);
auto
prefix
=
CetiRosToolbox
::
getPrivateParameter
<
std
::
string
>
(
"prefix"
,
"sub_select"
);
if
((
rv
=
nng_pair1_open
(
&
sock
))
!=
0
)
{
if
((
rv
=
nng_pair1_open
(
&
sock
))
!=
0
)
{
ROS_ERROR_STREAM
(
"nng_pair1_open returned: "
<<
nng_strerror
(
rv
));
ROS_ERROR_STREAM
(
"nng_pair1_open returned: "
<<
nng_strerror
(
rv
));
}
}
...
@@ -70,6 +75,11 @@ int main(int argc, char **argv) {
...
@@ -70,6 +75,11 @@ int main(int argc, char **argv) {
std
::
random_device
rd
;
std
::
random_device
rd
;
std
::
mt19937
rng
(
rd
());
std
::
mt19937
rng
(
rd
());
ros
::
Subscriber
sub_select
=
n
.
subscribe
<
std_msgs
::
String
>
(
prefix
+
"/select"
,
1000
,
[
&
](
auto
&
m
)
{
sendSelection
(
m
->
data
);
});
ros
::
Publisher
pub_objects
=
n
.
advertise
<
std_msgs
::
String
>
(
prefix
+
"/objects"
,
1
);
ros
::
Publisher
pub_bins
=
n
.
advertise
<
std_msgs
::
String
>
(
prefix
+
"/bins"
,
1
);
while
(
ros
::
ok
())
{
while
(
ros
::
ok
())
{
char
*
buf
=
nullptr
;
char
*
buf
=
nullptr
;
...
@@ -104,33 +114,52 @@ int main(int argc, char **argv) {
...
@@ -104,33 +114,52 @@ int main(int argc, char **argv) {
}
}
}
}
if
(
objects
.
empty
())
{
std_msgs
::
String
objects_msg
;
ROS_INFO
(
"No objects to select in a scene without boxes!"
);
objects_msg
.
data
=
objects
.
empty
()
?
""
:
}
else
if
(
bins
.
empty
())
{
std
::
accumulate
(
ROS_INFO
(
"No bin to put the object in available!"
);
++
objects
.
begin
(),
objects
.
end
(),
}
else
{
*
objects
.
begin
(),
// select a random object
[](
auto
&
a
,
auto
&
b
)
{
return
a
+
","
+
b
;
});
std
::
uniform_int_distribution
<
u_long
>
distribution
{
0
,
objects
.
size
()
-
1
};
pub_objects
.
publish
(
objects_msg
);
// wait some time, then send a selected object
pause_rate
.
sleep
();
std_msgs
::
String
bins_msg
;
std
::
string
object
{
objects
[
distribution
(
rng
)]};
bins_msg
.
data
=
bins
.
empty
()
?
""
:
std
::
accumulate
(
ROS_INFO_STREAM
(
"Selecting random object: "
<<
object
);
++
bins
.
begin
(),
bins
.
end
(),
sendSelection
(
object
);
*
bins
.
begin
(),
[](
auto
&
a
,
auto
&
b
)
{
return
a
+
","
+
b
;
});
// wait again, then send the bin object
pause_rate
.
sleep
();
pub_bins
.
publish
(
bins_msg
);
// we expect an object named "bin" to be there
if
(
autoselect
)
{
// select a random object
if
(
objects
.
empty
())
{
std
::
uniform_int_distribution
<
u_long
>
binDistribution
{
0
,
bins
.
size
()
-
1
};
ROS_INFO
(
"No objects to select in a scene without boxes!"
);
}
else
if
(
bins
.
empty
())
{
std
::
string
bin
{
bins
[
binDistribution
(
rng
)]};
ROS_INFO
(
"No bin to put the object in available!"
);
ROS_INFO_STREAM
(
"Selecting random bin: "
<<
bin
);
}
else
{
sendSelection
(
bin
);
// select a random object
std
::
uniform_int_distribution
<
u_long
>
distribution
{
0
,
objects
.
size
()
-
1
};
// wait some time, then send a selected object
pause_rate
.
sleep
();
std
::
string
object
{
objects
[
distribution
(
rng
)]};
ROS_INFO_STREAM
(
"Selecting random object: "
<<
object
);
sendSelection
(
object
);
// wait again, then send the bin object
pause_rate
.
sleep
();
// we expect an object named "bin" to be there
// select a random object
std
::
uniform_int_distribution
<
u_long
>
binDistribution
{
0
,
bins
.
size
()
-
1
};
std
::
string
bin
{
bins
[
binDistribution
(
rng
)]};
ROS_INFO_STREAM
(
"Selecting random bin: "
<<
bin
);
sendSelection
(
bin
);
}
}
}
}
else
if
(
rv
==
NNG_EAGAIN
)
{
}
else
if
(
rv
==
NNG_EAGAIN
)
{
// no message received in current spin
// no message received in current spin
}
else
{
}
else
{
...
...
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