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

Revision history [back]

click to hide/show revision 1
initial version

hi

you must to use Float32MultiArray

#include <ros.h>
#include "std_msgs/Float64MultiArray.h"


ros::NodeHandle nh;

float voltage1 = 23.44, voltage2 = 74.43;

std_msgs::Float64MultiArray test;

ros::Publisher p("my_topic", &test);

void setup()
{

  nh.initNode();
  nh.advertise(p);
  test.data.resize(2);

}

void loop()
{
  test.data.at(0) = voltage1;
  test.data.at(1) = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

hi

you must to use Float32MultiArray

#include <ros.h>
#include "std_msgs/Float64MultiArray.h"


ros::NodeHandle nh;

float voltage1 = 23.44, voltage2 = 74.43;

std_msgs::Float64MultiArray test;

ros::Publisher p("my_topic", &test);

void setup()
{

  nh.initNode();
  nh.advertise(p);
  test.data.resize(2);

}

void loop()
{
  test.data.at(0) = voltage1;
  test.data.at(1) = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

if you want to publish single float via topic change this part of code:

void loop()
{
  test.data = voltage1;
  p.publish( &test );// add this line
  test.data = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

hi

you must to use Float32MultiArray

#include <ros.h>
#include "std_msgs/Float64MultiArray.h"


ros::NodeHandle nh;

float voltage1 = 23.44, voltage2 = 74.43;

std_msgs::Float64MultiArray test;

ros::Publisher p("my_topic", &test);

void setup()
{

  nh.initNode();
  nh.advertise(p);
  test.data.resize(2);
test.data = (float*)malloc(sizeof(float) *2);

}

void loop()
{
  test.data.at(0) = test.data[0]= voltage1;
  test.data.at(1) test.data[1] = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

if you want to publish single float via topic change this part of code:

void loop()
{
  test.data = voltage1;
  p.publish( &test );// add this line
  test.data = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

hi

you must to use Float32MultiArray

#include <ros.h>
#include "std_msgs/Float64MultiArray.h"


ros::NodeHandle nh;

float voltage1 = 23.44, voltage2 = 74.43;

std_msgs::Float64MultiArray test;

ros::Publisher p("my_topic", &test);

void setup()
{

  nh.initNode();
  nh.advertise(p);
  test.data = (float*)malloc(sizeof(float) *2);
  test.layout.dim_length = 2;

}

void loop()
{
  test.data[0]= voltage1;
  test.data[1] = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

if you want to publish single float via topic change this part of code:

void loop()
{
  test.data = voltage1;
  p.publish( &test );// add this line
  test.data = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

hi

you must to use Float32MultiArray

#include <ros.h>
#include "std_msgs/Float64MultiArray.h"


ros::NodeHandle nh;

float voltage1 = 23.44, voltage2 = 74.43;

std_msgs::Float64MultiArray test;

ros::Publisher p("my_topic", &test);

void setup()
{

  nh.initNode();
  nh.advertise(p);
  test.data = (float*)malloc(sizeof(float) *2);
  test.layout.dim_length = 2;
test.data_length =2;

}

void loop()
{
  test.data[0]= voltage1;
  test.data[1] = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}

if you want to publish single float via topic change this part of code:

void loop()
{
  test.data = voltage1;
  p.publish( &test );// add this line
  test.data = voltage2;
  p.publish( &test );
  nh.spinOnce();
  delay(10);
}