ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

clepz's profile - activity

2022-03-03 02:47:53 -0500 received badge  Student (source)
2021-11-24 06:39:08 -0500 received badge  Notable Question (source)
2021-11-24 06:39:08 -0500 received badge  Famous Question (source)
2021-11-24 06:39:08 -0500 received badge  Popular Question (source)
2021-07-01 01:45:54 -0500 edited question Log4cxx shutdown on ros::shutdown

Log4cxx shutdown on ros::shutdown Hi, I want to use my own logger. However I can't use the logger after call ros::shutdo

2021-07-01 01:44:27 -0500 edited question Log4cxx shutdown on ros::shutdown

Log4cxx shutdown on ros::shutdown Hi, I want to use my own logger. However I can't use the logger after call ros::shutdo

2021-07-01 01:44:27 -0500 received badge  Editor (source)
2021-07-01 01:43:44 -0500 edited question Log4cxx shutdown on ros::shutdown

Log4cxx shutdown on ros::shutdown Hi, I want to use my own logger. However I can't use the logger after call ros::shutdo

2021-07-01 01:42:30 -0500 asked a question Log4cxx shutdown on ros::shutdown

Log4cxx shutdown on ros::shutdown Hi, I want to use my own logger. However I can't use the logger after call ros::shutdo

2021-06-26 02:39:32 -0500 received badge  Famous Question (source)
2021-04-28 16:17:48 -0500 received badge  Notable Question (source)
2021-04-17 21:00:49 -0500 received badge  Popular Question (source)
2021-04-05 05:51:37 -0500 marked best answer Linker error for geometry_msgs

Hi,

I explore ros2 recently. Differences with ros, creating custom messages, pub sub examples for c++ etc.

I just wanted to demonstrate that another package can be used in a custom message.

I generated a message for simple pub-sub example. Message and its CMakefile in autodrive_msgs package :

AccelCommand.msg

float32 accel
geometry_msgs/Vector3 v

CMakefile:

cmake_minimum_required(VERSION 3.5)
project(autodrive_msgs)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

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)
find_package(rclcpp)
find_package(autodrive_msgs)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/AccelCommand.msg"
 )
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

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

I can generate the message. However It gives me a linker error when I want to use the message. Codes and CMakefile in pub_sub package:

pub.cpp:

#include <chrono>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "autodrive_msgs/msg/accel_command.hpp"     // CHANGE

using namespace std::chrono_literals;

class MinimalPublisher : public rclcpp::Node
{
public:
  MinimalPublisher()
  : Node("minimal_publisher"), count_(0)
  {
    publisher_ = this->create_publisher<autodrive_msgs::msg::AccelCommand>("topic", 10);    // CHANGE
    timer_ = this->create_wall_timer(
      500ms, std::bind(&MinimalPublisher::timer_callback, this));
  }

private:
  void timer_callback()
  {
    auto message = autodrive_msgs::msg::AccelCommand();                               // CHANGE
    message.accel = this->count_++;                                        // CHANGE
    RCLCPP_INFO(this->get_logger(), "Publishing: '%d'", message.accel);    // CHANGE
    publisher_->publish(message);
  }
  rclcpp::TimerBase::SharedPtr timer_;
  rclcpp::Publisher<autodrive_msgs::msg::AccelCommand>::SharedPtr publisher_;         // CHANGE
  size_t count_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<MinimalPublisher>());
  rclcpp::shutdown();
  return 0;
}

sub.cpp:

#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "autodrive_msgs/msg/accel_command.hpp"     // CHANGE
using std::placeholders::_1;

class MinimalSubscriber : public rclcpp::Node
{
public:
  MinimalSubscriber()
  : Node("minimal_subscriber")
  { 
    subscription_ = this->create_subscription<autodrive_msgs::msg::AccelCommand>(          // CHANGE
      "topic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1));
  }

private:
  void topic_callback(const autodrive_msgs::msg::AccelCommand::SharedPtr msg) const       // CHANGE
  {
    RCLCPP_INFO(this->get_logger(), "I heard: '%d'", msg->accel);              // CHANGE
  }
  rclcpp::Subscription<autodrive_msgs::msg::AccelCommand>::SharedPtr subscription_;       // CHANGE
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<MinimalSubscriber>());
  rclcpp::shutdown();
  return 0;
}

CMakefile:

cmake_minimum_required(VERSION 3.5)
project(pub_sub)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

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)
find_package(rclcpp)
find_package(autodrive_msgs)
find_package(geometry_msgs)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)


add_executable(talker src/pub.cpp)
ament_target_dependencies(talker rclcpp autodrive_msgs geometry_msgs)         # CHANGE

add_executable(listener src/sub.cpp)
ament_target_dependencies(listener rclcpp autodrive_msgs geometry_msgs)     # CHANGE

install(TARGETS
  talker
  listener
  DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which ...
(more)
2021-04-05 05:50:51 -0500 commented answer Linker error for geometry_msgs

Thank you a lot. It builds now. I get this warning: WARNING:colcon.colcon_ros.prefix_path.ament:The path '/home/clepz/w

2021-04-05 05:49:26 -0500 received badge  Rapid Responder (source)
2021-04-05 05:49:26 -0500 answered a question Linker error for geometry_msgs

Thank you a lot. It builds now. I get this warning: WARNING:colcon.colcon_ros.prefix_path.ament:The path '/home/clepz/

2021-04-05 01:31:57 -0500 asked a question Linker error for geometry_msgs

Linker error for geometry_msgs Hi, I explore ros2 recently. Differences with ros, creating custom messages, pub sub exa

2020-02-06 12:56:57 -0500 received badge  Famous Question (source)
2020-02-06 12:56:57 -0500 received badge  Notable Question (source)
2020-01-22 07:56:11 -0500 received badge  Famous Question (source)
2020-01-22 07:56:11 -0500 received badge  Notable Question (source)
2019-12-05 06:59:44 -0500 received badge  Popular Question (source)
2019-11-26 15:12:14 -0500 marked best answer How to use protobuf with ros?

Hello everyone,

I have been searching for hours but I couldn't find any documentation about how to use protobuf with ros. I really don't know how to create a message with protobuf. If anyone could help me I would be glad.

2019-11-26 15:12:14 -0500 received badge  Scholar (source)
2019-11-25 04:58:45 -0500 received badge  Supporter (source)
2019-11-25 03:23:59 -0500 commented question How to use protobuf with ros?

http://wiki.ros.org/sig/NextGenerationROS/MessageFormats I want to publish my proto message. I tried few things but I co

2019-11-24 23:01:15 -0500 asked a question How to use protobuf with ros?

How to use protobuf with ros? Hello everyone, I have been searching for hours but I couldn't find any documentation abo

2019-10-10 07:04:28 -0500 received badge  Popular Question (source)
2019-10-01 13:50:12 -0500 answered a question How to see lgsvl vehicle main camera in rviz?

thank you, I did it. For people who have the same problem, the solution is : When lgsvl simulator connected to rosbrige,

2019-10-01 12:07:05 -0500 received badge  Rapid Responder (source)
2019-09-30 13:16:31 -0500 asked a question How to see lgsvl vehicle main camera in rviz?

How to see lgsvl vehicle main camera in rviz? Hi everyone, I need to achieve that main camera of lgsvl autoware vehicle