当前位置: 首页>>代码示例>>C++>>正文


C++ Transporter::getDisplacement方法代码示例

本文整理汇总了C++中Transporter::getDisplacement方法的典型用法代码示例。如果您正苦于以下问题:C++ Transporter::getDisplacement方法的具体用法?C++ Transporter::getDisplacement怎么用?C++ Transporter::getDisplacement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transporter的用法示例。


在下文中一共展示了Transporter::getDisplacement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: publish_odom

void TransporterNode::publish_odom()
{
// store the current pose
  prevPose.x = cur_x;
  prevPose.y = cur_y;
  prevPose.theta = cur_theta;

// calculate the new pose
  double distance, angle;
  trobot.getDisplacement(&distance, &angle);
  cur_theta += angle;
  cur_x += distance * cos(cur_theta);
  cur_y += distance * sin(cur_theta); 
  ROS_DEBUG("PREVIOUS x = [%f], y = [%f], theta = [%f]\n", prevPose.x, prevPose.y, prevPose.theta);
  ROS_DEBUG("CURRENT x = [%f], y = [%f], theta = [%f]\n", cur_x, cur_y, cur_theta);

  current_time = ros::Time::now();
  double dt = (current_time - last_time).toSec();

  // convert rotation about z into quaternion
  geometry_msgs::Quaternion odom_quat;
  odom_quat.z = sin(cur_theta/2.0);
  odom_quat.w = cos(cur_theta/2.0);

  //next, we'll publish the odometry message over ROS
  nav_msgs::Odometry odom;
  odom.header.stamp = current_time;
  odom.header.frame_id = "odom";
  odom.child_frame_id = "base_footprint";

  //set the position (with respect to header.frame)
  odom.pose.pose.position.x = cur_x;
  odom.pose.pose.position.y = cur_y;
  odom.pose.pose.position.z = 0.0;
  odom.pose.pose.orientation = odom_quat;
  odom.pose.covariance = 
		boost::array<double, 36>{{1e-3, 0, 0, 0, 0, 0, 
								0, 1e-3, 0, 0, 0, 0,
								0, 0, 1e6, 0, 0, 0,
								0, 0, 0, 1e6, 0, 0,
								0, 0, 0, 0, 1e6, 0,
								0, 0, 0, 0, 0, 1e-3}};

  //set the velocity (with respect to child_frame)
  odom.twist.twist.linear.x = distance/dt;
  odom.twist.twist.angular.z = angle/dt;
  odom.twist.covariance = 
		boost::array<double, 36>{{1e-3, 0, 0, 0, 0, 0, 
								0, 1e-3, 0, 0, 0, 0,
								0, 0, 1e6, 0, 0, 0,
								0, 0, 0, 1e6, 0, 0,
								0, 0, 0, 0, 1e6, 0,
								0, 0, 0, 0, 0, 1e-3}};

  //publish the message
  odom_pub.publish(odom);

// publish joint state in order to show the continuous joints (wheels) in tf
  sensor_msgs::JointState js;
  js.header.stamp=current_time;
  js.name.resize(2);
  js.position.resize(2);
  js.name[0]="left_wheel_joint";
  js.name[1]="right_wheel_joint";
  js.position[0]=0;
  js.position[1]=0;
  js_pub.publish(js);

  last_time = current_time;
} //void TransporterNode::publish_odom()
开发者ID:weiin,项目名称:transporter-project,代码行数:70,代码来源:transporter_node.cpp


注:本文中的Transporter::getDisplacement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。