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

Sensor data via USB

asked 2018-07-23 06:24:22 -0500

S.Yildiz gravatar image

Im working on a project and i want to use a sensor. I can plug in the sensor via usb. I do not need any driver for the sensor. My task is to have an access to the sensor data. I have followed the tutorial on this page: http://clearpathrobotics.com/assets/g... But i dont know if this is my soution. I dont know what to do now. How can i have access to the data in ROS? Do I have to write a wrapper node? If yes, how?

edit retag flag offensive close merge delete

Comments

How can I take raw data from the sensors and publish it to a ROS topic?

S.Yildiz gravatar image S.Yildiz  ( 2018-07-23 06:30:17 -0500 )edit

How do you usually access the data without ROS? Is there a program you run? Or is it like a mouse that you just plug and play? I think you might need a wrapper to capture the stream of data.

bpinaya gravatar image bpinaya  ( 2018-07-23 06:30:38 -0500 )edit

I can have access to the data on windows. I have to install a software(Docklight) and configure the setting for the sensor like the baudrate etc. If i do this i get all the data on the software listed. Yes like a mouse. And how can i write a wrapper? is there any tutorial for this?

S.Yildiz gravatar image S.Yildiz  ( 2018-07-23 06:33:45 -0500 )edit

ROS works on Linux, did you get it to run on Windows? I think you should find how the data is being communicated (maybe serial? in that case check http://wjwwood.io/serial/ ). More info on the sensor would be helpful, but btw if you have to use Windows it seems quite hard to do.

bpinaya gravatar image bpinaya  ( 2018-07-23 08:04:07 -0500 )edit

So it is a sensor for detecting the range between two modules. No, I dont have to use Windows. There is just a software which can read the data supported on windows. And yes the communicatian is serial.

S.Yildiz gravatar image S.Yildiz  ( 2018-07-23 08:19:25 -0500 )edit

Btw I replied down below.

bpinaya gravatar image bpinaya  ( 2018-07-31 02:54:06 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-25 04:29:39 -0500

bpinaya gravatar image

updated 2018-07-25 07:11:52 -0500

Okay with the info provided I think I can sort of give some help. Check this past answer too btw.

So you in order to get the data in ROS, you need to make a wrapper for your sensor, if you know it's serial communication check the serial support for ROS here.

Also the guy from the answer made a nice simple example of ROS serial communication here

From his code:

#include <ros/ros.h>
#include <serial/serial.h>
#include <std_msgs/String.h>
#include <std_msgs/Empty.h>

serial::Serial ser;

void write_callback(const std_msgs::String::ConstPtr& msg){
    ROS_INFO_STREAM("Writing to serial port" << msg->data);
    ser.write(msg->data);
}

int main (int argc, char** argv){
    ros::init(argc, argv, "serial_example_node");
    ros::NodeHandle nh;

    ros::Subscriber write_sub = nh.subscribe("write", 1000, write_callback);
    ros::Publisher read_pub = nh.advertise<std_msgs::String>("read", 1000);

    try
    {
        ser.setPort("/dev/ttyACM0");
        ser.setBaudrate(9600);
        serial::Timeout to = serial::Timeout::simpleTimeout(1000);
        ser.setTimeout(to);
        ser.open();
    }
    catch (serial::IOException& e)
    {
        ROS_ERROR_STREAM("Unable to open port ");
        return -1;
    }

    if(ser.isOpen()){
        ROS_INFO_STREAM("Serial Port initialized");
    }else{
        return -1;
    }

    ros::Rate loop_rate(5);
    while(ros::ok()){

        ros::spinOnce();

        if(ser.available()){
            ROS_INFO_STREAM("Reading from serial port");
            std_msgs::String result;
            result.data = ser.read(ser.available());
            ROS_INFO_STREAM("Read: " << result.data);
            read_pub.publish(result);
        }
        loop_rate.sleep();

    }
}

I think it doesn't get any simpler than that. Once you read the data from the serial port you can use it in your project. Good luck and happy coding!

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-07-23 06:24:22 -0500

Seen: 1,141 times

Last updated: Jul 25 '18