ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

rosserial baud rate not being set

asked 2016-09-07 10:03:47 -0500

updated 2016-10-28 10:47:20 -0500

I am trying to use rosserial with an Arduino Uno (ROS Indigo & ubuntu 14.04) to control a Kangaroo motor controller from Dimension Engineering. I am publishing a twist message which the Arduino subscribes to. Things are working at 57600 baud except that over half of the commands are not making it through, and after roughly 10 seconds it looses sync.

Now I'm trying to lower the baud rate to 9600. In my arduino code I have:

#define TX_Pin 10
#define RX_Pin 9

SoftwareSerial SerialPort(RX_PIN, TX_PIN);
KangarooSerial K(SerialPort);
KangarooChannel Drive(K, 'D');
KangarooChannel Turn(K, 'T');

ros::NodeHandle nh;

ros::Subscriber<geometry_msgs::Twist> sub("move", &move_cb);

void setup()
{
nh. initNode();
nh.getHardware()->setBaud(9600);
nh.subscribe(sub);

SerialPort.begin(9600);
SerialPort.listen();
}

And in my launch file I put:

<node pkg="rosserial_python" type="serial_node.py" name="serial_node" output="screnn">
    <param name="port" value="/dev/ttyACM0" />
    <param name ="baud" value="9600" />
</node>

The Arduino then fails to sync, but if I change the launch file to

<node pkg="rosserial_python" type="serial_node.py" name="serial_node" output="screnn">
    <param name="port" value="/dev/ttyACM0" />
    <param name ="baud" value="57600" />
</node>

Then i connect, which tells me that the baud rate of the Arduino is not being set properly. Does anyone know how to properly set the baud rate?

UPDATE:

I have since abandoned using ROSSERIAL and instead am using an FTDI cable which I highly recommend. A lot of sensors have packages already made for them to communicate over serial, and those that don't you can use pyserial which is very easy to setup :) This eliminates the need for a unnecessary Arduino, saving money and debugging time.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-09-07 18:42:12 -0500

Mark Rose gravatar image

The baud rate is used in ArduinoHardware::init(), which is called by NodeHandle_::initNode(), so I think you should set the baud rate before calling nh.initNode().

edit flag offensive delete link more

Comments

I haven't had any problems with the default 57600 baud rate, though. How are you communicating, through a USB cable?

Mark Rose gravatar image Mark Rose  ( 2016-09-07 18:43:03 -0500 )edit

Yes I am communicating through a USB cable. Moving nh.getHardware()->setBaud(9600); above nh. initNode(); solved my issue. Although I am considering abandoning using an arduino altogether and instead using an FTDI cable because even with the baud rate issue fixed I am having issue sending motor cmds

shoemakerlevy9 gravatar image shoemakerlevy9  ( 2016-09-07 19:02:47 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-07 10:03:47 -0500

Seen: 2,248 times

Last updated: Oct 28 '16