while loop not updating global variable in cpp
hello everyone,
so i came across while loop not updating global variable in cpp
#include "ros/ros.h"
#include "std_msgs/Int32.h"
#include <fstream>
#include <iostream>
int op1;
int start= 0;
int right;
void rightCB(const std_msgs::Int32::ConstPtr& msg)
{
right=msg->data;
ROS_INFO("position of wheel1:[%d]",right);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "encoder");
ros::NodeHandle n;
ros::Subscriber enc = n.subscribe<std_msgs::Int32>("/right", 1000,&rightCB);
while (ros::ok())
{
if(start == 0)
{
int distx = op1 + 100;
ROS_INFO("Distance range:[%d]",distx);
while(ros::ok())
{
ROS_INFO("position of wheel1:[%d]",right);
}
}
ros::spinOnce();
}
ros::spin();
return 0;
}