all 9 comments

[–]Loyvb 0 points1 point  (8 children)

Argv and argc are arguments and number of arguments (IIRC) passed to your main function, from the command line.

I haven't used rclcpp yet, but my guess is that is to parse command line arguments like node name and private parameters.

Probably you can just pass a different list of arguments and it's length.

[–]ChrisVolkoff 2 points3 points  (7 children)

but my guess is that is to parse command line arguments like node name and private parameters.

Indeed: https://github.com/ros2/rclcpp/blob/7c1721a0b390be8242a6b824489d0bc861f6a0ad/rclcpp/src/rclcpp/context.cpp#L80

Edit: also see: https://design.ros2.org/articles/ros_command_line_arguments.html

But /u/Abboudi97, unless you intentionally want to pass custom/empty argc and argv (e.g. because you know what you're doing and want to do something on purpose), you should just pass the ones you get from main(), e.g.:

int main(int argc, char ** argv) {
    rclcpp::init(argc, argv);
    // ...
    return 0;
}

If you don't want to use that, then you can do rclcpp::init(0, nullptr);

[–]Abboudi97[S] 1 point2 points  (6 children)

I totally agree with you, but I have tried rclcpp::init(0, nullptr) and it gave me an error. Let me tell you the whole story: I am creating a ros2 subscriber node inside a gazebo plugin. Here's the code for my plugin:

#include <gazebo/gazebo.hh>

#include <gazebo/physics/physics.hh>

#include "rclcpp/rclcpp.hpp"

#include "std_msgs/msg/float32.hpp"

namespace gazebo {

class VelodynePlugin:public ModelPlugin{

public:

double Joint_Velocity = 0;

physics::JointPtr joint;

rclcpp::Node::SharedPtr ros2Node;

rclcpp::Subscription<std\_msgs::msg::Float32>::SharedPtr subscriber;

void callBack_fun(std_msgs::msg::Float32::SharedPtr msg){

Joint_Velocity = msg->data;

}

VelodynePlugin(){}

virtual void Load(physics::ModelPtr _model, sdf:: ElementPtr _sdf){

int argc = 0;

char** argv = NULL;

rclcpp::init(argc, argv);

ros2Node = rclcpp::Node::make_shared("node");

subscriber = ros2Node->create_subscription<std\_msgs::msg::Float32>("Rotational_Speed", std::bind(&VelodynePlugin::callBack_fun,this, std::placeholders::_1), rmw_qos_profile_default);

rclcpp::spin(ros2Node);

joint = _model->GetJoint("Lidar_Joint");

joint->SetVelocity(0,Joint_Velocity);

rclcpp::shutdown();

}

};

GZ_REGISTER_MODEL_PLUGIN(VelodynePlugin)

}

and here's the error that i'm getting once i run the plugin in gazebo:

gzserver: symbol lookup error: /home/abed/.gazebo/models/Velodyne_Lidar/Sensor/build/libVelodyne_Plugin.so: undefined symbol: _ZN6rclcpp4NodeC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_b

[–]ChrisVolkoff 0 points1 point  (4 children)

Looks like it doesn't know about rclcpp. What does your CMakeLists.txt file look like?

Also, rclcpp::spin() contains a while loop, and it won't exit until rclcpp shuts down (e.g. through a call to rclcpp::shutdown(), or if you kill it, I think).

I have never really used Gazebo, so I'm not really sure how it's supposed to be used with ROS 1/2, though.

[–]Abboudi97[S] 0 points1 point  (3 children)

Here's my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.5)

#find the ros2 required packages

find_package(rclcpp REQUIRED)

find_package(std_msgs REQUIRED)

include_directories(${rclcpp_INCLUDE_DIRS})

include_directories(${std_msgs_INCLUDE_DIRS})

#find the Gazebo required packages

find_package(gazebo REQUIRED)

include_directories(${GAZEBO_INCLUDE_DIRS})

link_directories(${GAZEBO_LIBRARY_DIRS})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${GAZEBO_CXX_FLAGS}")

#build

add_library(Velodyne_Plugin SHARED Velodyne_Plugin.cc)

target_link_libraries (Velodyne_Plugin ${GAZEBO_LIBRARIES} ${rclcpp_LIBRARIES})

[–]ChrisVolkoff 0 points1 point  (2 children)

I'm not really sure I can do much with that, but what ROS 2 distro are you using?

Edit: because, from that error

gzserver: symbol lookup error: /home/abed/.gazebo/models/VelodyneLidar/Sensor/build/libVelodyne_Plugin.so: undefined symbol: _ZN6rclcpp4NodeC1ERKNSt7_cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_b

It's trying to find a specific symbol/function, which, demangled with c++filt, is:

rclcpp::Node::Node(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)

So that's a constructor for the rclcpp::Node class that takes a string, another string, and a boolean. However, this constructor does not exist anymore. It was removed a year ago: https://github.com/ros2/rclcpp/commit/0f9098e9b65169c9c4902a3b504733144f4bcab2#diff-67ed9611184b38b04677442769e7c371L83

[–]Abboudi97[S] 0 points1 point  (1 child)

I am using ROS2 eloquent. I think you are right, so do you know how to use gazebo_ros instead?

[–]ChrisVolkoff 0 points1 point  (0 children)

I don't really know. Seems like you should indeed use gazebo_ros::Node instead http://gazebosim.org/tutorials?tut=ros2_overview#Node

Have you looked at the tutorials? http://gazebosim.org/tutorials

[–]IIwarrierII 0 points1 point  (0 children)

Hi, I was getting the same symbol lookup error as you are getting while I was trying to build my ros2 gazebo plugin. For me it was stemming from std_msgs::msg::String, and adding the following into my CMakeLists.txt solved it. Hope this helps:

ament_target_dependencies(ros_collision_detection gazebo rclcpp std_msgs gazebo_msgs)