Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ros2 #38

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft

Ros2 #38

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6242ee2
migrate CMakeLists and packagexml
PetervDooren Feb 27, 2024
35d70a9
fix some cmake errors
PetervDooren Feb 27, 2024
af6dbbf
fix amend_package placement and remove test
PetervDooren Feb 27, 2024
9e950e3
roscpp to rclcpp
PetervDooren Feb 27, 2024
8480d3c
migration
PetervDooren Feb 27, 2024
e8eaf9c
msg conversion
PetervDooren Feb 27, 2024
64efc41
comment rosparam functionality and fix typos
PetervDooren Feb 28, 2024
3604a2e
fix some more errors in logging and imports
PetervDooren Feb 28, 2024
f7fa7ba
fix time syntax
PetervDooren Feb 28, 2024
2049185
fix tf publishing
PetervDooren Feb 28, 2024
5d6e159
fix errors in rate and fsm
PetervDooren Feb 28, 2024
f413ba0
add visualization msgs dependency
PetervDooren Feb 28, 2024
01d7ecc
install executables
PetervDooren Feb 28, 2024
4bd4483
initialise rcl
PetervDooren Feb 28, 2024
966fee9
remove outdated comment
PetervDooren Feb 28, 2024
4385e47
update example for debugging
PetervDooren Mar 8, 2024
254bf97
add ros2 publisher and subscriber wrappers
PetervDooren Mar 8, 2024
2d3b3ba
integrate pub and sub wrappers in communication
PetervDooren Mar 8, 2024
bf373dc
Fix missing newline at EOF
MatthijsBurgh Mar 8, 2024
cd962f0
add node name as argument
PetervDooren Mar 8, 2024
d674459
pull changes to ros2 branch? (#40)
PetervDooren Apr 2, 2024
ec7663b
added publishers for visualizing the localization exercises
KdVos Apr 11, 2024
141123f
changed some function names to be consistent with the ROS1 branch (st…
KdVos Apr 12, 2024
0d0e359
export library
ThijsBeurskensTUE Apr 12, 2024
3c6bf56
forward declare rclcpp rate
ThijsBeurskensTUE Apr 12, 2024
b90ad1c
change library name
ThijsBeurskensTUE Apr 12, 2024
04d1e6b
add comments
PetervDooren Nov 26, 2024
c64ea07
add simple talker script to test subscribers
PetervDooren Nov 26, 2024
32e9fad
compile and adjust libraries for ros2
WiktorBocian Dec 3, 2024
3863ae4
Odometry topic and laser scan topic updated: odometry/filtered and scan
WiktorBocian Dec 6, 2024
a973357
Include library paths into the CMake file to avoid needing to set env…
WiktorBocian Dec 8, 2024
9c20c6c
Merge branch 'master' into ros2
PetervDooren Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
CMakeLists.txt.user*
/build/
/log/
/install/
.txt
*.txt
settings.json
*.pyc
89 changes: 51 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.5)
project(emc_system)

set(CMAKE_CXX_STANDARD 14)

add_compile_options(-Wall -Werror=all)
add_compile_options(-Wextra -Werror=extra)

find_package(catkin REQUIRED COMPONENTS
geometry_msgs
sensor_msgs
nav_msgs
roscpp
tf2
tf2_ros
)
find_package(ament_cmake REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)



# find_package(Boost REQUIRED COMPONENTS system program_options)
# find_package(PCL REQUIRED)
find_package(OpenCV REQUIRED)

# ------------------------------------------------------------------------------------------------
# CATKIN EXPORT
# ------------------------------------------------------------------------------------------------

catkin_package(
# INCLUDE_DIRS include
# LIBRARIES bla
# CATKIN_DEPENDS other_catkin_pkg
# DEPENDS system_lib
)

# ------------------------------------------------------------------------------------------------
# BUILD
# ------------------------------------------------------------------------------------------------
Expand All @@ -36,67 +30,86 @@ include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${tf2_geometry_msgs_INCLUDE_DIRS}
)

add_library(emc_system
add_library(emc-framework SHARED
include/emc/engine.h
include/emc/communication.h
include/emc/data.h
include/emc/odom.h
include/emc/io.h
include/emc/rate.h
include/emc/bumper.h
include/emc/ros2subscriber.h
include/emc/ros2publisher.h

src/engine.cpp
src/communication.cpp
src/data.cpp
#src/data.cpp
src/io.cpp
src/rate.cpp
)
target_link_libraries(emc_system ${catkin_LIBRARIES})
ament_target_dependencies(emc-framework geometry_msgs sensor_msgs visualization_msgs nav_msgs rclcpp tf2 tf2_ros tf2_geometry_msgs)

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

# ------------------------------------------------------------------------------------------------
# TOOLS
# ------------------------------------------------------------------------------------------------

add_executable(emc_viz tools/visualize.cpp)
target_link_libraries(emc_viz emc_system ${OpenCV_LIBRARIES})
target_link_libraries(emc_viz emc-framework ${OpenCV_LIBRARIES})

# ------------------------------------------------------------------------------------------------
# IO
# ------------------------------------------------------------------------------------------------

add_executable(emc_test_io examples/test_io.cpp)
target_link_libraries(emc_test_io emc_system)
target_link_libraries(emc_test_io emc-framework)

add_executable(testspeech examples/testspeech.cpp)
target_link_libraries(testspeech emc_system)
add_executable(emc_test_speech examples/testspeech.cpp)
target_link_libraries(emc_test_speech emc-framework)

add_executable(test_send_path examples/test_sendpath.cpp)
target_link_libraries(test_send_path emc_system)
target_link_libraries(test_send_path emc-framework)

add_executable(test_send_pose examples/test_sendpose.cpp)
target_link_libraries(test_send_pose emc_system)
target_link_libraries(test_send_pose emc-framework)

# ------------------------------------------------------------------------------------------------
# EXAMPLES
# ------------------------------------------------------------------------------------------------

add_executable(emc_example1 examples/example01.cpp)
target_link_libraries(emc_example1 emc_system)
target_link_libraries(emc_example1 emc-framework)

add_executable(emc_example2 examples/example02.cpp)
target_link_libraries(emc_example2 emc_system)
add_executable(emc_test_subscriber examples/test_subscriber.cpp)
target_link_libraries(emc_test_subscriber emc-framework)

add_executable(emc_test_publisher examples/test_publisher.cpp)
target_link_libraries(emc_test_publisher emc-framework)

add_executable(emc_example3 examples/example03.cpp)
target_link_libraries(emc_example3 emc_system)
add_executable(emc_example2 examples/example02.cpp)
target_link_libraries(emc_example2 emc-framework)

# ------------------------------------------------------------------------------------------------
# UNIT TESTS
# ------------------------------------------------------------------------------------------------

if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest_gtest(tests_io test/io.test test/test_io.cpp)
target_link_libraries(tests_io emc_system ${catkin_LIBRARIES})
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(tests_io test/test_io.cpp)
target_link_libraries(tests_io emc-framework)
ament_target_dependencies(tests_io geometry_msgs sensor_msgs nav_msgs rclcpp tf2 tf2_ros)
endif()

#############
## Install ##
#############
install(TARGETS emc-framework emc_example1 emc_example2 emc_test_io emc_test_speech emc_test_subscriber emc_test_publisher
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
1 change: 1 addition & 0 deletions examples/example02.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <emc/engine.h>
#include <emc/data.h>

#include <iostream>

Expand Down
47 changes: 0 additions & 47 deletions examples/example03.cpp

This file was deleted.

7 changes: 7 additions & 0 deletions examples/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

int main()
{
std::cout << "initialising" << std::endl;
// Create IO object, which will initialize the io layer
emc::IO io;

std::cout << "creating rate object" << std::endl;
// Create Rate object, which will help using keeping the loop at a fixed frequency
emc::Rate r(10);

std::cout << "starting loop" << std::endl;
// Loop while we are properly connected
while(io.ok())
{
Expand All @@ -20,10 +23,14 @@ int main()
emc::OdometryData odom;
if (io.readOdometryData(odom))
std::cout << "Odometry: " << odom.x << ", " << odom.y << ", " << odom.a << std::endl;
else
std::cout << "No Odom received" << std::endl;

emc::LaserData scan;
if (io.readLaserData(scan))
std::cout << "Laser: " << scan.ranges.size() << " beams" << std::endl;
else
std::cout << "No laser received" << std::endl;

// Sleep remaining time
r.sleep();
Expand Down
28 changes: 28 additions & 0 deletions examples/test_publisher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "emc/ros2publisher.h"

#include <emc/rate.h>
#include "rclcpp/rclcpp.hpp"

int main()
{
rclcpp::init(0,nullptr);

// Create publisher
emc::Ros2Publisher pub;

// Create Rate object, which will help using keeping the loop at a fixed frequency
emc::Rate r(10);

// Loop while we are properly connected
while(rclcpp::ok())
{
std::cout << "sending msgs" << std::endl;
pub.sendBaseVelocity(1, 0, 0.1);
pub.speak("hello world");

// Sleep remaining time
r.sleep();
}

return 0;
}
36 changes: 36 additions & 0 deletions examples/test_subscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "emc/ros2subscriber.h"

#include <emc/rate.h>
#include "rclcpp/rclcpp.hpp"

#include <sensor_msgs/msg/laser_scan.hpp>

int main()
{
rclcpp::init(0,nullptr);

// Create subscriber
std::shared_ptr<emc::Ros2Subscriber<sensor_msgs::msg::LaserScan>> laser_node = std::make_shared<emc::Ros2Subscriber<sensor_msgs::msg::LaserScan>>("laser_scan", "emc_laser");
rclcpp::executors::SingleThreadedExecutor executor;

executor.add_node(laser_node);

// Create Rate object, which will help using keeping the loop at a fixed frequency
emc::Rate r(10);

// Loop while we are properly connected
while(rclcpp::ok())
{
std::cout << "spin" <<std::endl;
executor.spin_once(std::chrono::nanoseconds(0)); // wait 0 nanoseconds for new messages. just empty the buffer.
sensor_msgs::msg::LaserScan msg;
bool newdata = laser_node->readMsg(msg);
std::cout << "newdata: " << newdata << std::endl;
std::cout << "Laser: " << msg.range_min << " range_min" << std::endl;

// Sleep remaining time
r.sleep();
}

return 0;
}
Loading