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

rosserial Losing Sync with Device when publishing encoder counts.

asked 2019-02-19 03:54:37 -0500

geistmate gravatar image

updated 2019-02-19 04:02:32 -0500

Hi,

I have an Arduino on Kinetic that is supposed to be publishing encoder counts. It is working properly but for some reason now I am running into an issue where the device falls out of sync with ROS.

My code is working properly, and it publishes counts successfully except every 20 seconds it times out and restarts. I looked at other answers, and I have made sure my distro is up to date, and made sure I gave permissions to the USB port that it is on.

I actually seemed to start having this issue today, when I was testing my code for my ultrasonic sensor range publishing. I never had this issue before with that arduino sketch, so I'm not necessarily sure if it's an Arduino problem..

If it makes any difference, the only major change I made in my computer is upgrading from Python 3.5 to 3.6 a couple days ago before I started working again on my robot.

Here is my code following,

#include <ArloRobot.h>      // Include ARLO Library
#include <SoftwareSerial.h> // Include SoftwareSerial Library
#include <Servo.h>

#include <ros.h>
#include <ros/time.h>
#include <sensor_msgs/Range.h>
#include <std_msgs/Int16.h>
#include <std_msgs/Int32.h>
#include <std_msgs/Float32.h>

int countsLeft, countsRight;                  // Encoder counting variables

/**** CREATE ARLO OBJECT AND SERIAL COMMUNICATION ****/
ArloRobot Arlo;                                       // Arlo Object
SoftwareSerial ArloSerial(12, 13);                    // Serial in I/O 12, 
Servo servo;

ros::NodeHandle_<ArduinoHardware, 1, 1, 200, 200> nh;

long duration;
int distance;

volatile long lwheel; 
volatile long rwheel; 

//std_msgs::Int32 lwheelMsg;
//ros::Publisher countsLeftPub("/lwheel_ticks", &lwheelMsg);

std_msgs::Int32 rwheelMsg;
ros::Publisher countsRightPub("/rwheel_ticks", &rwheelMsg);

void setup()
{
  ArloSerial.begin(19200);
  Arlo.begin(ArloSerial);

  Arlo.clearCounts(); 

  nh.initNode();
//  nh.advertise(countsLeftPub);
  nh.advertise(countsRightPub); 

  while(!nh.connected())
  {
    nh.spinOnce();
  }


}

void loop()
{
  Arlo.writeMotorPower(30,30); 
//  lwheelMsg.data = Arlo.readCountsLeft();
//  countsLeftPub.publish(&lwheelMsg);

  rwheelMsg.data = Arlo.readCountsRight(); 
  countsRightPub.publish(&rwheelMsg); 

  nh.spinOnce();

}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-03-26 17:14:15 -0500

Hi, geistmate. Have you identified this issue?

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-02-19 03:54:37 -0500

Seen: 273 times

Last updated: Feb 19 '19