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

How does the ROS-side host machine interface identify a rosserial-enabled device

asked 2022-02-18 10:46:02 -0600

TCIII gravatar image

updated 2022-02-18 11:47:24 -0600

SBC: Rpi 4B/4GB OS: Ubuntu 20.04 ROS: Noetic

Background: I presently have a robot chassis that is running ROS Noetic on an Rpi 4B/4GB and has multiple USB inputs from various detectors and controllers. I have an Arduino Uno R3 that is monitoring two IR receivers and is using rosserial to send IR Receiver beam detection data as irCode.x = flag2; and irCode.x = flag3; via ros::Publisher pub("irCode", &irCode); to the ROS-side host machine (Rpi 4B).

Question: How does the ROS-side host machine interface identify the correct USB port that the Arduino Uno R3 is attached to in the host machine ROS node code? The ROS-side host machine code does not appear to have any ROS commands that identify the Arduino USB port number and baud speed (57600). I have looked at the rosserial_python example and that example uses 'serial_node.py' to interface to a rosserial-enabled device, but I do not see an equivalent ROS function in the host machine node code to detect the Arduino (rosserial-endabled device).

#include <ros/ros.h>
#include <geometry_msgs/Vector3.h>
#include <geometry_msgs/Twist.h>


ros::Publisher cmd_vel_pub;
ros::Subscriber irValue_sub;

unsigned int foundDockingStation = 0;
geometry_msgs::Vector3 vec3;

void irValueCallback(const geometry_msgs::Vector3 &vector3)
{
  //omega_left = vector3.x;
  //omega_right  = vector3.y;


  vec3.x = vector3.x;
  vec3.y = vector3.y;

  if (foundDockingStation) {
    geometry_msgs::TwistPtr cmd(new geometry_msgs::Twist());
    cmd->linear.x = -0.08;
    cmd->angular.z = 0.1 * (vector3.x - vector3.y);
    if (vector3.x || vector3.y)
      cmd_vel_pub.publish(cmd);
  }
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "mybot_autodocking_irCode");

  ros::NodeHandle nh;
  cmd_vel_pub = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 50);
  irValue_sub = nh.subscribe("/irCode", 10, irValueCallback);

  vec3.x = 0; //initiallized with some big values
  vec3.y = 0;

  ros::Rate r(10);

  while (ros::ok())
  {
    ros::spinOnce(); 

    printf("x=%f, y=%f\n", vec3.x, vec3.y);
    if (!foundDockingStation && vec3.x == 0.0 && vec3.y == 0.0) {
      geometry_msgs::TwistPtr cmd(new geometry_msgs::Twist());
      cmd->angular.z = 0.1; // const rotate until 
      cmd->linear.x = 0.0;
      cmd_vel_pub.publish(cmd);
    } else {
      foundDockingStation = 1;
    }

    r.sleep();
  }
  return 0;
}

Comments?

Regards, TCIII

edit retag flag offensive close merge delete

Comments

What do you mean by:

I do not see an equivalent ROS function in the host machine node code to detect the Arduino (rosserial-endabled device).

what should be "detected" exactly?

rosserial allows an embedded device to "speak ROS". It doesn't matter for other ROS nodes where ROS nodes "are", what they are or what they do. The only things that matter are publishers, subscribers, services, actions and parameters. The rosserial server implements a proxy, which takes care of receiving and transmitting data from and to your embedded device. That proxy is the ROS node, not your Arduino. The proxy needs the device file name and baudrate. None of the other ROS nodes need it, as they're not "talking" to an Arduino on /dev/ttyUSB0 at 57600 baud, but to the rosserial server, over ROS topics.

If you could clarify what you mean by "detect[ing]" and "identify[ing ...(more)

gvdhoorn gravatar image gvdhoorn  ( 2022-02-19 10:24:35 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-19 12:27:16 -0600

Mike Scheutzow gravatar image

On the host running rosserial, ROS is not responsible for "finding" the linux /dev/[somehing] device. The author of the ROS launch file must create entries on the ros-parameter-server specifying a linux device name and a baudrate.

For USB, creating the linux device in /dev is typically done with a udev rule. You must install this rule before you insert the usb device and before the ROS launch file is executed. This new udev rule will be triggered when your specific USB-device is inserted, and then udev will create a fixed linux /dev name that you specify in the rule e.g. /dev/arduino

For this to work, the name in the udev rule has to exactly match the device name you specify in your ROS launch file.

edit flag offensive delete link more

Comments

@Mike Scheutzow,

Thanks for the response, much appreciated.

That was the what I expected, but needed expert input as I am not a ROS programmer by any means and was just doing research for the ROS programmer working with me. The ROS node code that we are using is obviously incomplete and we need to create a ROS launch file to specify the linux device name and baud rate.

TCIII

TCIII gravatar image TCIII  ( 2022-02-19 13:15:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-02-18 10:46:02 -0600

Seen: 83 times

Last updated: Feb 19 '22