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 15 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
67 changes: 34 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
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(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 @@ -39,21 +30,21 @@ include_directories(
)

add_library(emc_system
include/emc/engine.h
#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

src/engine.cpp
#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_system geometry_msgs sensor_msgs visualization_msgs nav_msgs rclcpp tf2 tf2_ros)

# ------------------------------------------------------------------------------------------------
# TOOLS
Expand All @@ -69,8 +60,8 @@ target_link_libraries(emc_viz emc_system ${OpenCV_LIBRARIES})
add_executable(emc_test_io examples/test_io.cpp)
target_link_libraries(emc_test_io emc_system)

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_system)

# ------------------------------------------------------------------------------------------------
# EXAMPLES
Expand All @@ -79,15 +70,25 @@ target_link_libraries(testspeech emc_system)
add_executable(emc_example1 examples/example01.cpp)
target_link_libraries(emc_example1 emc_system)

add_executable(emc_example2 examples/example02.cpp)
target_link_libraries(emc_example2 emc_system)
#add_executable(emc_example2 examples/example02.cpp)
#target_link_libraries(emc_example2 emc_system)

# ------------------------------------------------------------------------------------------------
# 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})
endif()
#if(BUILD_TESTING)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come on @PetervDooren, you can migrate tests as well. You have the skills

# find_package(rostest REQUIRED)
# add_rostest_gtest(tests_io test/io.test test/test_io.cpp)
# target_link_libraries(tests_io emc_system)
# ament_target_dependencies(emc_system geometry_msgs sensor_msgs nav_msgs roscpp tf2 tf2_ros rostest)
#endif()

#############
## Install ##
#############
install(TARGETS emc_example1 emc_test_io emc_test_speech
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
82 changes: 34 additions & 48 deletions include/emc/communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
#include "emc/odom.h"
#include "emc/bumper.h"

#include <ros/publisher.h>
#include <ros/subscriber.h>
#include <ros/callback_queue.h>
#include "rclcpp/rclcpp.hpp"
//#include <ros/callback_queue.h>
#include <tf2_ros/transform_broadcaster.h>
#include <sensor_msgs/JointState.h>
#include <nav_msgs/MapMetaData.h>
#include "nav_msgs/msg/map_meta_data.hpp"

#include <std_msgs/msg/bool.hpp>
#include <sensor_msgs/msg/laser_scan.hpp>
#include <visualization_msgs/msg/marker.hpp>
#include <nav_msgs/msg/odometry.hpp>
#include <geometry_msgs/msg/twist.hpp>
#include <std_msgs/msg/empty.hpp>
#include <std_msgs/msg/string.hpp>

#include <std_msgs/Bool.h>
#include <sensor_msgs/LaserScan.h>
#include <visualization_msgs/Marker.h>
#include <nav_msgs/Odometry.h>
#include <string>
#include <memory>

namespace emc
{

class Communication
class Communication : public rclcpp::Node
{

public:
Expand All @@ -44,70 +46,54 @@ class Communication

void sendOpendoorRequest();

void sendMarker(visualization_msgs::Marker marker);
void sendMarker(visualization_msgs::msg::Marker marker);

void speak(const std::string& text);

void play(const std::string& file);

// Postion data
void sendPoseEstimate(const geometry_msgs::Transform& pose);
void sendPoseEstimate(const geometry_msgs::msg::Transform& pose);

private:

// Base velocity reference
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr pub_cmd_vel_;
rclcpp::Publisher<std_msgs::msg::Empty>::SharedPtr pub_open_door_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_speak_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_play_;
rclcpp::Publisher<visualization_msgs::msg::Marker>::SharedPtr pub_marker_;

ros::Publisher pub_base_ref_;

ros::Publisher pub_open_door_;

ros::Publisher pub_speak_;

ros::Publisher pub_play_;

ros::Publisher pub_marker_;
// Position data

std::unique_ptr<tf2_ros::TransformBroadcaster> pub_tf2; //has to be defined after ros::init(), which is called in the constructor

// pose publishing
std::string robot_frame_name;
std::unique_ptr<tf2_ros::TransformBroadcaster> pub_tf2_;

// Laser data
rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr sub_laser_;

ros::CallbackQueue laser_cb_queue_;

ros::Subscriber sub_laser_;
sensor_msgs::msg::LaserScan::SharedPtr laser_msg_;

sensor_msgs::LaserScanConstPtr laser_msg_;

void laserCallback(const sensor_msgs::LaserScanConstPtr& msg);
void laserCallback(const sensor_msgs::msg::LaserScan::SharedPtr msg);


// Odometry data

ros::CallbackQueue odom_cb_queue_;

ros::Subscriber sub_odom_;
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr sub_odom_;

nav_msgs::OdometryConstPtr odom_msg_;
nav_msgs::msg::Odometry::SharedPtr odom_msg_;

void odomCallback(const nav_msgs::OdometryConstPtr& msg);
void odomCallback(const nav_msgs::msg::Odometry::SharedPtr msg);

// Bumper data
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr sub_bumper_f_;
rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr sub_bumper_b_;

ros::CallbackQueue bumper_f_cb_queue_;
ros::CallbackQueue bumper_b_cb_queue_;
std_msgs::msg::Bool::SharedPtr bumper_f_msg_;
std_msgs::msg::Bool::SharedPtr bumper_b_msg_;

ros::Subscriber sub_bumper_f_;
ros::Subscriber sub_bumper_b_;
void bumperfCallback(const std_msgs::msg::Bool::SharedPtr msg);
void bumperbCallback(const std_msgs::msg::Bool::SharedPtr msg);

std_msgs::BoolConstPtr bumper_f_msg_;
std_msgs::BoolConstPtr bumper_b_msg_;

void bumperfCallback(const std_msgs::BoolConstPtr& msg);
void bumperbCallback(const std_msgs::BoolConstPtr& msg);

// pose publishing
std::string robot_frame_name;
};

} // end namespace emc
Expand Down
3 changes: 2 additions & 1 deletion include/emc/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct ControlEffort

// ----------------------------------------------------------------------------------------------------

/*
class FSMInterface
{

Expand All @@ -51,7 +52,7 @@ class FSMInterface
std::string event_;

};

*/
} // end namespace emc

#endif
13 changes: 8 additions & 5 deletions include/emc/rate.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef EMC_SYSTEM_RATE_H_
#define EMC_SYSTEM_RATE_H_

namespace ros
#include "rclcpp/rclcpp.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should include this in the source file. That is why the pre-declaration was there.

#include <rclcpp/logger.hpp>

/*namespace rclcpp
{
class Rate;
class GenericRate;
}

*/
namespace emc
{

Expand All @@ -22,8 +25,8 @@ class Rate

private:

ros::Rate* rate_;

rclcpp::GenericRate<std::chrono::system_clock>* rate_;
//rclcpp::Logger logger_;
};


Expand Down
12 changes: 9 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="2.0"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no XML version 2...

<?xml-model
href="http://download.ros.org/schema/package_format3.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
Expand All @@ -11,19 +11,25 @@

<license>TODO</license>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only needed when generating message, etc.

Though you should have a buildtool dep on ament_cmake


<depend>geometry_msgs</depend>
<depend>nav_msgs</depend>
<depend>roscpp</depend>
<depend>rclcpp</depend>
<depend>sensor_msgs</depend>
<depend>visualization_msgs</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>

<exec_depend>rosidl_default_runtime</exec_depend>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not needed as we are not generating messages etc.


<doc_depend>doxygen</doc_depend>

<test_depend>ament_cmake_gtest</test_depend>

<export>
<rosdoc config="rosdoc.yaml" />
<build_type>ament_cmake</build_type>
</export>

</package>
Loading