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