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

Array data from arduino

asked 2016-01-06 04:17:39 -0600

starcu gravatar image

updated 2016-01-06 04:21:52 -0600

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-01-06 04:37:36 -0600

updated 2016-01-06 04:56:55 -0600

http://wiki.ros.org/rosserial/Overvie... 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/Overvie... of generating messages that contain arrays, and instructions on how to send them as messages

http://wiki.ros.org/rosserial/Overvie... 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
}
edit flag offensive delete link more

Comments

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<int>::const_iterator it = motor_step->data.begin(); it != motor_step->data.end(); ++it) { Arr[i] = *it; i++; }

Jishnu Pillai gravatar image Jishnu Pillai  ( 2017-07-15 07:14:09 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-06 04:17:39 -0600

Seen: 4,535 times

Last updated: Jan 06 '16