-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# [NodeMCU](https://en.wikipedia.org/wiki/NodeMCU) | ||
- Know more about NodeMCU : [Project Page](https://www.nodemcu.com/index_en.html), [Github](https://github.com/nodemcu/nodemcu-devkit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## NodeMCU Esp8266 ROS_serial Publisher | ||
Upload [sketch](https://www.arduino.cc/en/tutorial/sketch) to NodeMCU from [Arduino IDE](https://www.arduino.cc/en/main/software). | ||
Connect to wireless access point by ESP. | ||
|
||
Echo msgs published by `chatter`, run each in separate terminals | ||
``` | ||
$ roscore | ||
$ rosrun rosserial_python serial_node.py tcp | ||
$ rostopic echo /chatter | ||
``` |
52 changes: 52 additions & 0 deletions
52
nodeMCU_esp8266/nodeMCU_ROSserial_publisher/nodeMCU_ROSserial_publisher.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <ros.h> | ||
#include <std_msgs/String.h> | ||
|
||
/* ESP AP Config. */ | ||
#ifndef APSSID | ||
#define APSSID "ESP_AP" | ||
#define APPSK "ROSserial@nodeMCU" | ||
#endif | ||
|
||
const char *ssid = APSSID; | ||
const char *password = APPSK; | ||
|
||
/* ROS */ | ||
IPAddress server(192,168,4,2); | ||
const uint16_t serverPort = 11411; | ||
|
||
ros::NodeHandle nh; | ||
std_msgs::String str_msg; | ||
ros::Publisher chatter("chatter", &str_msg); | ||
|
||
char firstMsg[5] = "Hey,"; bool recievedFirstMsg = false; | ||
char msgtxt[19] = "Message Recieved !"; | ||
|
||
void setup() { | ||
ESP.eraseConfig(); | ||
WiFi.disconnect(true); | ||
WiFi.mode(WIFI_AP); | ||
WiFi.softAP(ssid, password); | ||
delay(1000); | ||
|
||
nh.getHardware()->setConnection(server, serverPort); | ||
nh.initNode(); | ||
nh.advertise(chatter); | ||
} | ||
|
||
void loop() { | ||
if (nh.connected()) { | ||
if(!recievedFirstMsg){ | ||
str_msg.data = firstMsg; | ||
chatter.publish( &str_msg ); | ||
recievedFirstMsg = true; | ||
} | ||
str_msg.data = msgtxt; | ||
chatter.publish( &str_msg ); | ||
} else { | ||
// Don't publish unless connected.. | ||
recievedFirstMsg = false; | ||
} | ||
nh.spinOnce(); | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## NodeMCU Esp8266 ROS_serial Subscriber | ||
Upload [sketch](https://www.arduino.cc/en/tutorial/sketch) to NodeMCU from [Arduino IDE](https://www.arduino.cc/en/main/software) and open [Serial Monitor](https://www.arduino.cc/en/guide/environment#toc12). | ||
Connect to wireless access point by ESP. | ||
|
||
Publish msgs to `chatter_`, run each in separate terminals | ||
``` | ||
$ roscore | ||
$ rosrun rosserial_python serial_node.py tcp | ||
$ rostopic pub /chatter_ std_msgs/String "data: '<your msg here>'" --once | ||
``` |
53 changes: 53 additions & 0 deletions
53
nodeMCU_esp8266/nodeMCU_ROSserial_subscriber/nodeMCU_ROSserial_subscriber.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <ros.h> | ||
#include <std_msgs/String.h> | ||
|
||
/* ESP AP Config. */ | ||
#ifndef APSSID | ||
#define APSSID "ESP_AP" | ||
#define APPSK "ROSserial@nodeMCU" | ||
#endif | ||
|
||
const char *ssid = APSSID; | ||
const char *password = APPSK; | ||
|
||
/* ROS */ | ||
IPAddress server(192,168,4,2); | ||
const uint16_t serverPort = 11411; | ||
|
||
ros::NodeHandle nh; | ||
|
||
void messageCb(const std_msgs::String& str_msg){ | ||
String txt; | ||
txt = str_msg.data; | ||
Serial.println(txt); | ||
int blinkCount = txt.length(); | ||
for(int i=1;i<=blinkCount;i++){ | ||
digitalWrite(LED_BUILTIN, HIGH-digitalRead(LED_BUILTIN)); | ||
delay(200); | ||
digitalWrite(LED_BUILTIN, HIGH-digitalRead(LED_BUILTIN)); | ||
delay(200); | ||
} | ||
} | ||
|
||
ros::Subscriber<std_msgs::String> sub("chatter_", &messageCb); | ||
|
||
void setup() { | ||
ESP.eraseConfig(); | ||
WiFi.disconnect(true); | ||
WiFi.mode(WIFI_AP); | ||
WiFi.softAP(ssid, password); | ||
delay(1000); | ||
|
||
Serial.begin(9600); | ||
pinMode(LED_BUILTIN,OUTPUT); | ||
|
||
nh.getHardware()->setConnection(server, serverPort); | ||
nh.initNode(); | ||
nh.subscribe(sub); | ||
} | ||
|
||
void loop() { | ||
nh.spinOnce(); | ||
delay(1); | ||
} |