Hi,
I had tried to run the demo file for ROS custom handler. While I tried to
build it, it gave an error mentioning that it is unable to identify some
files from ROS include Directory. But on further check I realized that
those files are not missing, but the path to the directory is not being
detected. Could someone please help me resolve this issue?
In Chrono, I have enabled following modules:
- Irrlicht
- ROS
- Vehicle
In addition I have also enabled:
- Openmp
I am running it in Ubuntu 20.04. I have installed ROS2 Galactic. (I am
getting same error in another system with Ubuntu 22.04 and ROS2 Humble).
I have attached the error message along with the source files to this post.
Thank you in advance.
--
You received this message because you are subscribed to the Google Groups
"ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/projectchrono/0122af9b-57a5-4653-ba28-8c536a6186dcn%40googlegroups.com.
// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2023 projectchrono.org
// All right reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: Aaron Young
// =============================================================================
//
// Demo to show how to create a custom Chrono::ROS handler
//
// =============================================================================
#include "chrono/core/ChTypes.h"
#include "chrono/core/ChRealtimeStep.h"
#include "chrono/physics/ChSystemNSC.h"
#include "chrono/physics/ChBody.h"
#include "chrono/physics/ChBodyEasy.h"
#include "chrono/geometry/ChTriangleMeshConnected.h"
#include "chrono_ros/ChROSManager.h"
#include "chrono_ros/ChROSHandler.h"
#include "chrono_ros/handlers/ChROSClockHandler.h"
#include "chrono_ros/handlers/ChROSTFHandler.h"
#include "chrono_ros/handlers/ChROSBodyHandler.h"
#include <std_msgs/msg/int64.hpp>
#include <chrono>
using namespace chrono;
using namespace chrono::ros;
// =============================================================================
class MyCustomHandler : public ChROSHandler {
public:
MyCustomHandler(const std::string& topic) : ChROSHandler(1), m_topic(topic), m_ticker(0) {}
virtual bool Initialize(std::shared_ptr<ChROSInterface> interface) override {
std::cout << "Creating publisher for topic " << m_topic << " ..." << std::endl;
m_publisher = interface->GetNode()->create_publisher<std_msgs::msg::Int64>(m_topic, 1);
return true;
}
virtual void Tick(double time) override {
std::cout << "Publishing " << m_ticker << " ..." << std::endl;
std_msgs::msg::Int64 msg;
msg.data = m_ticker;
m_publisher->publish(msg);
m_ticker++;
}
private:
const std::string m_topic;
rclcpp::Publisher<std_msgs::msg::Int64>::SharedPtr m_publisher;
int m_ticker;
};
// =============================================================================
int main(int argc, char* argv[]) {
std::cout << "Copyright (c) 2023 projectchrono.org\nChrono version: " << CHRONO_VERSION << std::endl << std::endl;
// Create the system
ChSystemNSC sys;
sys.SetGravitationalAcceleration({0, 0, -9.81});
// Add a mesh object to make the scene interesting
auto phys_mat = chrono_types::make_shared<ChContactMaterialNSC>();
phys_mat->SetFriction(0.5f);
auto floor = chrono_types::make_shared<ChBodyEasyBox>(20, 20, 1, 1000, true, true, phys_mat);
floor->SetPos({0, 0, -1});
floor->SetFixed(true);
floor->SetName("floor");
sys.AddBody(floor);
auto box = chrono_types::make_shared<ChBodyEasyBox>(1, 1, 1, 1000, true, true, phys_mat);
box->SetPos({0, 0, 5});
box->SetRot(QuatFromAngleAxis(0.2, {1, 0, 0}));
box->SetName("box");
sys.AddBody(box);
// ------------
// Create ROS manager
auto ros_manager = chrono_types::make_shared<ChROSManager>();
// Create a publisher for the simulation clock
// The clock automatically publishes on every tick and on topic /clock
auto clock_handler = chrono_types::make_shared<ChROSClockHandler>();
ros_manager->RegisterHandler(clock_handler);
// Create a handler that will publish the state of the box
// It will publish at a rate of 25Hz on the topic "~/box"
auto box_handler = chrono_types::make_shared<ChROSBodyHandler>(25, box, "~/box");
ros_manager->RegisterHandler(box_handler);
// Create a TF handler that will publish the transform of the box relative to the floor
auto tf_handler = chrono_types::make_shared<ChROSTFHandler>(100);
tf_handler->AddTransform(floor, floor->GetName(), box, box->GetName());
ros_manager->RegisterHandler(tf_handler);
// Create a custom handler
auto custom_handler = chrono_types::make_shared<MyCustomHandler>("~/my_topic");
ros_manager->RegisterHandler(custom_handler);
// Finally, initialize the ros manager
ros_manager->Initialize();
// ------------
// Simulation
double time = 0;
double step_size = 2e-3;
double time_end = 1000;
// Simulation loop
ChRealtimeStepTimer realtime_timer;
while (time < time_end) {
time = sys.GetChTime();
// Updates
if (!ros_manager->Update(time, step_size))
break;
sys.DoStepDynamics(step_size);
realtime_timer.Spin(step_size);
}
return 0;
}
#--------------------------------------------------------------
#
# Example of CMake configuration file to build an external
# project depending on Chrono and on optional Chrono modules.
#
# This minimal sample project can be used as a template for a
# user project. Modify sections 1, 2, and 3 below as appropriate.
#
#--------------------------------------------------------------
cmake_minimum_required(VERSION 3.18)
cmake_policy(SET CMP0091 NEW)
#--------------------------------------------------------------
# === 1 ===
# Set the project name
#--------------------------------------------------------------
project(ros_demo)
#--------------------------------------------------------------
# === 2 ===
# Find the Chrono package and any REQUIRED or OPTIONAL modules
# by invoking the find_package function in CONFIG mode:
# find_package(Chrono
# COMPONENTS Irrlicht ...
# OPTIONAL_COMPONENTS
# CONFIG)
# The following Chrono modules can be requested (case insensitive):
# Cascade, Cosimulation, Irrlicht, OpenGL, Matlab, Multicore, Gpu,
# PardisoMKL, PardisoProject, Postprocess, Python, Vehicle,
# VehicleCosimm, VSG.
# A component can be requested either as required or optional
# (see the CMake documentation for find_package).
#
# Note that you will have to set the variable Chrono_DIR to
# specify the location of the chrono-config.cmake script, if
# it is not in its default install location.
# Chrono_DIR can be either a Chrono build tree or a Chrono install tree.
#
# The following variables are set and can be used further down:
# Chrono_FOUND
# set to true if Chrono and all required components were found
# CHRONO_C_FLAGS
# CHRONO_CXX_FLAGS
# C and C++ compilation flags
# CHRONO_INCLUDE_DIRS
# additional paths for included headers
# CHRONO_LIBRARIES
# list of required libraries (with full path)
# CHRONO_LINKER_FLAGS
# additional linker flags
# CHRONO_DATA_DIR
# path to the Chrono data make_directory
#
# In addition, for each requested component [COMPONENT], the
# following variable is set to true (ON) or false (OFF):
# CHRONO_[COMPONENT]_FOUND
#
# In this example, we only request the Irrlicht module (required)
# and, for demonstration purposes, the PardisoMKL module (optional)
#--------------------------------------------------------------
LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}/../Chrono/lib")
find_package(Chrono
COMPONENTS Irrlicht
OPTIONAL_COMPONENTS
CONFIG)
#--------------------------------------------------------------
# Return now if Chrono or a required component was not found.
#--------------------------------------------------------------
if (NOT Chrono_FOUND)
message("Could not find Chrono or one of its required modules")
return()
endif()
#--------------------------------------------------------------
# Important! To ensure ABI compatibility, use the same C++ standard
# as the one used to build the Chrono libraries.
#--------------------------------------------------------------
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD ${CHRONO_CXX_STANDARD})
#--------------------------------------------------------------
# Enable creation of "application bundles" on MacOSX.
#--------------------------------------------------------------
# This is necessary for any Irrlicht-based project (like the example here).
# For OpenGL-based or non-graphics projects, this is optional and the block
# below can be removed (or else explcitly set CMAKE_MACOSX_BUNDLE to 'OFF').
#
# If creating application bundles, the build output will be named 'myexe.app'.
# Use the convenience script 'run_app.sh' available under
'contrib/appbundle-macosx/'
# to run:
# start_demo.sh myexe.app
if(APPLE)
set(CMAKE_MACOSX_BUNDLE ON)
endif()
#--------------------------------------------------------------
# Add path to Chrono headers and to headers of all dependencies
# of the requested modules.
#--------------------------------------------------------------
include_directories(${CHRONO_INCLUDE_DIRS})
#-----------------------------------------------------------------------------
# Fix for VS 2017 15.8 and newer to handle alignment specification with Eigen
#-----------------------------------------------------------------------------
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(MSVC AND ${MSVC_VERSION} GREATER_EQUAL 1915)
add_definitions( "-D_ENABLE_EXTENDED_ALIGNED_STORAGE" )
endif()
endif()
#--------------------------------------------------------------
# Tweaks to disable some warnings with MSVC
#--------------------------------------------------------------
if(MSVC)
add_definitions("-D_CRT_SECURE_NO_DEPRECATE") # avoids deprecation warnings
add_definitions("-D_SCL_SECURE_NO_DEPRECATE") # avoids deprecation warnings
add_definitions( "-DNOMINMAX" ) # do not use MSVC's min/max
macros
endif()
#--------------------------------------------------------------
# === 3 ===
# Add the executable from your project and specify all C++
# files in your project.
#--------------------------------------------------------------
add_executable(my_demo demo_ROS_custom_handler.cpp)
#--------------------------------------------------------------
# Set properties for your executable target
#
# Note that here we define a macro CHRONO_DATA_DIR which will
# contain the path to the Chrono data directory, either in its
# source tree (if using a build version of Chrono), or in its
# install tree (if using an installed version of Chrono).
#--------------------------------------------------------------
target_compile_definitions(my_demo PUBLIC
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\"")
target_compile_options(my_demo PUBLIC ${CHRONO_CXX_FLAGS})
target_link_options(my_demo PUBLIC ${CHRONO_LINKER_FLAGS})
#--------------------------------------------------------------
# Link to Chrono libraries and dependency libraries
#--------------------------------------------------------------
target_link_libraries(my_demo ${CHRONO_LIBRARIES})
#--------------------------------------------------------------
# === 4 (OPTIONAL) ===
#
# Optionally, add a custom command for copying all Chrono and
# dependency DLLs to the appropriate binary output folder.
# This function has effect only on Windows.
#
# DLLs will be copied into ${PROJECT_BINARY_DIR}/${config} by default
# or in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${config} if only
CMAKE_RUNTIME_OUTPUT_DIRECTORY is set
# or to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_<CONFIG>} if the specific
CMAKE_RUNTIME_OUTPUT_DIRECTORY_<CONFIG> has been set
#--------------------------------------------------------------
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "<mycustompathforrelease>")
add_DLL_copy_command()