ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I have already got the bluetooth connection to work with this module by setting some data to be printed on the Serial monitor of Arduino, but nothing related to ROS. The command lines I used were:
$ sudo rfcomm bind 0&
$ cat /dev/rfcomm0
By using this, I've got the data printed on my linux machine terminal. But I don't need just to see them, I need to get them with a node to make some operations. And I have already tried that same procedure with a 57.600 baud rate, and got the same error message.
2 | No.2 Revision |
I have already got the bluetooth connection to work with this module by setting some data to be printed on the Serial monitor of Arduino, but nothing related to ROS. The command lines I used were:
$ sudo rfcomm bind 0&
$ cat /dev/rfcomm0
By using this, I've got the data printed on my linux machine terminal. But I don't need just to see them, I need to get them with a node to make some operations. And I have already tried that same procedure with a 57.600 baud rate, and got the same error message.
EDITED
I have tried to change the serial port by using the class definition below, but it didn't recognize Serial1.
class NewHardware : public ArduinoHardware
{
public:
NewHardware():ArduinoHardware(&Serial1, 57600){};
};
ros::NodeHandle_<NewHardware> nh;
So, I added this line in the beginning of my sketch
# define USBCON
which would change the serial port, according to some page on the internet. And now, I get a new error message.
[INFO] [WallTime: 1470535945.212095] ROS Serial Python Node
[INFO] [WallTime: 1470535945.215136] Connecting to /dev/rfcomm0 at 57600 baud
Traceback (most recent call last):
File "/opt/ros/indigo/lib/rosserial_python/serial_node.py", line 80, in <module>
client = SerialClient(port_name, baud)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 385, in __init__
self.requestTopics()
File "/opt/ros/indigo/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 392, in requestTopics
self.port.flushInput()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 500, in flushInput
termios.tcflush(self.fd, TERMIOS.TCIFLUSH)
termios.error: (5, 'Input/output error')
Any ideas? This new error message doesn't even say what the problem is.
3 | No.3 Revision |
I have already got the bluetooth connection to work with this module by setting some data to be printed on the Serial monitor of Arduino, but nothing related to ROS. The command lines I used were:
$ sudo rfcomm bind 0&
$ cat /dev/rfcomm0
By using this, I've got the data printed on my linux machine terminal. But I don't need just to see them, I need to get them with a node to make some operations. And I have already tried that same procedure with a 57.600 baud rate, and got the same error message.
EDITED
I have tried to change the serial port by using the class definition below, but it didn't recognize Serial1.
class NewHardware : public ArduinoHardware
{
public:
NewHardware():ArduinoHardware(&Serial1, 57600){};
};
ros::NodeHandle_<NewHardware> nh;
So, I added this line in the beginning of my sketch
# define USBCON
which would change the serial port, according to some page on the internet. And now, I get a new error message.
[INFO] [WallTime: 1470535945.212095] ROS Serial Python Node
[INFO] [WallTime: 1470535945.215136] Connecting to /dev/rfcomm0 at 57600 baud
Traceback (most recent call last):
File "/opt/ros/indigo/lib/rosserial_python/serial_node.py", line 80, in <module>
client = SerialClient(port_name, baud)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 385, in __init__
self.requestTopics()
File "/opt/ros/indigo/lib/python2.7/dist-packages/rosserial_python/SerialClient.py", line 392, in requestTopics
self.port.flushInput()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 500, in flushInput
termios.tcflush(self.fd, TERMIOS.TCIFLUSH)
termios.error: (5, 'Input/output error')
Any ideas? This new error message doesn't even say what the problem is.
"SOLVED"
Well, I ended up choosing another way to accomplish my goal. I've developed (not alone) a ROS code, on my laptop, that gets data directly from serial port. This is the code:
#include "ros/ros.h"
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <sys/ioctl.h>
int main(int argc, char **argv)
{
ros::init (argc,argv,"imu_node");
ros::NodeHandle nh;
ros::Rate loop_rate(50); //Hz
std::string aux;
//Begin serial communication with Arduino
struct termios toptions;
int fd, n;
float roll, pitch, yaw;
nh.getParam("imu_node/serial_port",aux);
ROS_INFO_STREAM(aux);
fd = open(aux.c_str(), O_RDWR | O_NOCTTY);
/* wait for the Arduino to reboot */
usleep(3500000);
/* get current serial port settings */
tcgetattr(fd, &toptions);
/* set 9600 baud both ways */
cfsetispeed(&toptions, B115200);
cfsetospeed(&toptions, B115200);
/* 8 bits, no parity, no stop bits */
toptions.c_cflag &= ~PARENB;
toptions.c_cflag &= ~CSTOPB;
toptions.c_cflag &= ~CSIZE;
toptions.c_cflag |= CS8;
/* Canonical mode */
toptions.c_lflag |= ICANON;
/* commit the serial port settings */
tcsetattr(fd, TCSANOW, &toptions);
while(ros::ok())
{
char buf[64]="temp text";
write(fd, "I\n", 2);
usleep(500);
/* Receive string from Arduino */
do
{
n = read(fd, buf, 32);
}while (n < 10);
/* insert terminating zero in the string */
buf[n] = 0;
sscanf(buf, "I|%f|%f|%f|*\r\n", &yaw, &pitch, &roll);
ROS_INFO_STREAM(buf);
ROS_INFO_STREAM("accel_x: " << roll);
ROS_INFO_STREAM("accel_y: " << pitch);
ROS_INFO_STREAM("yaw: " << yaw);
ros::spinOnce();
loop_rate.sleep();
}
}
Then, I link the rfcomm0 port created by the bluetooth connection to another random serial port, because, apparently, the parameter setting doesn't work with the original bluetooth port (rfcomm0).
$ sudo ln -s /dev/rfcomm0 /dev/ttyBT
And finally, I set the node parameter and run the node.
$ rosparam set /imu_node/serial_port /dev/ttyBT
$ rosrun imu imu