I'm having an issue with using a class function as my subscriber callback function on Arduino.
First, I'm wondering why there are differences between ROS classes and functions on Arduino and "normal" ROS installation on Linux. For example:
> `nh.initNode()`
instead of
> `ros::init(argc, argv, "controller")`
Or:
> `ros::Subscriber relPos_subscriber("stepper_rel_pos", &Class::callback_fct, &class)`
instead of
> `ros::Subscriber relPos_subscriber("stepper_rel_pos", 10, &Class::callback_fct, &class)`
But my main concern is about using a class function as a callback for my subscriber, which is not in the same class and namespace. Before, it worked fine by using a callback function in the same class with "this" and the same namespace. But I couldn't find any help for my specific case.
I'm getting a large error message about the Subscriber. Last line:
> no matching function for call to> 'ros::Subscriber::Subscriber(const> char [16], void> (asc_node::Stepper::*)(const> std_msgs::Int32&),> asc_node::Stepper*)'
My node:
#include
#include "Stepper.h"
ros::NodeHandle nh;
asc_node::Stepper stepper; //creating the class object
ros::Subscriber relPos_subscriber("stepper_rel_pos", &asc_node::Stepper::moveRel, &stepper);
nh.initNode();
nh.subscribe(relPos_subscriber);
My class function:
#include "Stepper.h"
namespace asc_node {
// Constructor & Destructor
void Stepper::moveRel(const std_msgs::Int32& message)
{
// do something
}
} /* namespace */
And my declaration in Stepper.h:
namespace asc_node {
class Stepper {
//...
void moveRel(const std_msgs::Int32& message);
}
} /* namespace */
I'm using Arduino IDE and an Arduino Uno Rev. 3.
Any help is appreciated.
↧