how to have subs and publisher in one single cpp
i see some posts about writting the subs and publi in on cpp, but for my code, I will subs some points position from the camera and publish it with 10*those coordinate how do i do that ? (Say my ps4->pose.position.x is 10, i want to have a topic called "positions" which will publish this coordinate to be 100)please help
#include "ros/ros.h"
#include <math.h>
#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include "geometry_msgs/PoseStamped.h"
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/PoseWithCovariance.h"
#include <visp/vpDisplayGDI.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDot2.h>
#include <visp/vpImageIo.h>
#include <visp/vpPixelMeterConversion.h>
#include <visp/vpPose.h>
using namespace std;
using namespace cv;
void imageCallback(const geometry_msgs::PoseStamped::ConstPtr& ps4){
cout<<"pose is"<<ps4->pose.position<<endl;
//ps_cov->publish(ps);
}
int main(int argc, char **argv){
geometry_msgs::PoseStamped my_vidoe2;
ros::init(argc, argv, "coordinator");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe<geometry_msgs::PoseStamped>("/visp_auto_tracker/object_position", 1000, imageCallback);
ros::Publisher positions_pub = n.advertise<geometry_msgs::PoseStamped>("positions", 1000);
ros::Rate loop_rate(30);
int count=0;
while (ros::ok())
{
double x;
geometry_msgs::PoseStamped msg;
ros::spinOnce();
loop_rate.sleep();
++count;
}
i know this is a partial code, please help~~ i am new to ros, please explain in details, thanks ~