0
$\begingroup$

Rosanswers logo

I'm using ros kinetic on ubuntu 16.04. I'm able to perform the hello world code from rosserial tutorials http://wiki.ros.org/rosserial_arduino/Tutorials/Hello%20World However not being able to operate the servo example. Any ideas? no error on Arduino IDE. After i perform the test on the terminal roscore rostopic pub servo std_msgs/UInt16 8

the terminal output:publishing and latching message. Press ctrl-C to terminate Nothing after that

/*
 * rosserial Servo Control Example

#if (ARDUINO >= 100)
 #include <Arduino.h>
#else
 #include <WProgram.h>

#endif

#include <Servo.h> 
#include <ros.h>
#include <std_msgs/UInt16.h>

ros::NodeHandle  nh;

Servo servo;

void servo_cb( const std_msgs::UInt16& cmd_msg){
  servo.write(cmd_msg.data); //set servo angle, should be from 0-180  
  digitalWrite(13, HIGH-digitalRead(13));  //toggle  led  
}


ros::Subscriber<std_msgs::UInt16> sub("servo", servo_cb);

void setup(){
pinMode(13, OUTPUT);

nh.initNode();

nh.subscribe(sub);
  
servo.attach(9); //attach it to pin 9
}

void loop(){
  nh.spinOnce();
  delay(1);
}

Originally posted by alam121 on ROS Answers with karma: 15 on 2020-01-14

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

delay(1) is a very small delay. You may want to try and change it to something a little higher. I've seen previous Q&As where using a larger delay makes things work better.

Not saying it will solve your problem though. Just something to keep in mind.


Originally posted by gvdhoorn with karma: 86574 on 2020-01-14

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by alam121 on 2020-01-14:
This actually worked. I'm not sure why i did not think of it earlier. Many thanks!

$\endgroup$

Your Answer

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