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

Joy node with Arduino

asked 2016-11-11 05:37:36 -0500

marcoresk gravatar image

updated 2016-11-11 10:35:44 -0500

Hi, I'm very confused.

With ROS Indigo, i managed to set up the rosserial communication with Arduino and all works. I am trying to use the Joy node as input for Arduino but nothing occurs.

This is my code. The purpose is: if a certain button is pressed, the led should turn on as output of pin 3.

#include <stdint.h>
#include <stdlib.h>  
#include <ros.h>
#include <std_msgs/Float32.h>
#include <sensor_msgs/Joy.h>

void joydata ( const sensor_msgs::Joy& joy){

  if ((joy.axes[14]) >= 0.5){
    digitalWrite(3,HIGH); 

     }     
}

ros::NodeHandle  nh;
ros::Subscriber<sensor_msgs::Joy> sub1("joy", joydata);    

void setup()
{
    pinMode(3, OUTPUT); //set up the LED
    nh.initNode();
    nh.subscribe(sub1);
}

void loop()   {
 nh.spinOnce();
 delay(1);
}

And I don't understand what I am doing wrong. Joy node works (checked it with rostopic echo) and rosserial works (checked it with another subscriber program). The led and all electrical things work (checked it with an alternative arduino sketch). What is the proper way to read data from Joy node? Thanks in advance!

UPDATE I tried to mirror the signal reading it in Arduino and publishing it from Arduino. If the Joy signal has this structure

header: 
  seq: 163
  stamp: 
    secs: 1478877490
    nsecs: 840985264
  frame_id: ''
axes: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0, 0.08682194352149963, 0.0]
buttons: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

my mirrored signal is empty like this (except for "seq" value. Numbered are different because copy&paste in different times).

header: 
  seq: 3744
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: ''
axes: []
buttons: []

I'm still confused, I'll hope someone will help. Thank you

edit retag flag offensive close merge delete

Comments

Does rqt_graph (rosrun rqt_graph rqt_graph) show you that rosserial is subscribed to the joy topic?

gvdhoorn gravatar image gvdhoorn  ( 2016-11-11 05:46:35 -0500 )edit

@gvdhoorn: Yes, This is my graph Also the terminal states that

[INFO] [WallTime: 1478868186.772826] Setup subscriber on joy [sensor_msgs/Joy]
marcoresk gravatar image marcoresk  ( 2016-11-11 06:47:10 -0500 )edit

Same problem faced here. Any help? :'(

Jarvis_007 gravatar image Jarvis_007  ( 2016-12-15 05:18:00 -0500 )edit

I'm not sure, but by default, the arduino implementation of rosserial has a rather small receive and send buffer. Perhaps you could see whether increasing that improves things. The Joy message can be large.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-15 05:49:14 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2016-12-15 13:14:44 -0500

marcoresk gravatar image

updated 2016-12-15 13:15:26 -0500

I actually solved my problem with a node that extracts some values from Joy and publish them as an array (Float32MultiArray type) in a topic. Arduino reads that topic. I think gvdhoorn's observation is correct, but I don't know how to increase the buffer.

edit flag offensive delete link more

Comments

Can you put the full code , i have the same problem. thanks in advance.

NickyDuDe gravatar image NickyDuDe  ( 2018-07-17 10:54:51 -0500 )edit

Can you publish full code?

serhatzengin gravatar image serhatzengin  ( 2019-10-16 03:13:19 -0500 )edit
0

answered 2016-12-16 07:55:28 -0500

gvdhoorn gravatar image

Some probably related questions (and answers):

Looking at rosserial_arduino/ros.h the buffer is set to 150 or 280 bytes. That isn't very much. You should be able to chance it by defining your own NodeHandle type.

edit flag offensive delete link more
0

answered 2022-08-29 07:57:33 -0500

Brilan gravatar image

from your code, if ((joy.axes[14]) >= 0.5){ digitalWrite(3,HIGH); axes don't have an element of int 14 in the array. Its elements ranges from int 0 - 3.

ie axes[ ] = {0, 1, 2, 3};

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-11 05:37:36 -0500

Seen: 1,844 times

Last updated: Dec 16 '16