Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tutorial_ros_pub_sub
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 Summer School
tutorial_ros_pub_sub
Commits
ce5abacb
Commit
ce5abacb
authored
4 years ago
by
Sebastian Ebert
Browse files
Options
Downloads
Patches
Plain Diff
code for service tutorial
parent
ea2d0181
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+8
-0
8 additions, 0 deletions
CMakeLists.txt
src/add_two_ints_client.cpp
+30
-0
30 additions, 0 deletions
src/add_two_ints_client.cpp
src/add_two_ints_server.cpp
+23
-0
23 additions, 0 deletions
src/add_two_ints_server.cpp
with
61 additions
and
0 deletions
CMakeLists.txt
+
8
−
0
View file @
ce5abacb
...
...
@@ -26,3 +26,11 @@ add_dependencies(talker tutorial_ros_pub_sub_generate_messages_cpp)
add_executable
(
listener src/listener.cpp
)
target_link_libraries
(
listener
${
catkin_LIBRARIES
}
)
add_dependencies
(
listener tutorial_ros_pub_sub_generate_messages_cpp
)
add_executable
(
add_two_ints_server src/add_two_ints_server.cpp
)
target_link_libraries
(
add_two_ints_server
${
catkin_LIBRARIES
}
)
add_dependencies
(
add_two_ints_server tutorial_ros_pub_sub_generate_gencpp
)
add_executable
(
add_two_ints_client src/add_two_ints_client.cpp
)
target_link_libraries
(
add_two_ints_client
${
catkin_LIBRARIES
}
)
add_dependencies
(
add_two_ints_client tutorial_ros_pub_sub_generate_gencpp
)
This diff is collapsed.
Click to expand it.
src/add_two_ints_client.cpp
0 → 100644
+
30
−
0
View file @
ce5abacb
#include
"ros/ros.h"
#include
"tutorial_ros_pub_sub/AddTwoInts.h"
#include
<cstdlib>
int
main
(
int
argc
,
char
**
argv
)
{
ros
::
init
(
argc
,
argv
,
"add_two_ints_client"
);
if
(
argc
!=
3
)
{
ROS_INFO
(
"usage: add_two_ints_client X Y"
);
return
1
;
}
ros
::
NodeHandle
n
;
ros
::
ServiceClient
client
=
n
.
serviceClient
<
tutorial_ros_pub_sub
::
AddTwoInts
>
(
"add_two_ints"
);
tutorial_ros_pub_sub
::
AddTwoInts
srv
;
srv
.
request
.
a
=
atoll
(
argv
[
1
]);
srv
.
request
.
b
=
atoll
(
argv
[
2
]);
if
(
client
.
call
(
srv
))
{
ROS_INFO
(
"Sum: %ld"
,
(
long
int
)
srv
.
response
.
sum
);
}
else
{
ROS_ERROR
(
"Failed to call service add_two_ints"
);
return
1
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
src/add_two_ints_server.cpp
0 → 100644
+
23
−
0
View file @
ce5abacb
#include
"ros/ros.h"
#include
"tutorial_ros_pub_sub/AddTwoInts.h"
bool
add
(
tutorial_ros_pub_sub
::
AddTwoInts
::
Request
&
req
,
tutorial_ros_pub_sub
::
AddTwoInts
::
Response
&
res
)
{
res
.
sum
=
req
.
a
+
req
.
b
;
ROS_INFO
(
"request: x=%ld, y=%ld"
,
(
long
int
)
req
.
a
,
(
long
int
)
req
.
b
);
ROS_INFO
(
"sending back response: [%ld]"
,
(
long
int
)
res
.
sum
);
return
true
;
}
int
main
(
int
argc
,
char
**
argv
)
{
ros
::
init
(
argc
,
argv
,
"add_two_ints_server"
);
ros
::
NodeHandle
n
;
ros
::
ServiceServer
service
=
n
.
advertiseService
(
"add_two_ints"
,
add
);
ROS_INFO
(
"Ready to add two ints."
);
ros
::
spin
();
return
0
;
}
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