0
$\begingroup$

Rosanswers logo

Hi i trying to send array data from arduino to my node but i have problems with it. I'm reading data from accelerometer and want to send xyz values in array message. Code compile properly but when i tryng to start serial connection with arduino it stucks even if i trying to send only one value. What is wrong here?

/*
 * rosserial Publisher Example
 * Prints "hello world!"
 */
#include "I2Cdev.h"
#include "MPU6050.h"
#include <Wire.h>
#include <ros.h>
//#include <std_msgs/Int16.h>
#include <std_msgs/Int16MultiArray.h>

MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;

ros::NodeHandle  nh;

//std_msgs::Int16 x;
std_msgs::Int16MultiArray xar;


//ros::Publisher inty("inty", &x);
ros::Publisher intyarr("intyarr", &xar);

void setup()
{
  nh.initNode();
  nh.advertise(intyarr);
  Wire.begin();
  accelgyro.initialize();
}

void loop()
{
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  //x.data = ay;
  //inty.publish(&x);
  xar.data[1]=ax;
  intyarr.publish(&xar);
  nh.spinOnce();
  delay(1000);
}

Also i want to resend data from my node to arduino to send it into robot but i dont know how to do it.

void messageCb( const std_msgs::Int16& msg){
  //digitalWrite(13, HIGH-digitalRead(13));   // blink the led
  msg->data;
}

Code like this doesn't work in Arduino IDE.


Originally posted by starcu on ROS Answers with karma: 1 on 2016-01-06

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

http://wiki.ros.org/rosserial/Overview/Limitations Part 1.4 talks about issues with arrays and the need to specify the length of the array explicitly - this may be the issue

example here http://wiki.ros.org/rosserial/Overview/Messages of generating messages that contain arrays, and instructions on how to send them as messages

http://wiki.ros.org/rosserial/Overview/Publishers%20and%20Subscribers shows how to read the data in a message

void messageCb(const std_msgs::Float64& msg)
  if(msg.data > 1.0)
    digitalWrite(13, HIGH-digitalRead(13));   // blink the led
}

Originally posted by nickw with karma: 1504 on 2016-01-06

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Jishnu Pillai on 2017-07-15:
how to access the array data from node to arduino. this is my code: int Arr[4]; void handle_motorspd( const std_msgs::Int32MultiArray::ConstPtr& motor_step) { for (std::vector::const_iterator it = motor_step->data.begin(); it != motor_step->data.end(); ++it) { Arr[i] = *it; i++; }

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.