ros-drivers / rosserial

A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial
515 stars 525 forks source link

ROS Nodemcu Arduino compilation issue #353

Open chrissunny94 opened 6 years ago

chrissunny94 commented 6 years ago

Hey guys , i am trying to run this https://github.com/agnunez/espros

I got an error like this when i tried to compile , 'class ArduinoHardware' has no member named 'setConnection' nh.getHardware()->setConnection(server, serverPort); ^ exit status 1 'class ArduinoHardware' has no member named 'setConnection' Any one faced similar problems before ?

I am trying to run this on Ros-Indigo (Might that be the problem , should i try some newer version)

https://www.youtube.com/watch?v=o_gFG... , this is what i am trying to do right now .

I can control the bot vai UDP packets generated from a python script .

But i would like to get it ROS enabled right from the MCU level . I know i can write a middle ware python script to make it ROS enabled .(but i want a cleaner code)

romainreignier commented 6 years ago

Why are you using this external repo? The ESP8266 has been included in this git repo. But it might not be available in ROS Indigo Ubuntu packages, so you have to clone this repo in your Catkin workspace, build it, source it and then re-generate the ros_lib library in your Arduino Libraries folder.

Because the setConnection() method exists in the current version of rosserial_arduino, see here: https://github.com/ros-drivers/rosserial/blob/c58e2f11b2ff8060b86a9c50982e31ce02f802ab/rosserial_arduino/src/ros_lib/ArduinoTcpHardware.h#L54 So you should not get that error.

R0dri commented 6 years ago

@romainreignier thank you, had the same problem and it was because I was not using this git repo as you stated. Should this be closed?

romainreignier commented 6 years ago

Yes, this issue can be closed.

Edit: Noticed that it is not the OP that commented.

Le jeu. 14 juin 2018 à 05:07, R0dri notifications@github.com a écrit :

@romainreignier https://github.com/romainreignier thank you, had the same problem and it was because I was not using this git repo as you stated. Should this be closed?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ros-drivers/rosserial/issues/353#issuecomment-397143784, or mute the thread https://github.com/notifications/unsubscribe-auth/AIb5YHE3qyb3_CNQ01rK2kd-LT53WC7Lks5t8cVigaJpZM4Rinxv .

arom25 commented 2 years ago

Hi @chrissunny94, make sure you add #define ROSSERIAL_ARDUINO_TCP before including the file "ros.h".

Like this:

#define ROSSERIAL_ARDUINO_TCP
#include "ros.h"
IPAddress server(192, 168, 0, 100);
const uint16_t serverPort = 11411;
nh.getHardware()->setConnection(server, serverPort);

Thanks!

noshluk2 commented 2 years ago

For me your solution + wifi connectivity delay was the solution


#define ROSSERIAL_ARDUINO_TCP #LorenzF solution -> which is now updated in noetic-devel -> ros_lib->ros.h
#include "WiFi.h"
#include <ros.h>
#include <std_msgs/Int16.h>
#define IR_pin 16

void setup() { Serial.begin(115200); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) # -> wifi delay -> a must -> other wise it will restart continuously { delay(500); Serial.print("."); } Serial.println("WiFi connected - IP address: "); Serial.println(WiFi.localIP()); nh.getHardware()->setConnection(server, serverPort); nh.initNode(); nh.advertise(ir_values_node); pinMode(IR_pin,INPUT); }


Order of the code lines is important , especially 
1- delay(500) on connecting ,
2-   nh.getHardware()->setConnection(server, serverPort); and then   nh.initNode();
sajidmohd717 commented 2 years ago

Hi @chrissunny94, make sure you add #define ROSSERIAL_ARDUINO_TCP before including the file "ros.h".

Like this:

#define ROSSERIAL_ARDUINO_TCP
#include "ros.h"
IPAddress server(192, 168, 0, 100);
const uint16_t serverPort = 11411;
nh.getHardware()->setConnection(server, serverPort);

Thanks!

Thanks!, this solved it for me