Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:59:37+00:00 2026-06-09T19:59:37+00:00

I have code to define behavior of a position model set in a world

  • 0

I have code to define behavior of a position model set in a world file for stageros. I want to keep track of it’s current position in the world in the variables px py and ptheta by subscribing to the odom topic for Odometry messages sent by stageros. Like this:

ros::Subscriber RobotOdometry_sub = n.subscribe<nav_msgs::Odometry>("robot_0/odom",1000,&Robot::ReceiveOdometry,this);

Which is put in the constructor for a Robot object. Then the callback is as follows:

void Robot::ReceiveOdometry(nav_msgs::Odometry msg)
{
    //This is the call back function to process odometry messages coming from Stage.
    px = initialX + msg.pose.pose.position.x;
    py = initialY + msg.pose.pose.position.y;
    ptheta = angles::normalize_angle_positive(asin(msg.pose.pose.orientation.z) * 2);
    ROS_INFO("x odom %f y odom %f theta %f", px, py, ptheta);
}

This callback seems to get called no problem. The px, py and ptheta values printed by the callback are all correct as well and correspond with their current position in the world. The problem occurs in other functions:

void Robot::OtherFunction() {
    while (ros::ok())
    {
        ros::spinOnce();
        ROS_INFO("x %f y %f theta %f", px, py, ptheta);
    }
}

This is just an example, but for some reason the px, py and ptheta values printed from another function always seem to be stuck at the initial px, py and ptheta values. Even though the ReceiveOdometry callback is continuously printing the right values as well. The px, py, ptheta values are different as if there are two different values for each variable.

ROS_INFO from ReceiveOdometry prints the current position correctly.

ROS_INFO from OtherFunction prints the initial positions and doesn’t change at all even though px, py and ptheta are continuously being set in ReceiveOdometry.

Does anyone know what is causing the changes to px, py and ptheta in the ReceiveOdometry callback not to carry over to the OtherFunction? Hopefully this question makes sense.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:59:39+00:00Added an answer on June 9, 2026 at 7:59 pm

    Print and check this in both functions. You shall be using two different objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this (working) CPU code: #define NF 3 int ND; typedef double (*POT)(double
I have the following code snippet: #ifdef DO_LOG #define log(p) record(p) #else #define log(p)
i have the following piece of code in php: define('QUERY', $some_query_string); if(empty(QUERY) || mb_strlen(QUERY)
I have the following code: #include <iostream> #define BOOST_TEST_MODULE my test #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE(
I have the following code: #include <stdio.h> #include <pthread.h> #define THREAD_CNT 10 #define ITER
I have the following code: #include <stdlib.h> #include <stdio.h> #include <pthread.h> #define NUM_THREADS 100
I have some Objective-C code that looks like this: #define myVar 10 float f
I have a define: hashdefine kPingServerToSeeIfInternetIsOn http://10.0.0.8 then in code I with to use
if for example i have : #define PRINT(x) fprintf(stderr, x); and in code i
I created a UITextField in code, now I have now idea how to define

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.