Publisher is not publishing what can I do?
Hi guys im trying to publish in the setpoint topic. When I do the rostopic echo /setpoint I get nothing not eaven the first value i tried everything yo yo know what can i do?
Note: motor.h has all the libraries that I need
#include "motor.h"
#define TIMER 0.1
#define ACCELERATION 75.0
MotorCluster motors(ACCELERATION, TIMER);
void ControlEffortCallback(const std_msgs::Float64& control_effort_input)
{
control_effort=control_effort_input.data;
}
void motorPWM_callback(const geometry_msgs::Vector3::ConstPtr& msg)
{
motors.moveRobot(msg->x, msg->y, msg->z);
}
int main (int argc, char** argv)
{
ros::init(argc, argv, "motorPWM_node");
ros::NodeHandle motorPWM_node;
motors.initGPIO(m_camera, 1, 0);
motors.initGPIO(m_left, 2, 3);
motors.initGPIO(m_right, 4, 5);
ros::Timer tmrMotor = motorPWM_node.createTimer(ros::Duration(TIMER), &MotorCluster::reportStat, &motors);
ros::Subscriber motorPWM_sub = motorPWM_node.subscribe("moveRobot", 10, motorPWM_callback);
//For the PID
ros::Subscriber conteff_sub=motorPWM_node.subscribe("control_effort",1, ControlEffortCallback);
std_msgs::Float64 setpoint;
setpoint.data=0.5;
std_msgs::Float64 state;
std_msgs::Float64 pid_enable;
ros::Publisher setpoint_pub= motorPWM_node.advertise<std_msgs::Float64>("setpoint", 1);
ros::Publisher state_pub= motorPWM_node.advertise<std_msgs::Float64>("state", 1);
ros::Publisher pid_enable_pub= motorPWM_node.advertise<std_msgs::Float64>("pid_enable", 1);
sleep (5);
ROS_LOG(ros::console::levels::Info, ROSCONSOLE_DEFAULT_NAME, "[MOT] Node initialized");
ros::Rate loop_rate(0.5);
while (ros::ok())
{
ros::spinOnce();
setpoint_pub.publish(setpoint);
setpoint.data=3.0;
setpoint_pub.publish(setpoint);
state_pub.publish(state);
pid_enable_pub.publish(pid_enable);
loop_rate.sleep();
}
return 0;
}
the terminal doesnt send me an error, but i dont get the value in the topic
Do the other topics publish? There's a chance that one of your callback functions is blocking and therefore ros::spinOnce() is not returning, so the topics aren't being published at all. But if the state and pid are publishing, just not the setpoint, then that may be harder to solve.
Also, what is
sleep (5);
referring to? Where is the sleep function defined?None of the topics are publishing. I used the sleep for waiting 5 seconds because I wanted to give time for the publishers to set, before I start pusblishing data
Tanks for your replay
Few things here. Firstly,
sleep(5);
isn't scoped to anything, and I can't see where it would be coming from. Useros::Duration(5).sleep();
instead, which is the proper ROS way to sleep. Secondly, are the topics being advertised? IE, do they show up usingrostopic list
? If so, it is a ...problem with your callback functions. IE, one of the lines
control_effort=control_effort_input.data;
ormotors.moveRobot(msg->x, msg->y, msg->z);
is blocking and not returning. If they don't show up at all, it is a problem with one of themotors.initGPIO
lines. Also, where are your ...ROS-related include lines? You'll need
ros/ros.h
andstd_msgs/Float64.h
at a minimum for this to compile? Or did you put them intomotor.h
?All of the include lines are in motor.h and yes all the topics are advertised if the problem is related to my callback functions what can i do? Thanks again and i will change the
sleep(5);
forros::Duration(5).sleep();