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

dj95's profile - activity

2023-02-24 04:29:28 -0500 received badge  Nice Question (source)
2022-02-25 04:12:57 -0500 marked best answer How to use data from a callback function in another function

I'm trying to take the x, y, and yaw value from the callback function and use them in a different function. Although when I run the code I have below, all the variables below return a value of 0. From my thought process, I think the global variables should be accessible for the void move() function as well, which doesn't seem to be the case.

Can someone tell what's wrong?

#include "ros/ros.h"
#include "turtlesim/Pose.h"
#include "geometry_msgs/Twist.h"

float x = 0, y = 0, yaw = 0 ;

void callback(const turtlesim::Pose::ConstPtr& msg)
{
    x = msg->x;
    y = msg->y;
    yaw = msg->theta;

}

void move()
{
    while (ros::ok())
    {
        ROS_INFO("x: [%f], y: [%f], yaw: [%f]", x, y, yaw);
    }
}

    int main(int argc, char **argv)
    {
        ros::init(argc, argv, "pose");
        ros::NodeHandle n;
        ros::Subscriber sub = n.subscribe("/turtle1/pose", 1000, callback);
        move();
        ros::spin();
}
2021-09-10 13:09:37 -0500 received badge  Famous Question (source)
2021-09-10 13:09:37 -0500 received badge  Notable Question (source)
2021-09-10 13:09:37 -0500 received badge  Popular Question (source)
2021-05-02 21:13:12 -0500 received badge  Notable Question (source)
2021-05-02 21:13:12 -0500 received badge  Popular Question (source)
2020-07-13 23:39:24 -0500 received badge  Famous Question (source)
2020-07-08 10:20:29 -0500 commented question How to compile the Connext DDS with ROS2

Is compiling ROS2 same as building ros workspace (colcon build)?

2020-07-07 13:55:18 -0500 edited question rmw_dps install and run

rmw_dps install and run Hi, I'm trying to learn more about Intel's Distributed Publish & Subscribe for IoT (DPS). (h

2020-07-07 13:55:18 -0500 received badge  Editor (source)
2020-07-07 13:54:45 -0500 asked a question rmw_dps install and run

rmw_dps install and run Hi, I'm trying to learn more about Intel's Distributed Publish & Subscribe for IoT (DPS). (h

2020-06-04 21:25:42 -0500 received badge  Famous Question (source)
2020-06-04 21:25:42 -0500 received badge  Notable Question (source)
2020-06-04 21:25:42 -0500 received badge  Popular Question (source)
2020-06-03 13:55:07 -0500 received badge  Famous Question (source)
2020-05-07 16:02:48 -0500 asked a question tf_remapper

tf_remapper Hi, I'm trying to using tf_remap (http://wiki.ros.org/tf) I followed the documentation, but I'm struggling

2020-05-07 15:39:00 -0500 commented answer How to use tf_remap??

Can tf_remap be used without using bag files?

2020-04-29 11:57:23 -0500 received badge  Student (source)
2020-04-28 10:33:50 -0500 commented answer catkin_make command not found executing by a dockerfile

What does && rm -rf /var/lib/apt/lists/* do? Why is it required?

2020-04-28 10:33:40 -0500 commented answer catkin_make command not found executing by a dockerfile

What does && rm -rf /var/lib/apt/lists/* do? Why is required?

2020-04-28 10:33:20 -0500 commented answer catkin_make command not found executing by a dockerfile

What does && rm -rf /var/lib/apt/lists/* do?

2020-04-28 10:10:54 -0500 commented question catkin_make command not found executing by a dockerfile

Hello, I'm a beginner trying to understand Docker. Could someone explain what does replacing shell with bash actually do

2020-04-22 12:12:47 -0500 received badge  Notable Question (source)
2020-04-15 09:59:49 -0500 received badge  Notable Question (source)
2020-04-15 09:59:49 -0500 received badge  Popular Question (source)
2020-04-03 07:09:02 -0500 received badge  Popular Question (source)
2020-04-01 09:22:18 -0500 asked a question Can I add apriltag as an obstacle in my cost map for path planning?

Can I add apriltag as an obstacle in my cost map for path planning? I've a robot which is attached with a camera which c

2020-03-31 18:46:49 -0500 asked a question How to perform basic path planning?

How to perform basic path planning? Hi, I've a robot which is attached with a camera which can detect and mark apriltag

2020-03-16 16:00:17 -0500 received badge  Popular Question (source)
2020-03-13 04:34:17 -0500 received badge  Popular Question (source)
2020-03-11 10:10:12 -0500 marked best answer VS code can't find the headerfiles even when workspace compiles without error

Hi,

I've been having this error where the squiggles in vscode don't go away when I try to include headerfiles for custom messages and services. I am able to compile my workspace, I can see the header file for the service created (with response.h and request.h), I can do rossrv show __________ to see the content of my header files as well. It's just that I can't get rid of the red squiggle because of which I can't use autocomplete.

Does anyone know what can I do?

2020-03-11 10:08:15 -0500 commented answer Publishing to a topic via subscriber callback function

Thanks Martin!

2020-03-11 10:04:38 -0500 commented answer VS code can't find the headerfiles even when workspace compiles without error

This looks great, Thanks.

2020-03-10 10:20:27 -0500 commented answer VS code can't find the headerfiles even when workspace compiles without error

I have that extension already, still doesn't get the header files. Btw, do you know if adding these lines to my CMakelis

2020-03-10 10:20:16 -0500 commented answer VS code can't find the headerfiles even when workspace compiles without error

I have that extension already, still doesn't get the header files. Btw, do you know if adding these lines to my CMakelis

2020-03-10 10:19:36 -0500 commented answer VS code can't find the headerfiles even when workspace compiles without error

I have that extension already, still doesn't get the header files. Btw, do you know if adding these lines to my CMakelis

2020-03-09 14:20:07 -0500 commented answer VS code can't find the headerfiles even when workspace compiles without error

Okay, I'll have a look, Thanks!

2020-03-09 14:19:55 -0500 commented answer VS code can't find the headerfiles even when workspace compiles without error

Okay, I'll have a look

2020-03-09 14:19:55 -0500 received badge  Commentator
2020-03-09 10:46:34 -0500 asked a question VS code can't find the headerfiles even when workspace compiles without error

VS code can't find the headerfiles even when workspace compiles without error Hi, I've been having this error where the

2020-03-06 12:35:28 -0500 commented answer Publishing to a topic via subscriber callback function

Is there a particular nomenclature for having trailing underscores in variable name definition? (pub_,sub_,n_)

2020-03-05 08:59:38 -0500 commented answer AprilTag detection using ROS

You actually have to define tags for them to be detected, If you don't specify the id and size it wouldn't know what to