Convert Float32 to C++ float variable
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.