Arduino + Bluetooth + ROS : Error
Respected all, My task is to get the orientation sensor data from the phone and send it to the ROS for further processing.
I have decided to implement this via the following procedure: 1: Android App | 2: Bluetooth Shield | 3: Arduino (retrieving real time orientation data from android app) | 4: ROS (Rosserial)
I have implemented the first three steps and have retrieved the orientation data on arduino serial monitor on real time.
Now, when I am trying to use the serial_node.py (from the ros wiki), using the command:
rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=9600
I am getting the following error!
This works well when I tried the conventional "Hello World" example of the rosserial. This means that the node files are working well. Also, i have use the command "nh.getHardware()-> setBaud(9600);" to set the baud rate.
Following is the code i am trying. (Please note that there can be manyy error in the code). I have edited the conventional "hello world" program and the arduino bluetooth code to get the orientation string
#include<SoftwareSerial.h>;
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
SoftwareSerial myBT (11, 10);
const int ledPin = 13;
String inCode = "";
boolean endCode = false;
void setup () {
nh.getHardware()-> setBaud(9600);
Serial.begin(9600);
pinMode (ledPin, OUTPUT);
inCode.reserve (30);
nh.initNode();
nh.advertise(chatter);
}
void loop () {
if (myBT.available ()) {
char incomingChar = myBT.read ();
if (incomingChar == ')') {
endCode = true;
}
else
{
inCode = (inCode + incomingChar);
}
}
if (endCode) {
int comma1 = inCode.indexOf (',');
int comma2 = inCode.indexOf (',', comma1 + 1);
String As = inCode.substring (0, comma1);
String Ps = inCode.substring (comma1 + 1, comma2);
String Rs = inCode.substring (comma2 + 1);
Serial.print ("inCode =");
Serial.print (inCode);
Serial.print ("Azimuth =");
Serial.print (As);
Serial.print ("Pitch =");
Serial.print (Ps);
Serial.print ("Roll =");
Serial.println (Rs);
str_msg.data = 'As';
chatter.publish( &str_msg );
nh.spinOnce();
delay(1000);
int A = As.toInt ();
int P = Ps.toInt ();
int R = Rs.toInt ();
inCode = "";
endCode = false;
}
}
Why am i getting such errors? Kindly help. Regards