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

slim71's profile - activity

2023-09-05 08:37:56 -0500 received badge  Famous Question (source)
2023-08-16 04:17:40 -0500 received badge  Famous Question (source)
2023-08-15 15:27:24 -0500 received badge  Notable Question (source)
2023-08-12 04:39:44 -0500 received badge  Popular Question (source)
2023-08-11 15:20:09 -0500 marked best answer [ROS2] Testing launch of Node

I've been trying to write some tests for my package, but with not much success until now...

I have a "PelicanUnit" node and in its constructor I require a path to a .sdf model: if that's not given, everything shuts down with a std::runtime_error. Now, using colcon test and Google Test, I've been trying to write sort of like smoketests for successful and unsuccessful launches. The failing case has been a little tricky, but in the end I've managed with this:

TEST(SmokeTests, ParseModelFailing) {
     // Initialize RCLCPP
     rclcpp::init(0, nullptr);
     EXPECT_THROW(
         {
             try {
                 PelicanUnit pelican;
             } catch (const std::exception& e) {
                 EXPECT_STREQ("Agent model could not be parsed!", e.what());
                 throw; // Re-throw the exception for Google Test to catch
             }
         }, 
         std::runtime_error);
     // Shutdown RCLCPP
     rclcpp::shutdown(); 
}

Unfortunately, I cannot find a way for the other test.

Up until now I've tried:

  • launching the node from the test itself but I could not pass the config file I normally use with the standard launch file

    TEST(SmokeTests, Main) {
        // Useless, since the node itself does not parse arguments (?)
        char  arg0[] = "--params-file";
        char  arg1[] = "src/pelican/config/copter1.yaml"; // TODO: use package share directory
        char* argv[] = { &arg0[0], &arg1[0], NULL };
        int   argc   = (int)(sizeof(argv) / sizeof(argv[0])) - 1;
    
        // Initialization
        rclcpp::init(argc, argv);
    
        // Instantiation
        rclcpp::Node::SharedPtr node = std::make_shared<PelicanUnit>();
        rclcpp::executors::MultiThreadedExecutor executor;
    
        executor.add_node(node);
        executor.spin();
    
        rclcpp::shutdown();
    }
    
  • using a test launch_file, which has been somewhat almost good, but the config file used has not been found and, most importantly, I'm not sure I can use this as a proper test. I can only test that the command is launched, not that the node itself fires up smoothly...

    TEST(SmokeTests, NodeStartingCorrectly) {
        // Set the launch file path and arguments
        const std::string pwd = "source ";
        const std::string launch_command = "ros2 launch pelican test_launch.launch.py";
    
        // Run the launch command and check its exit status
        std::system(pwd.c_str());
        int exit_status = std::system(launch_command.c_str());
        ASSERT_EQ(exit_status, 0);
    }
    

(launch file)

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from launch.substitutions import PathJoinSubstitution, ThisLaunchFileDir


def generate_launch_description():
    config_pkg_share = FindPackageShare('pelican')
    config_middleware = 'config/'

    ld =  LaunchDescription()

    config_file = 'copter1.yaml'

    node = Node(
            package='pelican',
            executable='pelican_unit',
            ros_arguments=['--params-file', 
                           PathJoinSubstitution([config_pkg_share, config_middleware, config_file])]
        )

    ld.add_action(node)

    return ld

Is there anyone that can provide some assistance or suggestions for this? Thank you!

2023-08-11 15:20:04 -0500 answered a question [ROS2] Testing launch of Node

In the end I've managed to do it like this: TEST(SmokeTests, NodeStartingCorrectly) { char arg0[] = "--ros-args";

2023-08-08 16:14:11 -0500 asked a question [ROS2] Testing launch of Node

[ROS2] Testing launch of Node I've been trying to write some tests for my package, but with not much success until now..

2023-07-20 11:49:20 -0500 received badge  Notable Question (source)
2023-07-20 08:18:35 -0500 marked best answer [ROS2] Close all threads when using CTRL-C

Hi all! In my project I'm spawning a thread which contains a while loop, simply like so:

std::thread worker([this]() { this->ballotCheckingThread(); });
std::unique_lock<std::mutex> lock(this->candidate_mutex_);

where the thread code is like this

void ballotCheckingThread() {
    while (!this->checkVotingCompleted() && !this->checkForExternalLeader()) {
        // Simulate some delay between checks
        std::this_thread::sleep_for(std::chrono::milliseconds(200));
    }

    // Notify the first thread to stop waiting
    cv.notify_all();
}

Unfortunately, when I use CTRL-C to terminate the node, this thread remains hanging and I have to manually kill it.

Right now in the main function I'm doing this:

int main(int argc, char *argv[]) {
    std::cout << "Starting  node..." << std::endl;
    setvbuf(stdout, NULL, _IONBF, BUFSIZ);
    rclcpp::init(argc, argv);

    rclcpp::Node::SharedPtr node = std::make_shared<myNode>();
    rclcpp::executors::MultiThreadedExecutor executor;
    executor.add_node(node);

    try {
        executor.spin();
    } catch (std::exception& e) {
        std::cout << "rclcpp shutting down..." << std::endl;
        rclcpp::shutdown();
        return 0;
    }

}

but I guess that's not enough. Is there a standard way to do this?

2023-07-20 02:21:34 -0500 answered a question [ROS2] Close all threads when using CTRL-C

In the end, I've found a solution. Using a global variable std::weak_ptr<MyNode> MyNode::instance_;, I've initiali

2023-07-19 02:59:07 -0500 received badge  Popular Question (source)
2023-07-18 16:04:23 -0500 answered a question I'm confused with callback_groups and threads

Are you actually using rclpy.spin() in the spawned thread? If I'm getting this right, in the spawned thread you're tryin

2023-07-18 16:04:23 -0500 received badge  Rapid Responder (source)
2023-07-17 12:51:33 -0500 asked a question [ROS2] Close all threads when using CTRL-C

[ROS2] Close all threads when using CTRL-C Hi all! In my project I'm spawning a thread which contains a while loop, simp

2023-07-04 15:29:50 -0500 received badge  Popular Question (source)
2023-07-03 15:03:32 -0500 edited question Use system time as default for a node's clock

Use system time as default for a node's clock Hi all. I was reviewing stuff about nodes' Clock and Time in general, to

2023-07-03 14:55:22 -0500 edited question Use system time as default for a node's clock

Use system time as default for a node's clock Hi all. I was reviewing stuff about nodes' Clock and Time in general, to

2023-07-03 14:55:22 -0500 received badge  Editor (source)
2023-07-03 14:51:32 -0500 asked a question Use system time as default for a node's clock

Use system time as default for a node's clock Hi all. I was reviewing stuff about nodes' Clock and Time in general, to

2023-06-03 22:08:13 -0500 received badge  Notable Question (source)
2023-05-20 07:25:08 -0500 marked best answer ROS2 on Windows with NVidia GPU

Hi everyone! I'm trying to understand the best way to setup my environment for ROS2+Gazebo.

Up until now I was using an Ubuntu 22.04 VM with Virtualbox to get simple exercises up and running in ROS2, with no major problem. Since I have to go up a step and start a more complex system, plus I'll need Gazebo for simulations, I thought about how to improve the environment, given that there is always some kind of performance issue using VMs. It seems my options are:

  • dual boot
  • Docker
  • Git Bash from CMD, as if I was actually on Unix

Since for simplicity of use, budget (can't get another laptop) and resources (my laptop's SDD is not that big) the dual boot is not an option, I moved to Docker. I set up the container (osrf/ros), I installed XLaunch for the GUI and successfully integrated Docker with WSL2. Everything following this guide

However, I can't seem to use my Nvidia graphic card. I've tried launching the turtlesim node + teleop, but it's laggy and slow and Task Manager does not show the process as executing with the Nvidia card.

Has anyone managed to successfully setup a similar environment? Or is there any other option that is actually better than this?

Thanks in advance!

2023-05-20 06:31:24 -0500 received badge  Popular Question (source)
2023-05-20 05:26:38 -0500 answered a question ROS2 on Windows with NVidia GPU

To anybody interested, I gave up. Getting everything set up on Windows is such a pain, and gives no benefits. I've fo

2023-05-15 01:39:07 -0500 received badge  Famous Question (source)
2023-05-14 02:25:07 -0500 received badge  Enthusiast
2023-05-13 10:04:09 -0500 commented answer [URDF] What is a dummy link needed for?

it wasn't the main topic here, but in case someone needing this comes here: I've found out that the diff_drive plugin

2023-05-13 05:33:00 -0500 received badge  Supporter (source)
2023-05-13 05:32:55 -0500 marked best answer [URDF] What is a dummy link needed for?

Hi,

I'm trying to learn as bet as possible ROS2, Gazebo and of course SDF and URDF files. I'm currently following some tutorials (a bit troublesome, given the different version of Gazebo/Ignition and the confusion about the name) on how to build robot models.

I've seen that often URDF models have a dummy link (almost always called base_link) which is empty and does nothing more than provide a "mounting point" of the robot to the world/ground, so to speak.

I'm failing to understand when and why this is needed, and I think this is giving me issues for the test model I'm building. Could someone please let me in on this?

Thanks! :D

EDIT: an example of what I'm referencing:

<link name="dummy"/>  
<joint name="dummy_to_base_link=" type="fixed">  
    <parent link="dummy"/>  
     <child link="base_link"/>  
< /joint>
2023-05-13 05:32:55 -0500 received badge  Scholar (source)
2023-05-13 05:32:53 -0500 commented answer [URDF] What is a dummy link needed for?

Airght, I've reviewed what you linked in your edit and it is clearer to me now. Now then, I only have to figure out why

2023-05-13 02:50:32 -0500 commented answer [URDF] What is a dummy link needed for?

OK, so in general: the dummy link is to avoid the warning (or for other purposes) the base_link is the first link of

2023-05-13 02:49:12 -0500 commented answer [URDF] What is a dummy link needed for?

OK, so in general: - the dummy link is to avoid the warning (or for other purposes) - the base_link is the first link

2023-05-13 01:27:00 -0500 received badge  Notable Question (source)
2023-05-12 16:18:57 -0500 received badge  Popular Question (source)
2023-05-12 14:47:19 -0500 edited question [URDF] What is a dummy link needed for?

[URDF] What is a dummy link needed for? Hi, I'm trying to learn as bet as possible ROS2, Gazebo and of course SDF and U

2023-05-12 13:02:18 -0500 asked a question [URDF] What is a dummy link needed for?

[URDF] What is a dummy link needed for? Hi, I'm trying to learn as bet as possible ROS2, Gazebo and of course SDF and U

2023-04-23 06:52:48 -0500 asked a question ROS2 on Windows with NVidia GPU

ROS2 on Windows with NVidia GPU Hi everyone! I'm trying to understand the best way to setup my environment for ROS2+Gaze