9694浏览
查看: 9694|回复: 7

[讨论] ROS和arduino连接掉线,Lost sync with device, restarting...

[复制链接]
我的Arduino板子发布nav_msgs/Odometry类型主题以及tf变换,每当我打开节点时会出现一个错误,错误如下:
[ERROR] [WallTime: 1478676771.744104] Lost sync with device, restarting...
有趣的是,我的程序中去掉这一句“odom_pub.publish(&odom);”就不会出现这个错误了,我的程序如下,请各位朋友帮我分析以下,怎么解决,谢谢.
/*
* rosserial Planar Odometry Example
*/

#include <ros.h>
#include <ros/time.h>
#include <tf/tf.h>
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>

ros::NodeHandle  nh;

geometry_msgs::TransformStamped t;
tf::TransformBroadcaster broadcaster;
nav_msgs::Odometry odom;
ros::Publisher odom_pub("/odom",&odom);
ros::Time current_time;
ros::Time last_time;

double x = 0.0;
double y = 0.0;
double theta = 0.0;
double vx=0.0;
double vy=0.0;
double vth=0.0;


char base_link[] = "/base_link";
char base_odom[] = "/odom";

void setup()
{
  nh.initNode();
  broadcaster.init(nh);
  nh.advertise(odom_pub);
  last_time = nh.now();
}

void loop()
{
  current_time = nh.now();
  double dt=current_time.toSec()-last_time.toSec();
  double delta_x = (vx*cos(theta)-vy*sin(theta))*dt;
  double delta_y = (vx*sin(theta)+vy*cos(theta))*dt;
  double delta_th = vth*dt;

  x+=delta_x;
  y+=delta_y;
  theta+=delta_th;  
   
  // tf odom->base_link
  t.header.frame_id = base_odom;
  t.child_frame_id = base_link;
  t.transform.translation.x = x;
  t.transform.translation.y = y;
  t.transform.rotation = tf::createQuaternionFromYaw(theta);
  t.header.stamp = current_time;
//odometry odom->base_link
  odom.header.stamp=current_time;
  odom.header.frame_id="odom";
  odom.child_frame_id="base_link";

  odom.pose.pose.position.x=x;
  odom.pose.pose.position.y=y;
  odom.pose.pose.position.z=0;
  odom.pose.pose.orientation = tf::createQuaternionFromYaw(theta);

  odom.twist.twist.linear.x=vx;
  odom.twist.twist.linear.y=0;
  odom.twist.twist.linear.z=0;
  odom.twist.twist.angular.z=vth;
  odom.twist.twist.angular.x=0;
  odom.twist.twist.angular.y=0;  
  last_time=current_time;
  broadcaster.sendTransform(t);
  odom_pub.publish(&odom);
  
  nh.spinOnce();
  delay(10);
}

dsweiliang  初级技神

发表于 2016-11-9 16:17:07

看头像我以为是你@swanglei  
回复

使用道具 举报

dsweiliang  初级技神

发表于 2016-11-9 16:17:33

@-stark 大神
回复

使用道具 举报

swanglei  中级技神

发表于 2016-11-9 17:06:35

dsweiliang 发表于 2016-11-9 16:17
看头像我以为是你@swanglei

假的我。。。
回复

使用道具 举报

dsweiliang  初级技神

发表于 2016-11-10 08:20:07


哈哈哈
回复

使用道具 举报

dsweiliang  初级技神

发表于 2016-11-10 08:20:12


哈哈哈
回复

使用道具 举报

-stark  中级技师

发表于 2016-11-14 11:03:44

简单理解下就是在发布信息的时候,丢失了与硬件的同步导致重启。
试着参照一下官方的程序进行代码修改:http://wiki.ros.org/navigation/Tutorials/RobotSetup/Odom
回复

使用道具 举报

southeast_cczu  学徒

发表于 2017-8-22 10:00:34

楼主问题解决了吗,我也遇到了同样的问题,求答案
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail