subscriber callback not running (c++)
so I've been stuck on this for a while now and have come to realize that the issue with my code is that for some reason the callback function for my subscriber never seems to run and I can't understand why for the life of me.
I'm using 3 files to run my code in order to make sure that in the future everything will be as modular as possible and I can simply swap 1 or 2 lines in my main function file to make my turtlebot do different things based on the functions in the function file.
To make sure the callback was running I added a cout << "test" << endl;
to the function just to see if anything prints, and it doesn't. So I assume that's where my major problem lies.
Any help would be greatly appreciated.
The files are:
mainfunction.cpp
#include <iostream>
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <std_msgs/Empty.h>
#include "TurtleFunction.cpp"
#include "TurtleFunction.h"
#include <sstream>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;
int main(int argc, char** argv){
// Initialize ROS
ros::init(argc, argv, "test3");
ros::NodeHandle nh;
// Define Global Variables for use
cmd_pub = nh.advertise<geometry_msgs::Twist>("/cmd_vel_mux/input/teleop", 50);
reset_pub = nh.advertise<std_msgs::Empty>("/mobile_base/commands/reset_odometry", 1);
OdomSub = nh.subscribe<nav_msgs::Odometry>("/odom",50,processodom);
resetOdom(); // Reset the Odometry of the Turtlebot
ros::Rate r(50);
ros::spinOnce();
// Define Initial Velocity Variables for TurtleBot
double v = 0.1;
double theta = 0.01;
int i = 0;
/*
* Begin Infinite Loop.
* First Function is our method of identifying other TurtleBots (if applicable)
* Second Function is our chosen Control Law (if applicable)
* Third Function is how we drive the TurtleBot
*/
while(ros::ok()){
UnicycleModel();
cout << "this is working" << i << endl;
i++;
ros::spinOnce();
}
return 0;
}
The function file:
TurtleFunction.cpp
#include <iostream>
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <std_msgs/Empty.h>
#include "TurtleFunction.h"
#include <sstream>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;
/*
* The Movement Function allows us to test that our Turtlebot can be controlled usings a
* separate function file. It's also the "block" we use to make the movement modules for the
* Turtlebot (i.e.- Unicycle Model or Feedback Linearization) work.
* It takes three (3) inputs;
* 1) the ros::Publisher that we will use to publish to the Turtlebot
* 2) the desired linear velocity
* 3) the desired rotational velocity
* Using these three (3) inputs, it publishes a command to the Turtlebot telling it how to move
*/
void Movement(double v,double theta){
// geometry_msgs::Twist cmd_msg;
cmd_msg.linear.x = v;
cout << "v = " << cmd_msg.linear.x << endl;
cmd_msg.angular.z = theta;
cout << "theta = " << cmd_msg.angular.z << endl;
cmd_pub.publish(cmd_msg); //send
ros::spinOnce();
}
/*
* The Unicycle Model is the classic model used for describing the dynamics
* of the Turtlebot. The Unicycle Model Function allows us to find the desired linear velocity
* and rotational velocity which we can ...