Problem with bridging CORE2 to ROS network

While working with ROS tutorial chapter 3 together with the code from https://community.husarion.com/t/examples-for-using-makeblock-sensors/138/3 I got an error message using the following command at my RPi:

$ /opt/husarion/tools/rpi-linux/ros-core2-client /dev/ttyCORE2

The program started, the messages ROS serial Python node and Connecting to /dev/ttyCORE2 at 57600 Baud appeared, but after a few seconds there appears an error message:

Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

“roscore” is running on the RPi and shows kinetic as distro, After starting “ros-core-client” “rosnode list” shows an additional node “/serial_node”.

My Core2 program starts with:

platform.begin(&RPi);
nh.getHardware()->initWithDevice(&platform.LocalSerial);
nh.initNode();
nh.advertise(range_pub);

I am working offline (without Husarion Cloud). If that is the problem, what must I change to be able to work offline?

Hi MichaelT.

Working offline or online don’t have any matters here. If you don’t mind I would like to see all your code to check what the problem is. After that I will can give you some more info.

Regard,
Hubert.

Hi Hubert

I am not at home at the moment, but I used the code from https://community.husarion.com/t/examples-for-using-makeblock-sensors/138/3, changed the calls for LED1 to something like hLed1 because of compilation problems and used my MeDistanceSensor code.
But I can send you my full code probably later.

Michael

Hi Hubert

here is my code:

#include “hFramework.h”
#include “hCloudClient.h”
#include “MeDistanceSensor.h”
#include <ros.h>
#include “tf/tf.h”
#include “sensor_msgs/Range.h”
using namespace meModules;
using namespace hFramework;

MeDistanceSensor sens(hSens2);

ros::NodeHandle nh;
sensor_msgs::Range range;
ros::Publisher range_pub("/range", &range);

void hMain()
{
platform.begin(&RPi);
nh.getHardware()->initWithDevice(&platform.LocalSerial);
nh.initNode();
nh.advertise(range_pub);
hLED1.on();

while (true) {
    int dist = sens.getDistance();
    range.range = (float)dist;
    range_pub.publish(&range);
    nh.spinOnce();
    hLED1.toggle();
    sys.delay(10); // 10 ms
}

}

After being connected to the cloud it works now.
But how it works offline (without cloud, only with my local Wifi)?

It will work offline, you only need internet access for first setup. If you want to avoid internet access at all, you can disable it and connect ROS directly to CORE2 serial port.

First disable Husarion service (systemctl disable husarion-shield) and reboot (you can reenable it later with systemctl enable husarion-shield). Then change the program to connect directly to the serial port:

void hMain()
{
    //platform.begin(&RPi); // comment this line
    nh.getHardware()->initWithDevice(&RPi); // change here
    nh.initNode();
    nh.subscribe(sub);
// ...

Later, use /opt/husarion/tools/rpi-linux/ros-core2-client /dev/ttyS1 to connect CORE2 to ROS network.

It tried that but I get permantly

[INFO] [1511466791.180960]: Connecting to /dev/ttyS1 at 57600 baud

messages after entering:

/opt/husarion/tools/rpi-linux/ros-core2-client /dev/ttyS1

My Core2 program published ROS-Range and ROS-BatteryState.
rosnode list showed an additional node /serial_node

I forgot to mention that you should use /dev/serial0 if you are on Raspberry Pi (the command I’ve given previously was for ASUS Tinkerboard):

/opt/husarion/tools/rpi-linux/ros-core2-client /dev/serial0

Also, please make sure you have updated your system (apt-get update; apt-get dist-upgrade -y) - I have also pushed update fixing other possible problem.

That works.
But after a short time I get “Lost sync with device” messages and I have to restart Core2.
I am publishing a “sensor_msgs/Range” and a “sensor_msgs/BatteryState” message with a delay of 100ms.

Thanks for your help

Michael

Running the “/opt/husarion/tools/rpi-linux/ros-core2-client /dev/serial0” command gives me the following output:

Unable to register with master node [http://localhost:11311]: master may not be running yet. Will keep trying.
[INFO] [1512504303.906058]: ROS Serial Python Node
[INFO] [1512504303.955650]: Connecting to /dev/serial0 at 500000 baud
[ERROR] [1512504321.072081]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
[ERROR] [1512504336.076856]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

I just did a apt update and upgrade before trying the command.
As you can also see I forgot to start roscore at first, but starting roscore before doing the command also doesn’t work.

Is this also the correct baudrate?

In the meantime I wrote a launchfile:

<launch>
  <node pkg="rosserial_python" type="serial_node.py" name="robby_node">
    <param name="port" value="/dev/serial0" />
    <param name="baud" value="500000" />
  </node>
</launch>

But this is for working without cloud.

Do you use a Raspberry?

Yes I use a pi3, I want it to work with the cloud at the moment. Is there a default baudrate the core2 uses? Or can I just set my own baudrate with rosserrial_python and match it with the core2?

Now I’m getting the following messages:
[WARN] [1512548579.110756]: Serial Port read failure: device reports readiness to read but returned no data (device disconnected ormultiple access on port?)
[ERROR] [1512548586.069841]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

Hi Ruben.

First thing: you have to run is:

roscore

Without this you allways will have communicate:

Unable to register with master node [http://localhost:11311]: master may not be running yet. Will keep trying.

Secound thing: Do you upload/flash proper propgram to your CORE2? Maybe device sould returned no data? Try one of the code from this tutorial.

After completing these steps, let me now what the status is.

Regard,
Hubert.

Hi Hubert,

I know that I need to run roscore first, that was just a small mistaken which I only did once.
I got my code working now :).
I was using the /dev/serioal0, and that doesn’t work when I’m connected to the cloud.
I also did try with /dev/ttyCORE2 but that had failed all the times, I’m not sure what I’m doing different now.
But with rqt_graph I could se that the serial node was there but not connected to the /cmd_vel.

First I tried the code from the tutorial and then my previous code which now also works.
I can upload my code if someone else has trouble with getting this to work.

Ruben-
I would appreciate very much to see your test code. I’m stuck where you were ~7 months ago, but using Tinkerboard 2/Core2.
Thanks