Publisher is not publishing what can I do?

asked 2017-08-31 14:22:47 -0500

Frdrckzn gravatar image

updated 2017-08-31 14:23:44 -0500

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)
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;;
  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())

  return 0;

edit retag flag offensive close merge delete


the terminal doesnt send me an error, but i dont get the value in the topic

Frdrckzn gravatar image Frdrckzn  ( 2017-08-31 14:24:59 -0500 )edit

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.

ufr3c_tjc gravatar image ufr3c_tjc  ( 2017-08-31 17:58:25 -0500 )edit

Also, what is sleep (5); referring to? Where is the sleep function defined?

ufr3c_tjc gravatar image ufr3c_tjc  ( 2017-08-31 18:00:02 -0500 )edit

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

Frdrckzn gravatar image Frdrckzn  ( 2017-09-01 17:26:05 -0500 )edit

Few things here. Firstly, sleep(5); isn't scoped to anything, and I can't see where it would be coming from. Use ros::Duration(5).sleep(); instead, which is the proper ROS way to sleep. Secondly, are the topics being advertised? IE, do they show up using rostopic list? If so, it is a ...

ufr3c_tjc gravatar image ufr3c_tjc  ( 2017-09-03 18:17:52 -0500 )edit

problem with your callback functions. IE, one of the lines; or motors.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 the motors.initGPIO lines. Also, where are your ...

ufr3c_tjc gravatar image ufr3c_tjc  ( 2017-09-03 18:19:56 -0500 )edit

ROS-related include lines? You'll need ros/ros.h and std_msgs/Float64.h at a minimum for this to compile? Or did you put them into motor.h?

ufr3c_tjc gravatar image ufr3c_tjc  ( 2017-09-03 18:21:53 -0500 )edit

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); for ros::Duration(5).sleep();

Frdrckzn gravatar image Frdrckzn  ( 2017-09-03 19:36:08 -0500 )edit