I'm taking a sample I found on the web about how to get ROS and arduino to communicated together over serial. I have the sample working and now I'm moving the idea of the sample into my OOP project and am running into some trouble.
My sketch works but when I move a certain global variable to a protected member it breaks my sketch.
How do I declare this global variable
ros::Publisher chatter("chatter", &str_msg);
as a protected variable
protected:
ros::Publisher chatter("chatter", &str_msg);
without getting this error
expected identifier before string constant
sample .ino
/*
* rosserial Publisher Example
* Prints "hello world!"
*/
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
char hello[13] = "hello world!";
void setup()
{
nh.initNode();
nh.advertise(chatter);
}
void loop()
{
str_msg.data = hello;
chatter.publish( &str_msg );
nh.spinOnce();
delay(1000);
}
ROSController class
#include <ros.h>
#include <std_msgs/String.h>
class ROSController {
protected:
ros::NodeHandle _nh;
std_msgs::String str_msg;
// ros::Publisher chatter("chatter", &str_msg);
int _throttle;
bool _is_on = false;
public:
void loop();
ROSController();
double* getAttitude();
bool isOn() {
return this->_is_on;
}
int getThrottlePerc() {
return this->_throttle / ROSController::THR_MAX;
}
static const int THR_MAX;
};
const int ROSController::THR_MAX = 100;
ROSController::ROSController() {
this->_nh.initNode();
// this->_nh.advertise(chatter);
}
double* ROSController::getAttitude() {
return new double[3]{0, 0, 0};
}
void ROSController::loop() {
// str_msg.data = new char[] {"hello"};
// chatter.publish( str_msg );
this->_nh.spinOnce();
delay(1000);
}
ROSController
class to the bottom of the question