Arduino To Linux in ROS
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 ...
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...
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