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

Arduino To Linux in ROS

asked 2015-04-22 04:18:23 -0600

Andrew Godley gravatar image

Hi I am using a wii nunchuck controller to pass serial values to my Ubuntu Computer, I wrote a c++ file that carries out this function and it works perfectly, however I have tried making this in ROS where rather than print the value to the terminal I publish it to a topic. I cannot get my package to build in ROS and I dont know why. I have never used a ROS file before where i have had to include header files so i could have done this incorrectly, the headers are in ws/src/pakage/include. The error which i think is the main one is.

/home/satellite/sendws/src/nunout/src/serialin.cpp:57:14: error: ambiguous overload for ‘operator>>’ in ‘file >> ss’

My code for the program which runs as a standard executable is.

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

using namespace std;

int
main()
{
    struct termios tio;

    memset(&tio,0,sizeof(tio));
    tio.c_iflag=0;
    tio.c_oflag=0;
    tio.c_cflag=CS8|CREAD|CLOCAL;
    tio.c_lflag=0;
    tio.c_cc[VMIN]=1;
    tio.c_cc[VTIME]=5;

    cfsetispeed(&tio, B9600);


    int i;
    string str;
cout << "START OF PROG";

fstream file;

file.open("/dev/ttyACM0");

if(file!=NULL){
      cout << "file not null" << endl;  
    for(i=0;i<1000;i++){

      file >> str;
      if(str == ""){cout<< "null"<<endl;}
      else{cout<<str<<endl;}

  }
      //fclose(file);
}
else {cout<<"file null"<<endl;}
}

when it is in ROS the code has been changed to //Take nunchuck position from arduino //over serial and broadcast it to //topic for Odroid

     #include <stdio.h>
     #include <fstream>
     #include <termios.h>
     #include <unistd.h>
     #include <fcntl.h>
     //#include <string.h>

     #include "ros/ros.h" 
     #include "std_msgs/String.h"

     using namespace std;

     int
     main(int argc, char **argv)
     {
     //====================================================

        ros::init(argc, argv, "serialin");
        ros::NodeHandle n;
        ros::Publisher nunpos_pub = n.advertise<std_msgs::String>("nunpos",1);
        ros::Rate loop_rate(1);

     //==================================================== 


        struct termios tio;

        memset(&tio,0,sizeof(tio));
        tio.c_iflag=0;
        tio.c_oflag=0;
        tio.c_cflag=CS8|CREAD|CLOCAL;
        tio.c_lflag=0;
        tio.c_cc[VMIN]=1;
        tio.c_cc[VTIME]=5;

        cfsetispeed(&tio, B9600);


        int i;
        string str;

        fstream file;

        file.open("/dev/ttyACM0");

     if(file!=NULL){
        while(ros::ok()){

                  std_msgs::String msg;
                  std::stringstream ss;

                  file >> ss;

                  if(ss == ""){
                          ss = "Empty";
                          msg.data = ss.str();
                          ROS_INFO("%s", msg->data.c_str());
                      }
                  else{

                        msg.data = ss.str();
                        nunpos_pub.publish(msg);                  

                      }

            loop_rate.sleep();


            }

     return 0;
            }
        }

the output from the catkin_make is

satellite@satellite-OptiPlex-990:~/sendws$ catkin_make
Base path: /home/satellite/sendws
Source space: /home/satellite/sendws/src
Build space: /home/satellite/sendws/build
Devel space: /home/satellite/sendws/devel
Install space: /home/satellite/sendws/install
####
#### Running command: "make cmake_check_build_system" in "/home/satellite/sendws/build"
####
####
#### Running command: "make -j4 -l4" in "/home/satellite/sendws/build"
####
[100%] Building CXX object nunout/CMakeFiles/serialin.dir/src/serialin.cpp.o
/home/satellite/sendws/src/nunout/src/serialin.cpp: In function ‘int main(int, char**)’:
/home/satellite/sendws/src/nunout/src/serialin.cpp:57:14: error: ambiguous overload ...
(more)
edit retag flag offensive close merge delete

Comments

I would suggest using the serial functions from ros. Would be much easier ;-) http://wiki.ros.org/serial Example: http://docs.ros.org/indigo/api/serial...http://docs.ros.org/indigo/api/serial...

cyborg-x1 gravatar image cyborg-x1  ( 2015-04-22 09:30:58 -0600 )edit

Thanks, i am new to ubuntu and ROS so it been a difficult. I have used the ROS serial libraries and i can access the arduino from a desktop perfectly. But when trying to install on the odroid i get Unable to locate package ros-hydro-rosserial-arduino i don't know why since this code worked on the PC

Andrew Godley gravatar image Andrew Godley  ( 2015-04-24 04:54:05 -0600 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2015-04-24 08:03:41 -0600

I guess this problem results from the fact that you have a embedded system. There is another repo for those and this package is not built for the embedded repository, not all packages are built there. So you might have to build it yourself on your embedded platform (catkin_ws, checking out etc.)

edit flag offensive delete link more
0

answered 2015-04-24 05:31:56 -0600

I guess you have an error in your CPP code, see here:

http://stackoverflow.com/questions/11...

edit flag offensive delete link more

Comments

The CPP code works. The error happens when I try to install the rostral libraries from the terminal onto my device (its kind of similar to a raspberry pi). The command is; sudo apt-get install ros-hydro-rosserial-arduino. which returns Reading package lists... Done Building dependency tree --(1/2)--

Andrew Godley gravatar image Andrew Godley  ( 2015-04-24 07:11:46 -0600 )edit

--(2/2)-- Reading state information... Done E: Unable to locate package ros-hydro-rosserial-arduino

Andrew Godley gravatar image Andrew Godley  ( 2015-04-24 07:12:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-04-22 04:18:23 -0600

Seen: 622 times

Last updated: Apr 24 '15