0
$\begingroup$

Rosanswers logo

hi, i create a subscribe sevo controller like this tutorial wiki/rosserial_arduino/Tutorials/Servo Controller and i want to create a publisher on my PC. i try with this code, but it doesnt work. could you help me please?

  int main(int argc, char **argv)
    {
        ros::init(argc, argv, "servo_publisher");
        ros::NodeHandle n;
        ros::Publisher servo_pub = n.advertise<std_msgs::UInt16>("servo", 1000);
        ros::Rate loop_rate(10);
        int count = 0;
        while(ros::ok())
        {
            std_msgs::UInt16 cmd_msg;
            cmd_msg.data = 10;
            ROS_INFO("%i",cmd_msg.data);
            servo_pub.publish(cmd_msg);
            ros::spin();
            loop_rate.sleep();
            ++count;
        }
        return 0;
    }

Originally posted by Emilien on ROS Answers with karma: 167 on 2016-05-03

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

This should be a ros::spinOnce(); instead of ros::spin();

ros::spin() is spinning continuously and thus you should only receive the very first message.

Check out the wiki for more info.


Originally posted by mgruhler with karma: 12390 on 2016-05-04

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Emilien on 2016-05-04:
thank you very much

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.