rosserial stops working when trying to use software serial on arduino?
Hello everyone,
I am running ROS melodic on ubuntu 18.04 and I have encountered a problem for which I couldn't find any info , or I didn't know how to look for it (which could be possible! ) and I would like your help!
I have been using rosserial in the past with no issues at all. However, I have never tried using the serial communication on the arduino side, while it is plugged in the computer and the rosserial is running. When I did try yesterday to control a VESC through arduino's software serial library, if I do not send any commands to the vesc through UART all is fine and ros is happily connected to the arduino, but the moment I try to send a vesc command
(no matter what command i try to send ) I get the following error on the terminal:
[INFO] [1603186275.781290]: Requesting topics... Requesting topics... The setup is as follows:
Laptop running ros -> arduino -> vesc
Joystick sends commands to the arduino over rosserial || the arduino sends the current value to the vesc (vesc being controlled in current mode )
The rosserial is communicating with the arduino at 56200 BAUD whereas the software serial ( I am using this library because of lack of serial ports ) is set to 19600 BAUD.
I can control the vesc with ppm control and rosserial but then I lose all the info I could get back from it using the UART, which is something I would rather not!
Here is a simple arduino code:
#include <Arduino.h>
#include <VescUart.h>
#include <SoftwareSerial.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
// OBJECT INITIALIZATION
SoftwareSerial vesc1_serial(6, 7); // RX , TX
VescUart vesc1;
ros::NodeHandle nh;
/////// PUBLISHERS /////////
geometry_msgs::Twist vel_recieved;
ros::Publisher velocity_pub("/report/vel_received", &vel_recieved);
void setup()
{
// Serial.begin(19200);
// vesc1_serial.begin(19200);
nh.getHardware()->setBaud(57600);
nh.initNode();
nh.subscribe(control_sub);
nh.advertise(velocity_pub);
/** Define which ports to use as vesc1 */
vesc1.setSerialPort(&vesc1_serial);
}
void loop()
{
nh.spinOnce();
vel_recieved.linear.x = 3;
velocity_pub.publish(&vel_recieved);
vesc1.setCurrent(current);
vel_recieved.linear.x = 0;
velocity_pub.publish(&vel_recieved);
// drive_vesc();
// get_vesc_values();
delay(50);
}
The command that makes rosserial through the error is this one:
vesc1.setCurrent(current);
This is the library I use for vesc uart control. Important! It has to be the development branch because this allows controlling vescs over software serial.
Any idea as to what might be causing that? Any advice greatly appreciated!
Should you require any additional info, please let me know!