Ask Your Question

Subsribe and publish conversion problem [closed]

asked 2016-11-02 07:02:05 -0500

Milliau gravatar image

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



        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];


    ros::NodeHandle n;
    ros::Publisher pub_velocity_right;
    ros::Publisher pub_velocity_left;
    ros::Subscriber sub_joint;

int main(int argc, char **argv)

    SubscribeAndPublish SAPObject;


    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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Milliau
close date 2016-11-02 07:29:45.844047

1 Answer

Sort by » oldest newest most voted

answered 2016-11-02 07:16:17 -0500

Thomas D gravatar image

Try changing from velocity_left = 1000*joy->axes[7]; to = 1000*joy->axes[7];. In the std_msgs/Float64 the field holding the float is data. What the error is saying is that currently you are trying to assign the entire message (not just a single message field) to a float value.

edit flag offensive delete link more


Thanks this solve the problem :-)

Milliau gravatar image Milliau  ( 2016-11-02 07:29:25 -0500 )edit

Question Tools

1 follower


Asked: 2016-11-02 07:02:05 -0500

Seen: 1,850 times

Last updated: Nov 02 '16