Ask Your Question
0

Cannot convert ros::Subscriber to float

asked 2017-01-24 04:19:47 -0600

Milliau gravatar image

updated 2017-01-24 04:36:12 -0600

NEngelhard gravatar image

Hello,

I have the Problem: error: cannot convert ros::Subscriber to float in assignment

I used 2 Subscirber to listen to my velocities and i want to get this as an float but it doesn't work.

#include "ros/ros.h"
#include "std_msgs/Float64.h"
#include <can_msgs/Frame.h>
#include <socketcan_bridge/topic_to_socketcan.h>
#include <socketcan_interface/socketcan.h>

class VehicleDynamics
{    
    public:
    VehicleDynamics()

{

   sub_vel_left= n.subscribe<std_msgs::Float64>("left_velocity_controller/command",1, &VehicleDynamics::velCallback, this);
   sub_vel_right= n.subscribe<std_msgs::Float64>("right_velocity_controller/command",1, &VehicleDynamics::velCallback, this);

   pub_ = n.advertise<can_msgs::Frame>("sent_messages", 10);
}

float calculate()
{
    static const float calcReduc = m_reduc * 16.6666666f;
    static const float calcDiameter = (m_diameter * M_PI) / 1000.0f;

    velocity_rpm = ((left_wheel+right_wheel)/ 2);

    return (velocity_rpm* calcDiameter/calcReduc);
}

void velCallback(const std_msgs::Float64::ConstPtr& float_msgs)
{

    n.getParam("MobileResearchPlattform/motor/nominal_speed",m_max_velocity);
    n.getParam("MobileResearchPlattform/geometry/wheel_diameter",m_diameter); 
    n.getParam("/MobileResearchPlattform/motor/reduction",m_reduc); 

    left_wheel=sub_vel_left;
    right_wheel=sub_vel_right;
    velocity_kmh = calculate();

 can_msgs::Frame msg;
  msg.is_extended = false;
  msg.is_rtr = false;
  msg.is_error = false;
  msg.id = 0x220;
  msg.dlc = 8;

msg.data[1] = velocity_kmh;



  msg.header.frame_id = "0";  // "0" for no frame.
  msg.header.stamp = ros::Time::now();

  // send the can_frame::Frame message to the sent_messages topic.
  pub_.publish(msg);

}   
private:

ros::NodeHandle n;
ros::Publisher pub_;
ros::Subscriber sub_vel_left;
ros::Subscriber sub_vel_right;
float velocity_rpm;
float velocity_kmh;
float left_wheel;
float right_wheel;
float m_max_velocity;
float m_diameter;

    int m_reduc;

};




    int main(int argc, char **argv)

{
    ros::init(argc,argv,"VehilceDyn");

    VehicleDynamics SAPObject;
    ros::Rate loop_rate(10000);

    ros::spin();
    return 0;

 }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-01-24 04:36:03 -0600

NEngelhard gravatar image

updated 2017-01-24 04:36:31 -0600

The subscriber is a subscriber and not a float value. You can find the float value in the msg you receive. In your case, you need two callback functions in which you can access your float as float_msgs->data. So create two callbacks (leftVelCb, RightVelCb) and read the corresponding msg.

edit flag offensive delete link more

Comments

ok, so i have two make a function like this: void velLeftCallback(const std_msgs::Float64::ConstPtr& float_msgs) { float_msgs->data; } is that right? and where i can definded in which variable I write the data?

Milliau gravatar imageMilliau ( 2017-01-24 06:10:28 -0600 )edit

just assign it,,, (float left_vel = float_msgs->data;}

NEngelhard gravatar imageNEngelhard ( 2017-01-24 07:17:15 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-01-24 04:19:47 -0600

Seen: 775 times

Last updated: Jan 24 '17