Commit 428a9ea1 authored by CANNERE Xavier's avatar CANNERE Xavier
Browse files

modif t5 s1/s2

parent fd999969
......@@ -21,12 +21,112 @@ The objective is to create two components, a producer and a consumer.
Step 1 : Create the package
---------------------------
First we'll create the package with these following lines::
First we'll create one package for the main nodes with these following lines::
cd ~/colcon_ws/src
ros2 pkg create --build-type ament_cmake --node-name follower pkg_follower
ros2 pkg create --build-type ament_cmake pkg_follower
And one for the service::
ros2 pkg create --build-type ament_cmake pkg_srv
colcon build
Step 2 : Create the service
---------------------------
The service will allow the reset of the counter, type these on a terminal::
cd ~/colcon_ws/src/pkg_srv
mkdir srv
cd srv
gedit Raz.srv
And on your file paste that::
int64 a
---
int64 b
It define there is an int in input and an other int in output. Save and close your file.
Now edit your CMakeLists.txt of ``pkg_srv``::
cmake_minimum_required(VERSION 3.8)
project(pkg_srv)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/Raz.srv"
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
These lines define the service on the CMakeLists::
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/Raz.srv"
)
And your package.xml::
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>pkg_srv</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="Xavier.CANNERE@isae-supaero.fr">etdisc</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
And these lines define the service on the package.xml::
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
Step 2 : Create the producer
Step 3 : Create the producer
----------------------------
The producer is the node who'll publish information
......@@ -40,6 +140,8 @@ Open QtCreator, create a new file called ``producer.cpp`` into ``/src`` of ``pk
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/int64.hpp"
#include "pkg_srv/srv/raz.hpp"
This is part of the code where we include libraries::
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment