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

Revision history [back]

You could:

  1. Declare member variables, say goalX, goalY, robotX, and robotY.
  2. In the callbacks, store the values in the appropriate variables.
  3. When you want to calculate the angle, just do atan2(goalY - robotY, goalX - robotX).

As for your question regarding guaranteeing that you are working with the most recent data, every time ROS does a spin, it process all the callbacks sequentially, so your loop goes like this:

while(ros::ok())
{
  ros::spinOnce(); // Callbacks are processed here

  double angle = ::atan2(goalY - robotY, goalX - robotX);
  ...
}

You could:

  1. Declare member variables, say goalX, goalY, robotX, and robotY.
  2. In the callbacks, store the values in the appropriate variables.
  3. When you want to calculate the angle, just do atan2(goalY - robotY, goalX - robotX).

As for your question regarding guaranteeing that you are working with the most recent data, every time ROS does a spin, it process processes all the callbacks sequentially, so your loop goes like this:

while(ros::ok())
{
  ros::spinOnce(); // Callbacks are processed here

  double angle = ::atan2(goalY - robotY, goalX - robotX);
  ...
}

You could:

  1. Declare member variables, say goalX, goalY, robotX, and robotY.
  2. In the callbacks, store the values in the appropriate variables.
  3. When you want to calculate the angle, just do atan2(goalY - robotY, goalX - robotX).robotX).

As for your question regarding guaranteeing that you are working with the most recent data, every time ROS does a spin, it processes all the callbacks sequentially, so your loop goes like this:

while(ros::ok())
{
  ros::spinOnce(); // Callbacks are processed here

  double angle = ::atan2(goalY - robotY, goalX - robotX);
  ...
}