Custom Nodes not publishing or subscribing, why?
Hi all,
I'm writing a couple simple nodes that should work (they build without errors), but when launched rxgraph and rosnode don't show any publish or subscribe topics from those nodes.
I'm hoping someone can point me in the right direction. I've included one of the nodes below:
edit: updated joy_to_point.cpp per K_Yousif. edit: solution from K_Yousif resolves the issue
joy_to_point.h
#include <ros/ros.h>
#include <ros/node_handle.h>
#include <sensor_msgs/Joy.h>
#include <husky_seeg/XYPoint.h>
class JoyToPoint {
private:
// Node Handler
ros::NodeHandle nh;
// Subscribers
ros::Subscriber joySub;
// Publishers
ros::Publisher pointPub;
// Parameters
double rangeAtMax;
// Messages
sensor_msgs::Joy joy;
husky_seeg::XYPoint point;
public:
JoyToPoint(ros::NodeHandle nh_);
~JoyToPoint(){}
// Callbacks
void joyCallback( const sensor_msgs::Joy::ConstPtr& j );
};
joy_to_point.cpp
#include "joy_to_point.h"
JoyToPoint::JoyToPoint(ros::NodeHandle nh_) : nh(nh_) {
// Resolve topic names
std::string joy_topic = ros::names::clean(nh.resolveName("/joy"));
ROS_DEBUG("Subscribing to:\n\t* %s", joy_topic.c_str());
// Subscribe to input topics.
joySub = nh.subscribe(joy_topic, 1, &JoyToPoint::joyCallback, this);
// Get Parameters
ros::NodeHandle local_nh("~");
local_nh.param<double>( "range_at_max", rangeAtMax, 1 );
// Advertise publisher
pointPub = nh.advertise<husky_seeg::XYPoint>("/XYPoint", 1);
}
void JoyToPoint::joyCallback( const sensor_msgs::Joy::ConstPtr& j ) {
// Convert Joystick message to a virtual point
point.x = joy.axes[1] * rangeAtMax;
point.y = joy.axes[0] * rangeAtMax;
pointPub.publish(point);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "joy_to_point");
ros::NodeHandle nh;
JoyToPoint point(nh);
ros::spin();
return 0;
}