Subsribe and publish conversion problem [closed]
I'm trying to write an own Subscribe and Publisk node. I would like ti subscribe to the joystick and publish to my motors. For the publish i create with a launchfile to topics, I use the JointVelocityController for that, so they are from type std_msgs:.Float 64. And I think the type i get from the joy is Float32. So when ich start building the node i get this error:
/home/ae/catkin_ws/src/epos_hardware-indigo-devel/epos_hardware/src/nodes/talker.cpp:30:17: error: no match for ‘operator=’ (operand types are ‘std_msgs::Float64’ and ‘float’)
velocity_left = 1000*joy->axes[7];
^
/home/ae/catkin_ws/src/epos_hardware-indigo-devel/epos_hardware/src/nodes/talker.cpp:30:17: note: candidate is:
In file included from /home/ae/catkin_ws/src/epos_hardware-indigo-devel/epos_hardware/src/nodes/talker.cpp:2:0:
/opt/ros/indigo/include/std_msgs/Float64.h:22:8: note: std_msgs::Float64_<std::allocator<void> >& std_msgs::Float64_<std::allocator<void> >::operator=(const std_msgs::Float64_<std::allocator<void> >&)
struct Float64_
^
/opt/ros/indigo/include/std_msgs/Float64.h:22:8: note: no known conversion for argument 1 from ‘float’ to ‘const std_msgs::Float64_<std::allocator<void> >&’
make[2]: *** [epos_hardware-indigo-devel/epos_hardware/CMakeFiles/talker.dir/src/nodes/talker.cpp.o] Error 1
make[1]: *** [epos_hardware-indigo-devel/epos_hardware/CMakeFiles/talker.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
This is my Subscribe and Publish node:
#include "ros/ros.h"
#include "std_msgs/Float64.h"
#include <sensor_msgs/Joy.h>
#define MAX_VELO 80000
class SubscribeAndPublish
{
public:
SubscribeAndPublish()
{
sub_joint= n.subscribe<sensor_msgs::Joy>("joy",1, &SubscribeAndPublish::joyCallback, this);
pub_velocity_left= n.advertise<std_msgs::Float64>("left_velocity_controller/command", 1);
pub_velocity_right= n.advertise<std_msgs::Float64>("right_velocity_controller/command", 1);
}
void joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
std_msgs::Float64 velocity_left;
// do something with the code
velocity_left = 1000*joy->axes[7];
pub_velocity_right.publish(velocity_left);
pub_velocity_left.publish(velocity_left);
}
private:
ros::NodeHandle n;
ros::Publisher pub_velocity_right;
ros::Publisher pub_velocity_left;
ros::Subscriber sub_joint;
};
int main(int argc, char **argv)
{
ros::init(argc,argv,"subsribe_and_publish");
SubscribeAndPublish SAPObject;
ros::spin();
return 0;
}
I think the problem is that i have different kind of types, but i don't now how i can converted them or what i can do.
Thanks for your ideas