Ask Your Question
0

servo controller publisher

asked 2016-05-03 17:25:00 -0500

Emilien gravatar image

updated 2016-05-04 02:46:59 -0500

gvdhoorn gravatar image

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;
    }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-05-04 04:36:53 -0500

mgruhler gravatar image

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.

edit flag offensive delete link more

Comments

thank you very much

Emilien gravatar image Emilien  ( 2016-05-04 05:03:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-03 17:25:00 -0500

Seen: 88 times

Last updated: May 04 '16