ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Convert Float32 to C++ float variable

asked 2020-08-04 00:54:05 -0500

Padmal gravatar image

updated 2020-08-04 01:02:22 -0500

Hi, I'm trying to convert a Float32 type std_msg into a float variable. Following is the code I have at the moment.

void update_yaw(const std_msgs::Float32 &yaw)
{
    std_msgs::Float32 imu;
    imu = *yaw;
    fromIMU::Yaw = float(imu.data);
    ROS_INFO("Yaw updated");
}

But when I try to compile, the following error comes.

/home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp: In function ‘void update_yaw(const Float32&)’:
/home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:89:11: error: no match for ‘operator*’ (operand type is ‘const Float32 {aka const std_msgs::Float32_<std::allocator<void> >}’)
     imu = *yaw;
           ^~~~
In file included from /usr/include/boost/config/no_tr1/complex.hpp:21:0,
                 from /usr/include/boost/math/policies/error_handling.hpp:17,
                 from /usr/include/boost/math/special_functions/round.hpp:14,
                 from /opt/ros/melodic/include/ros/time.h:58,
                 from /opt/ros/melodic/include/ros/ros.h:38,
                 from /home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:1:
/usr/include/c++/7/complex:404:5: note: candidate: template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const std::complex<_Tp>&)
     operator*(const _Tp& __x, const complex<_Tp>& __y)
     ^~~~~~~~
/usr/include/c++/7/complex:404:5: note:   template argument deduction/substitution failed:
/home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:89:12: note:   candidate expects 2 arguments, 1 provided
     imu = *yaw;
            ^~~
In file included from /usr/include/boost/config/no_tr1/complex.hpp:21:0,
                 from /usr/include/boost/math/policies/error_handling.hpp:17,
                 from /usr/include/boost/math/special_functions/round.hpp:14,
                 from /opt/ros/melodic/include/ros/time.h:58,
                 from /opt/ros/melodic/include/ros/ros.h:38,
                 from /home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:1:
/usr/include/c++/7/complex:395:5: note: candidate: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const _Tp&)
     operator*(const complex<_Tp>& __x, const _Tp& __y)
     ^~~~~~~~
/usr/include/c++/7/complex:395:5: note:   template argument deduction/substitution failed:
/home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:89:12: note:   ‘const Float32 {aka const std_msgs::Float32_<std::allocator<void> >}’ is not derived from ‘const std::complex<_Tp>’
     imu = *yaw;
            ^~~
In file included from /usr/include/boost/config/no_tr1/complex.hpp:21:0,
                 from /usr/include/boost/math/policies/error_handling.hpp:17,
                 from /usr/include/boost/math/special_functions/round.hpp:14,
                 from /opt/ros/melodic/include/ros/time.h:58,
                 from /opt/ros/melodic/include/ros/ros.h:38,
                 from /home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:1:
/usr/include/c++/7/complex:386:5: note: candidate: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const std::complex<_Tp>&)
     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
     ^~~~~~~~
/usr/include/c++/7/complex:386:5: note:   template argument deduction/substitution failed:
/home/padmal/catkin_ws/src/ouster_example/ouster_ros/src/merger_node.cpp:89:12: note:   ‘const Float32 {aka const std_msgs::Float32_<std::allocator<void> >}’ is not derived from ‘const std::complex<_Tp>’
     imu = *yaw;
            ^~~

What could be the issue here? Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2020-08-04 01:56:15 -0500

mgruhler gravatar image

Your function signature shows you get a reference to yaw. It is not a pointer. So you don't need to dereference it. Simply imu = yaw should suffice.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-08-04 00:54:05 -0500

Seen: 1,693 times

Last updated: Aug 04 '20