Joy node with Arduino
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
Does
rqt_graph
(rosrun rqt_graph rqt_graph
) show you thatrosserial
is subscribed to thejoy
topic?@gvdhoorn: Yes, This is my graph Also the terminal states that
Same problem faced here. Any help? :'(
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. TheJoy
message can be large.