Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Arduino] Add ArduinoTcpHardware to use Arduino Ethernet shield. #324

Merged
merged 2 commits into from Oct 5, 2017

Conversation

romainreignier
Copy link
Contributor

I have modified the ESP8266 hardware class to be able to use the Arduino Ethernet Shield for an Arduino TCP connexion.

I have added the #define ROSSERIAL_ARDUINO_TCP to enable the TCP mode. Maybe another string is more suitable?

The class has the same name ArduinoHardware in order to simplify the ros.h file. Only the included header file change.

I have added two simple exemples.

Tested with Arduino Nano, UNO, MEGA, Leonardo, DUE and ESP8266 based Wemos D1 Mini.
Note that with the Atmega328, the RAM is limited after the include of the Ethernet and rosserial libraries.

I have modified the ESP8266 hardware class to be able to use the Arduino Ethernet Shield for an Arduino TCP connexion.

I have added the `#define ROSSERIAL_ARDUINO_TCP` to enable the TCP mode. Maybe another string is more suitable?

The class has the same name `ArduinoHardware` in order to simplify the `ros.h` file. Only the included header file change.

I have added two simple exemples.

Tested with Arduino Nano, UNO, MEGA, Leonardo, DUE and ESP8266 based Wemos D1 Mini.
Note that with the Atmega328, the RAM is limited after the include of the Ethernet and rosserial libraries.
Copy link
Member

@mikepurvis mikepurvis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have the whitespace fixed in overhauled files.

if(tcp_.connected()){
return tcp_.read();
}else{
tcp_.connect(server_, serverPort_);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're just following what was here before, but given that the file is basically being rewritten, it would be great if you could follow ROS brace style: http://wiki.ros.org/CppStyleGuide#Formatting

The astyle tool can quickly update the file: http://wiki.ros.org/roslint#Tips

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no problem, I will update the style.

#include <SPI.h>
#include <Ethernet.h>

#define ROSSERIAL_ARDUINO_TCP
Copy link
Member

@mikepurvis mikepurvis Oct 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not over the moon about switching behaviour based on this define, though it does kind of follow with what we've done previously, particularly around Leonardo and selecting whether to use the UART or USB connection.

I suppose the only alternatives are supplying a ros.h with custom NodeHandle typedefs in each example/firmware, which doesn't really make sense (though it's what we do internally at Clearpath).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is not the best thing. I thing it should be better to include a different header file directly in the sketch. But it means revise the architecture of rosserial_client.

I don't see how you manage the typedef from the firmware, do you have a simple example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our product firmwares, we're using rosserial ports that are not public— for example, that talk to the rosserial_server UDP implementation. In upstream rosserial (here), the ros.h file is supplied with the generated ros_lib and therefore has to be generic, but our ros.h files are much more use-case specific since they're instead supplied with the firmware source tree.

Anyway, it's a bit academic. I think what you have is fine for now, but it would be great to figure out how to document better for future users some suggested design patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About documentation, I think I will edit the rosserial_arduino wiki page to list all the available switches (USBCON, HW_SERIAL...).

About changing the design pattern, it would be nice to give a more explicit API but I have no idea how to do it right now.

@romainreignier
Copy link
Contributor Author

romainreignier commented Oct 4, 2017

Does my change about the white spaces is OK?

@mikepurvis
Copy link
Member

Yes, looks great! Thanks for the contribution.

@mikepurvis mikepurvis merged commit 979bae6 into ros-drivers:jade-devel Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants