Implementing a subscriber with std_msgs::Int16
Hello. I am new to ros and rosserial in general. After going through the beginner tutorials on rosserial-arduino, I decided to modify the blink example that comes with the ros library so that whenever I enter the following in the terminal:
rosoptic pub Led_Brigghtness std_msgs/Int16 x
(where x is between 0 and 100)
it maps it into the range of arduino analog values and then changes the brightness of the led. However, I am having problems in declaring a suitable subscriber. I was previously about to create a custom message for this but after I discovered that std_msgs has int data types, I figured I could use those instead. I have the following code:
#include <ros.h>
#include <std_msgs/Int16.h>
ros::NodeHandle nh;
int Control_Pin = 3;
std_msgs::Int16 User_Input;
void messageCb( std_msgs::Int16 & Brightness){
int brightness = map(User_Input.data, 0, 100, 0, 254);
analogWrite(Control_Pin, brightness); // blink the led
}
ros::Subscriber<std_msgs::Int16> sub("Led_Brightness", &User_Input);
void setup()
{
pinMode(Control_Pin, OUTPUT);
nh.initNode();
nh.subscribe(sub);
}
void loop()
{
nh.spinOnce();
delay(1);
}
When I try to compile the code, I get an error on the segment:
ros::Subscriber<std_msgs::Int16> sub("Led_Brightness", &User_Input);
that says:
no matching function for call to 'ros::Subscriber<std_msgs::Int16>::Subscriber(const char [15], std_msgs::Int16*)